re-add gate pulsar pulse counting with multiple actions, optimize builder code
This commit is contained in:
parent
2aa427f0be
commit
7f34e2824b
10 changed files with 69 additions and 27 deletions
|
@ -42,7 +42,7 @@ public abstract class GateExpansionController {
|
||||||
public void startResolution() {
|
public void startResolution() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean resolveAction(IStatement action) {
|
public boolean resolveAction(IStatement action, int count) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
* Please check the contents of the license, which should be located
|
* Please check the contents of the license, which should be located
|
||||||
* as "LICENSE.API" in the BuildCraft source code distribution.
|
* as "LICENSE.API" in the BuildCraft source code distribution.
|
||||||
*/
|
*/
|
||||||
@API(apiVersion = "3.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|gates")
|
@API(apiVersion = "4.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|gates")
|
||||||
package buildcraft.api.gates;
|
package buildcraft.api.gates;
|
||||||
import cpw.mods.fml.common.API;
|
import cpw.mods.fml.common.API;
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
import buildcraft.api.blueprints.BuilderAPI;
|
import buildcraft.api.blueprints.BuilderAPI;
|
||||||
|
@ -123,8 +124,12 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
||||||
public static IActionInternal actionStationDropInPipe = new ActionStationAcceptItemsPipe();
|
public static IActionInternal actionStationDropInPipe = new ActionStationAcceptItemsPipe();
|
||||||
public static IActionInternal actionStationMachineRequestItems = new ActionStationRequestItemsMachine();
|
public static IActionInternal actionStationMachineRequestItems = new ActionStationRequestItemsMachine();
|
||||||
|
|
||||||
|
public static float chipsetCostMultiplier = 1.0F;
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent evt) {
|
public void preInit(FMLPreInitializationEvent evt) {
|
||||||
|
chipsetCostMultiplier = BuildCraftCore.mainConfiguration.getFloat("chipset.costMultiplier", Configuration.CATEGORY_GENERAL, 1.0F, 0.001F, 1000.0F, "The multiplier for chipset recipe cost.");
|
||||||
|
|
||||||
BuildCraftCore.mainConfiguration.save();
|
BuildCraftCore.mainConfiguration.save();
|
||||||
|
|
||||||
laserBlock = new BlockLaser();
|
laserBlock = new BlockLaser();
|
||||||
|
@ -283,21 +288,21 @@ public class BuildCraftSilicon extends BuildCraftMod {
|
||||||
'I', "ingotIron");
|
'I', "ingotIron");
|
||||||
|
|
||||||
// CHIPSETS
|
// CHIPSETS
|
||||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redstoneChipset", 100000, Chipset.RED.getStack(),
|
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redstoneChipset", Math.round(100000 * chipsetCostMultiplier), Chipset.RED.getStack(),
|
||||||
"dustRedstone");
|
"dustRedstone");
|
||||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:ironChipset", 200000, Chipset.IRON.getStack(),
|
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:ironChipset", Math.round(200000 * chipsetCostMultiplier), Chipset.IRON.getStack(),
|
||||||
"dustRedstone", "ingotIron");
|
"dustRedstone", "ingotIron");
|
||||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:goldChipset", 400000, Chipset.GOLD.getStack(),
|
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:goldChipset", Math.round(400000 * chipsetCostMultiplier), Chipset.GOLD.getStack(),
|
||||||
"dustRedstone", "ingotGold");
|
"dustRedstone", "ingotGold");
|
||||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:diamondChipset", 800000,
|
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:diamondChipset", Math.round(800000 * chipsetCostMultiplier),
|
||||||
Chipset.DIAMOND.getStack(), "dustRedstone", "gemDiamond");
|
Chipset.DIAMOND.getStack(), "dustRedstone", "gemDiamond");
|
||||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:emeraldChipset", 1200000,
|
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:emeraldChipset", Math.round(1200000 * chipsetCostMultiplier),
|
||||||
Chipset.EMERALD.getStack(), "dustRedstone", "gemEmerald");
|
Chipset.EMERALD.getStack(), "dustRedstone", "gemEmerald");
|
||||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:pulsatingChipset", 400000,
|
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:pulsatingChipset", Math.round(400000 * chipsetCostMultiplier),
|
||||||
Chipset.PULSATING.getStack(2), "dustRedstone", Items.ender_pearl);
|
Chipset.PULSATING.getStack(2), "dustRedstone", Items.ender_pearl);
|
||||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:quartzChipset", 600000, Chipset.QUARTZ.getStack(),
|
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:quartzChipset", Math.round(600000 * chipsetCostMultiplier), Chipset.QUARTZ.getStack(),
|
||||||
"dustRedstone", "gemQuartz");
|
"dustRedstone", "gemQuartz");
|
||||||
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:compChipset", 600000, Chipset.COMP.getStack(),
|
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:compChipset", Math.round(600000 * chipsetCostMultiplier), Chipset.COMP.getStack(),
|
||||||
"dustRedstone", Items.comparator);
|
"dustRedstone", Items.comparator);
|
||||||
|
|
||||||
// ROBOTS AND BOARDS
|
// ROBOTS AND BOARDS
|
||||||
|
|
|
@ -144,7 +144,7 @@ public class TilePathMarker extends TileMarker {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinkedList<BlockIndex> getPath() {
|
public LinkedList<BlockIndex> getPath() {
|
||||||
TreeSet<BlockIndex> visitedPaths = new TreeSet<BlockIndex>();
|
HashSet<BlockIndex> visitedPaths = new HashSet<BlockIndex>();
|
||||||
LinkedList<BlockIndex> res = new LinkedList<BlockIndex>();
|
LinkedList<BlockIndex> res = new LinkedList<BlockIndex>();
|
||||||
|
|
||||||
TilePathMarker nextTile = this;
|
TilePathMarker nextTile = this;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
package buildcraft.core.blueprints;
|
package buildcraft.core.blueprints;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
@ -44,8 +45,8 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
||||||
public BlueprintBase blueprint;
|
public BlueprintBase blueprint;
|
||||||
public BptContext context;
|
public BptContext context;
|
||||||
protected boolean done;
|
protected boolean done;
|
||||||
protected TreeSet<BlockIndex> clearedLocations = new TreeSet<BlockIndex>();
|
protected HashSet<BlockIndex> clearedLocations = new HashSet<BlockIndex>();
|
||||||
protected TreeSet<BlockIndex> builtLocations = new TreeSet<BlockIndex>();
|
protected HashSet<BlockIndex> builtLocations = new HashSet<BlockIndex>();
|
||||||
protected int x, y, z;
|
protected int x, y, z;
|
||||||
protected boolean initialized = false;
|
protected boolean initialized = false;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
|
@ -59,7 +60,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
||||||
|
|
||||||
public ArrayList<ItemStack> neededItems = new ArrayList<ItemStack>();
|
public ArrayList<ItemStack> neededItems = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
protected TreeSet<Integer> builtEntities = new TreeSet<Integer>();
|
protected HashSet<Integer> builtEntities = new HashSet<Integer>();
|
||||||
|
|
||||||
private LinkedList<BuildingSlotBlock> buildList = new LinkedList<BuildingSlotBlock>();
|
private LinkedList<BuildingSlotBlock> buildList = new LinkedList<BuildingSlotBlock>();
|
||||||
private LinkedList<BuildingSlotEntity> entityList = new LinkedList<BuildingSlotEntity>();
|
private LinkedList<BuildingSlotEntity> entityList = new LinkedList<BuildingSlotEntity>();
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
import com.google.common.collect.HashMultiset;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
@ -80,6 +81,8 @@ public final class Gate implements IGate, IStatementContainer {
|
||||||
private float pulseStage = 0;
|
private float pulseStage = 0;
|
||||||
private ForgeDirection direction;
|
private ForgeDirection direction;
|
||||||
|
|
||||||
|
private HashMultiset<IStatement> statementCounts = HashMultiset.create();
|
||||||
|
|
||||||
// / CONSTRUCTOR
|
// / CONSTRUCTOR
|
||||||
public Gate(Pipe<?> pipe, GateMaterial material, GateLogic logic, ForgeDirection direction) {
|
public Gate(Pipe<?> pipe, GateMaterial material, GateLogic logic, ForgeDirection direction) {
|
||||||
this.pipe = pipe;
|
this.pipe = pipe;
|
||||||
|
@ -412,7 +415,7 @@ public final class Gate implements IGate, IStatementContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activeActions = new ArrayList<StatementSlot>();
|
activeActions.clear();
|
||||||
|
|
||||||
for (int it = 0; it < MAX_STATEMENTS; ++it) {
|
for (int it = 0; it < MAX_STATEMENTS; ++it) {
|
||||||
boolean allActive = true;
|
boolean allActive = true;
|
||||||
|
@ -452,6 +455,14 @@ public final class Gate implements IGate, IStatementContainer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
statementCounts.clear();
|
||||||
|
|
||||||
|
for (int it = 0; it < MAX_STATEMENTS; ++it) {
|
||||||
|
if (actionsState[it] == ActionActiveState.Activated) {
|
||||||
|
statementCounts.add(actions[it], 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Activate the actions
|
// Activate the actions
|
||||||
for (StatementSlot slot : activeActions) {
|
for (StatementSlot slot : activeActions) {
|
||||||
IStatement action = slot.statement;
|
IStatement action = slot.statement;
|
||||||
|
@ -501,7 +512,7 @@ public final class Gate implements IGate, IStatementContainer {
|
||||||
|
|
||||||
public boolean resolveAction(IStatement action) {
|
public boolean resolveAction(IStatement action) {
|
||||||
for (GateExpansionController expansion : expansions.values()) {
|
for (GateExpansionController expansion : expansions.values()) {
|
||||||
if (expansion.resolveAction(action)) {
|
if (expansion.resolveAction(action, statementCounts.count(action))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
|
||||||
private boolean singlePulse;
|
private boolean singlePulse;
|
||||||
private boolean hasPulsed;
|
private boolean hasPulsed;
|
||||||
private int tick;
|
private int tick;
|
||||||
|
private int count;
|
||||||
|
|
||||||
public GateExpansionControllerPulsar(TileEntity pipeTile) {
|
public GateExpansionControllerPulsar(TileEntity pipeTile) {
|
||||||
super(GateExpansionPulsar.this, pipeTile);
|
super(GateExpansionPulsar.this, pipeTile);
|
||||||
|
@ -65,12 +66,12 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean resolveAction(IStatement action) {
|
public boolean resolveAction(IStatement action, int count) {
|
||||||
if (action instanceof ActionEnergyPulsar) {
|
if (action instanceof ActionEnergyPulsar) {
|
||||||
enablePulse();
|
enablePulse(count);
|
||||||
return true;
|
return true;
|
||||||
} else if (action instanceof ActionSingleEnergyPulse) {
|
} else if (action instanceof ActionSingleEnergyPulse) {
|
||||||
enableSinglePulse();
|
enableSinglePulse(count);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -101,10 +102,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
|
||||||
|
|
||||||
if (pipeTile instanceof IEnergyHandler && (!singlePulse || !hasPulsed)) {
|
if (pipeTile instanceof IEnergyHandler && (!singlePulse || !hasPulsed)) {
|
||||||
gate.setPulsing(true);
|
gate.setPulsing(true);
|
||||||
// TODO: (1 - 1) is coming from pulse count, which has been
|
((IEnergyHandler) pipeTile).receiveEnergy(ForgeDirection.UNKNOWN, Math.min(1 << (count - 1), 64) * 10,
|
||||||
// removed. The add energy algorithm probably needs to be
|
|
||||||
// reviewed altogether.
|
|
||||||
((IEnergyHandler) pipeTile).receiveEnergy(ForgeDirection.UNKNOWN, Math.min(1 << (1 - 1), 64) * 10,
|
|
||||||
false);
|
false);
|
||||||
hasPulsed = true;
|
hasPulsed = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -112,14 +110,16 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableSinglePulse() {
|
private void enableSinglePulse(int count) {
|
||||||
singlePulse = true;
|
singlePulse = true;
|
||||||
isActive = true;
|
isActive = true;
|
||||||
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enablePulse() {
|
private void enablePulse(int count) {
|
||||||
isActive = true;
|
isActive = true;
|
||||||
singlePulse = false;
|
singlePulse = false;
|
||||||
|
this.count = count;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disablePulse() {
|
private void disablePulse() {
|
||||||
|
@ -127,6 +127,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
|
||||||
hasPulsed = false;
|
hasPulsed = false;
|
||||||
}
|
}
|
||||||
isActive = false;
|
isActive = false;
|
||||||
|
this.count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -139,6 +140,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
|
||||||
nbt.setBoolean("singlePulse", singlePulse);
|
nbt.setBoolean("singlePulse", singlePulse);
|
||||||
nbt.setBoolean("isActive", isActive);
|
nbt.setBoolean("isActive", isActive);
|
||||||
nbt.setBoolean("hasPulsed", hasPulsed);
|
nbt.setBoolean("hasPulsed", hasPulsed);
|
||||||
|
nbt.setByte("pulseCount", (byte) count);
|
||||||
nbt.setInteger("tick", tick);
|
nbt.setInteger("tick", tick);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +149,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
|
||||||
isActive = nbt.getBoolean("isActive");
|
isActive = nbt.getBoolean("isActive");
|
||||||
singlePulse = nbt.getBoolean("singlePulse");
|
singlePulse = nbt.getBoolean("singlePulse");
|
||||||
hasPulsed = nbt.getBoolean("hasPulsed");
|
hasPulsed = nbt.getBoolean("hasPulsed");
|
||||||
|
count = nbt.getByte("pulseCount");
|
||||||
tick = nbt.getInteger("tick");
|
tick = nbt.getInteger("tick");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,10 +8,31 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.transport.gates;
|
package buildcraft.transport.gates;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import buildcraft.api.statements.IStatement;
|
import buildcraft.api.statements.IStatement;
|
||||||
import buildcraft.api.statements.IStatementParameter;
|
import buildcraft.api.statements.IStatementParameter;
|
||||||
|
import buildcraft.api.statements.StatementManager;
|
||||||
|
|
||||||
public class StatementSlot {
|
public class StatementSlot {
|
||||||
public IStatement statement;
|
public IStatement statement;
|
||||||
public IStatementParameter[] parameters;
|
public IStatementParameter[] parameters;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o == null || !(o instanceof StatementSlot)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
StatementSlot s = (StatementSlot) o;
|
||||||
|
if (s.statement != statement || parameters.length != s.parameters.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < parameters.length; i++) {
|
||||||
|
IStatementParameter p1 = parameters[i];
|
||||||
|
IStatementParameter p2 = s.parameters[i];
|
||||||
|
if (!(p1.equals(p2))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,7 +147,7 @@ public class PipeItemsWood extends Pipe<PipeTransportItems> implements IEnergyHa
|
||||||
|
|
||||||
for (ItemStack stack : extracted) {
|
for (ItemStack stack : extracted) {
|
||||||
if (stack == null || stack.stackSize == 0) {
|
if (stack == null || stack.stackSize == 0) {
|
||||||
battery.useEnergy(10, 10, false);
|
//battery.useEnergy(10, 10, false);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -197,7 +197,7 @@ public class PipeItemsWood extends Pipe<PipeTransportItems> implements IEnergyHa
|
||||||
|
|
||||||
if (slot != null && slot.stackSize > 0 && inventory.canExtractItem(k, slot, from.ordinal())) {
|
if (slot != null && slot.stackSize > 0 && inventory.canExtractItem(k, slot, from.ordinal())) {
|
||||||
if (doRemove) {
|
if (doRemove) {
|
||||||
int stackSize = battery.useEnergy(10, slot.stackSize * 10, false) / 10;
|
int stackSize = (int) Math.floor(battery.useEnergy(10, slot.stackSize * 10, false) / 10);
|
||||||
|
|
||||||
return inventory.decrStackSize(k, stackSize);
|
return inventory.decrStackSize(k, stackSize);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue