re-add gate pulsar pulse counting with multiple actions, optimize builder code

This commit is contained in:
asiekierka 2014-12-29 22:17:40 +01:00
parent 2aa427f0be
commit 7f34e2824b
10 changed files with 69 additions and 27 deletions

View file

@ -42,7 +42,7 @@ public abstract class GateExpansionController {
public void startResolution() {
}
public boolean resolveAction(IStatement action) {
public boolean resolveAction(IStatement action, int count) {
return false;
}

View file

@ -6,7 +6,7 @@
* Please check the contents of the license, which should be located
* 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;
import cpw.mods.fml.common.API;

View file

@ -21,6 +21,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.oredict.OreDictionary;
import buildcraft.api.blueprints.BuilderAPI;
@ -123,8 +124,12 @@ public class BuildCraftSilicon extends BuildCraftMod {
public static IActionInternal actionStationDropInPipe = new ActionStationAcceptItemsPipe();
public static IActionInternal actionStationMachineRequestItems = new ActionStationRequestItemsMachine();
public static float chipsetCostMultiplier = 1.0F;
@Mod.EventHandler
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();
laserBlock = new BlockLaser();
@ -283,21 +288,21 @@ public class BuildCraftSilicon extends BuildCraftMod {
'I', "ingotIron");
// CHIPSETS
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redstoneChipset", 100000, Chipset.RED.getStack(),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:redstoneChipset", Math.round(100000 * chipsetCostMultiplier), Chipset.RED.getStack(),
"dustRedstone");
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:ironChipset", 200000, Chipset.IRON.getStack(),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:ironChipset", Math.round(200000 * chipsetCostMultiplier), Chipset.IRON.getStack(),
"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");
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:diamondChipset", 800000,
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:diamondChipset", Math.round(800000 * chipsetCostMultiplier),
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");
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:pulsatingChipset", 400000,
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:pulsatingChipset", Math.round(400000 * chipsetCostMultiplier),
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");
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:compChipset", 600000, Chipset.COMP.getStack(),
BuildcraftRecipeRegistry.assemblyTable.addRecipe("buildcraft:compChipset", Math.round(600000 * chipsetCostMultiplier), Chipset.COMP.getStack(),
"dustRedstone", Items.comparator);
// ROBOTS AND BOARDS

View file

@ -144,7 +144,7 @@ public class TilePathMarker extends TileMarker {
}
public LinkedList<BlockIndex> getPath() {
TreeSet<BlockIndex> visitedPaths = new TreeSet<BlockIndex>();
HashSet<BlockIndex> visitedPaths = new HashSet<BlockIndex>();
LinkedList<BlockIndex> res = new LinkedList<BlockIndex>();
TilePathMarker nextTile = this;

View file

@ -9,6 +9,7 @@
package buildcraft.core.blueprints;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.TreeSet;
@ -44,8 +45,8 @@ public abstract class BptBuilderBase implements IAreaProvider {
public BlueprintBase blueprint;
public BptContext context;
protected boolean done;
protected TreeSet<BlockIndex> clearedLocations = new TreeSet<BlockIndex>();
protected TreeSet<BlockIndex> builtLocations = new TreeSet<BlockIndex>();
protected HashSet<BlockIndex> clearedLocations = new HashSet<BlockIndex>();
protected HashSet<BlockIndex> builtLocations = new HashSet<BlockIndex>();
protected int x, y, z;
protected boolean initialized = false;

View file

@ -12,6 +12,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
@ -59,7 +60,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
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<BuildingSlotEntity> entityList = new LinkedList<BuildingSlotEntity>();

View file

@ -14,6 +14,7 @@ import java.util.List;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.HashMultiset;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@ -80,6 +81,8 @@ public final class Gate implements IGate, IStatementContainer {
private float pulseStage = 0;
private ForgeDirection direction;
private HashMultiset<IStatement> statementCounts = HashMultiset.create();
// / CONSTRUCTOR
public Gate(Pipe<?> pipe, GateMaterial material, GateLogic logic, ForgeDirection direction) {
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) {
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
for (StatementSlot slot : activeActions) {
IStatement action = slot.statement;
@ -501,7 +512,7 @@ public final class Gate implements IGate, IStatementContainer {
public boolean resolveAction(IStatement action) {
for (GateExpansionController expansion : expansions.values()) {
if (expansion.resolveAction(action)) {
if (expansion.resolveAction(action, statementCounts.count(action))) {
return true;
}
}

View file

@ -46,6 +46,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
private boolean singlePulse;
private boolean hasPulsed;
private int tick;
private int count;
public GateExpansionControllerPulsar(TileEntity pipeTile) {
super(GateExpansionPulsar.this, pipeTile);
@ -65,12 +66,12 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
}
@Override
public boolean resolveAction(IStatement action) {
public boolean resolveAction(IStatement action, int count) {
if (action instanceof ActionEnergyPulsar) {
enablePulse();
enablePulse(count);
return true;
} else if (action instanceof ActionSingleEnergyPulse) {
enableSinglePulse();
enableSinglePulse(count);
return true;
}
return false;
@ -101,10 +102,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
if (pipeTile instanceof IEnergyHandler && (!singlePulse || !hasPulsed)) {
gate.setPulsing(true);
// TODO: (1 - 1) is coming from pulse count, which has been
// removed. The add energy algorithm probably needs to be
// reviewed altogether.
((IEnergyHandler) pipeTile).receiveEnergy(ForgeDirection.UNKNOWN, Math.min(1 << (1 - 1), 64) * 10,
((IEnergyHandler) pipeTile).receiveEnergy(ForgeDirection.UNKNOWN, Math.min(1 << (count - 1), 64) * 10,
false);
hasPulsed = true;
} else {
@ -112,14 +110,16 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
}
}
private void enableSinglePulse() {
private void enableSinglePulse(int count) {
singlePulse = true;
isActive = true;
this.count = count;
}
private void enablePulse() {
private void enablePulse(int count) {
isActive = true;
singlePulse = false;
this.count = count;
}
private void disablePulse() {
@ -127,6 +127,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
hasPulsed = false;
}
isActive = false;
this.count = 0;
}
@Override
@ -139,6 +140,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
nbt.setBoolean("singlePulse", singlePulse);
nbt.setBoolean("isActive", isActive);
nbt.setBoolean("hasPulsed", hasPulsed);
nbt.setByte("pulseCount", (byte) count);
nbt.setInteger("tick", tick);
}
@ -147,6 +149,7 @@ public final class GateExpansionPulsar extends GateExpansionBuildcraft implement
isActive = nbt.getBoolean("isActive");
singlePulse = nbt.getBoolean("singlePulse");
hasPulsed = nbt.getBoolean("hasPulsed");
count = nbt.getByte("pulseCount");
tick = nbt.getInteger("tick");
}
}

View file

@ -8,10 +8,31 @@
*/
package buildcraft.transport.gates;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementManager;
public class StatementSlot {
public IStatement statement;
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;
}
}

View file

@ -147,7 +147,7 @@ public class PipeItemsWood extends Pipe<PipeTransportItems> implements IEnergyHa
for (ItemStack stack : extracted) {
if (stack == null || stack.stackSize == 0) {
battery.useEnergy(10, 10, false);
//battery.useEnergy(10, 10, false);
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 (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);
} else {