mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 18:30:27 -04:00
Added driver for analyzer block from Forestry for #723.
Slightly improved bee house driver (avoid duplicates in returned tables).
This commit is contained in:
parent
060990e977
commit
6f788e0b14
@ -0,0 +1,34 @@
|
||||
package li.cil.oc.integration.forestry
|
||||
|
||||
import forestry.api.genetics.AlleleManager
|
||||
import forestry.core.gadgets.TileAnalyzer
|
||||
import li.cil.oc.api.driver.NamedBlock
|
||||
import li.cil.oc.api.machine.Arguments
|
||||
import li.cil.oc.api.machine.Callback
|
||||
import li.cil.oc.api.machine.Context
|
||||
import li.cil.oc.api.prefab.DriverTileEntity
|
||||
import li.cil.oc.integration.ManagedTileEntityEnvironment
|
||||
import li.cil.oc.util.ResultWrapper._
|
||||
import net.minecraft.world.World
|
||||
|
||||
class DriverAnalyzer extends DriverTileEntity {
|
||||
override def getTileEntityClass = classOf[TileAnalyzer]
|
||||
|
||||
override def createEnvironment(world: World, x: Int, y: Int, z: Int) = new Environment(world.getTileEntity(x, y, z).asInstanceOf[TileAnalyzer])
|
||||
|
||||
class Environment(tileEntity: TileAnalyzer) extends ManagedTileEntityEnvironment[TileAnalyzer](tileEntity, "forestry_analyzer") with NamedBlock {
|
||||
override def preferredName = "forestry_analyzer"
|
||||
|
||||
override def priority = 0
|
||||
|
||||
@Callback(doc = "function():boolean -- Can the bees breed?")
|
||||
def isWorking(context: Context, args: Arguments): Array[AnyRef] = result(tileEntity.isWorking)
|
||||
|
||||
@Callback(doc = "function():boolean -- Can the bees breed?")
|
||||
def getProgress(context: Context, args: Arguments): Array[AnyRef] = result(1.0 - tileEntity.getProgressScaled(100) / 100.0)
|
||||
|
||||
@Callback(doc = "function():boolean -- Can the bees breed?")
|
||||
def getIndividualOnDisplay(context: Context, args: Arguments): Array[AnyRef] = result(AlleleManager.alleleRegistry.getIndividual(tileEntity.getIndividualOnDisplay))
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package li.cil.oc.integration.forestry;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import forestry.api.apiculture.IBeeHousing;
|
||||
import forestry.api.genetics.*;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
@ -14,8 +13,8 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class DriverBeeHouse extends DriverTileEntity {
|
||||
@Override
|
||||
@ -63,8 +62,7 @@ public class DriverBeeHouse extends DriverTileEntity {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Map<Integer, Map<String, Object>> result = Maps.newHashMap();
|
||||
int j = 1;
|
||||
final Set<Map<String, Object>> result = Sets.newHashSet();
|
||||
for (IMutation mutation : beeRoot.getMutations(false)) {
|
||||
HashMap<String, Object> mutationMap = new HashMap<String, Object>();
|
||||
|
||||
@ -86,7 +84,7 @@ public class DriverBeeHouse extends DriverTileEntity {
|
||||
if (template != null && template.length > 0) {
|
||||
mutationMap.put("result", template[0].getName());
|
||||
}
|
||||
result.put(j++, mutationMap);
|
||||
result.add(mutationMap);
|
||||
}
|
||||
return new Object[]{result};
|
||||
}
|
||||
@ -98,7 +96,7 @@ public class DriverBeeHouse extends DriverTileEntity {
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<IAlleleSpecies> result = Lists.newArrayList();
|
||||
final Set<IAlleleSpecies> result = Sets.newHashSet();
|
||||
for (IMutation mutation : beeRoot.getMutations(false)) {
|
||||
final IAllele[] template = mutation.getTemplate();
|
||||
if (template == null || template.length <= 0) {
|
||||
@ -112,7 +110,7 @@ public class DriverBeeHouse extends DriverTileEntity {
|
||||
|
||||
result.add((IAlleleSpecies) allele);
|
||||
}
|
||||
return new Object[]{result.toArray(new IAlleleSpecies[result.size()])};
|
||||
return new Object[]{result};
|
||||
}
|
||||
|
||||
@Callback(doc = "function(beeName:string):table -- Get the parents for a particular mutation")
|
||||
@ -122,7 +120,7 @@ public class DriverBeeHouse extends DriverTileEntity {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<IMutation> result = Lists.newArrayList();
|
||||
final Set<IMutation> result = Sets.newHashSet();
|
||||
final String childType = args.checkString(0).toLowerCase();
|
||||
for (IMutation mutation : beeRoot.getMutations(false)) {
|
||||
final IAllele[] template = mutation.getTemplate();
|
||||
@ -142,7 +140,7 @@ public class DriverBeeHouse extends DriverTileEntity {
|
||||
result.add(mutation);
|
||||
}
|
||||
}
|
||||
return new Object[]{result.toArray(new IMutation[result.size()])};
|
||||
return new Object[]{result};
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ object ModForestry extends ModProxy {
|
||||
override def initialize() {
|
||||
Driver.add(new ConverterIAlleles)
|
||||
Driver.add(new ConverterIIndividual)
|
||||
Driver.add(new DriverAnalyzer)
|
||||
Driver.add(new DriverBeeHouse)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user