Merge branch 'tables-actions' of https://github.com/Prototik/BuildCraft into Prototik-tables-actions

This commit is contained in:
SpaceToad 2014-05-07 11:44:02 +02:00
commit 308bf078a9
4 changed files with 48 additions and 73 deletions

View file

@ -32,13 +32,9 @@ import net.minecraft.util.IChatComponent;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftSilicon; import buildcraft.BuildCraftSilicon;
import buildcraft.api.core.IInvSlot; import buildcraft.api.core.IInvSlot;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionReceptor;
import buildcraft.api.power.ILaserTarget; import buildcraft.api.power.ILaserTarget;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuffer; import buildcraft.core.TileBuffer;
import buildcraft.core.inventory.InvUtils; import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.InventoryCopy; import buildcraft.core.inventory.InventoryCopy;
@ -56,7 +52,7 @@ import buildcraft.core.utils.CraftingHelper;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
public class TileAdvancedCraftingTable extends TileLaserTableBase implements IInventory, ILaserTarget, IMachine, IActionReceptor, ISidedInventory { public class TileAdvancedCraftingTable extends TileLaserTableBase implements IInventory, ILaserTarget, ISidedInventory {
private static final int[] SLOTS = Utils.createSlotArray(0, 24); private static final int[] SLOTS = Utils.createSlotArray(0, 24);
private static final EnumSet<ForgeDirection> SEARCH_SIDES = EnumSet.of(ForgeDirection.DOWN, ForgeDirection.NORTH, ForgeDirection.SOUTH, private static final EnumSet<ForgeDirection> SEARCH_SIDES = EnumSet.of(ForgeDirection.DOWN, ForgeDirection.NORTH, ForgeDirection.SOUTH,
@ -70,7 +66,6 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
private boolean justCrafted; private boolean justCrafted;
private InternalPlayer internalPlayer; private InternalPlayer internalPlayer;
private IRecipe currentRecipe; private IRecipe currentRecipe;
private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
private TileBuffer[] cache; private TileBuffer[] cache;
private InventoryCraftResult craftResult; private InventoryCraftResult craftResult;
private InternalInventoryCrafting internalInventoryCrafting; private InternalInventoryCrafting internalInventoryCrafting;
@ -252,7 +247,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
craftSlot = new SlotCrafting(internalPlayer, internalInventoryCrafting, craftResult, 0, 0, 0); craftSlot = new SlotCrafting(internalPlayer, internalInventoryCrafting, craftResult, 0, 0, 0);
updateRecipe(); updateRecipe();
} }
if (!!worldObj.isRemote) { if (worldObj.isRemote) {
return; return;
} }
if (lastMode == ActionMachineControl.Mode.Off) { if (lastMode == ActionMachineControl.Mode.Off) {
@ -445,22 +440,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
@Override @Override
public boolean isActive() { public boolean isActive() {
return requiresLaserEnergy(); return requiresLaserEnergy() && super.isActive();
}
@Override
public boolean manageFluids() {
return false;
}
@Override
public boolean manageSolids() {
return false;
}
@Override
public boolean allowAction(IAction action) {
return action == BuildCraftCore.actionOn || action == BuildCraftCore.actionOff;
} }
@Override @Override
@ -483,15 +463,6 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
return slot < 15; return slot < 15;
} }
@Override
public void actionActivated(IAction action) {
if (action == BuildCraftCore.actionOn) {
lastMode = ActionMachineControl.Mode.On;
} else if (action == BuildCraftCore.actionOff) {
lastMode = ActionMachineControl.Mode.Off;
}
}
@Override @Override
public boolean hasCustomInventoryName() { public boolean hasCustomInventoryName() {
return false; return false;

View file

@ -26,13 +26,13 @@ import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftSilicon; import buildcraft.BuildCraftSilicon;
import buildcraft.api.gates.IAction;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.IMachine; import buildcraft.core.IMachine;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketNBT; import buildcraft.core.network.PacketNBT;
import buildcraft.core.recipes.AssemblyRecipeManager; import buildcraft.core.recipes.AssemblyRecipeManager;
import buildcraft.core.recipes.AssemblyRecipeManager.AssemblyRecipe; import buildcraft.core.recipes.AssemblyRecipeManager.AssemblyRecipe;
import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
@ -94,7 +94,7 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
} }
} }
if (getEnergy() >= currentRecipe.getEnergyCost()) { if (getEnergy() >= currentRecipe.getEnergyCost() && lastMode != ActionMachineControl.Mode.Off) {
setEnergy(0); setEnergy(0);
if (currentRecipe.canBeDone(this)) { if (currentRecipe.canBeDone(this)) {
@ -297,27 +297,12 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
@Override @Override
public boolean isActive() { public boolean isActive() {
return currentRecipe != null; return currentRecipe != null && super.isActive();
}
@Override
public boolean manageFluids() {
return false;
}
@Override
public boolean manageSolids() {
return false;
}
@Override
public boolean allowAction(IAction action) {
return false;
} }
@Override @Override
public boolean canCraft() { public boolean canCraft() {
return currentRecipe != null; return isActive();
} }
@Override @Override

View file

@ -14,19 +14,18 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.IAction;
import buildcraft.api.recipes.BuildcraftRecipes; import buildcraft.api.recipes.BuildcraftRecipes;
import buildcraft.api.recipes.IIntegrationRecipeManager.IIntegrationRecipe; import buildcraft.api.recipes.IIntegrationRecipeManager.IIntegrationRecipe;
import buildcraft.core.IMachine;
import buildcraft.core.inventory.ITransactor; import buildcraft.core.inventory.ITransactor;
import buildcraft.core.inventory.InventoryMapper; import buildcraft.core.inventory.InventoryMapper;
import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.inventory.StackHelper; import buildcraft.core.inventory.StackHelper;
import buildcraft.core.inventory.Transactor; import buildcraft.core.inventory.Transactor;
import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
public class TileIntegrationTable extends TileLaserTableBase implements ISidedInventory, IMachine { public class TileIntegrationTable extends TileLaserTableBase implements ISidedInventory {
public static final int SLOT_INPUT_A = 0; public static final int SLOT_INPUT_A = 0;
public static final int SLOT_INPUT_B = 1; public static final int SLOT_INPUT_B = 1;
@ -116,7 +115,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
canCraft = true; canCraft = true;
if (getEnergy() >= currentRecipe.getEnergyCost()) { if (getEnergy() >= currentRecipe.getEnergyCost() && lastMode != ActionMachineControl.Mode.Off) {
setEnergy(0); setEnergy(0);
inv.decrStackSize(SLOT_INPUT_A, 1); inv.decrStackSize(SLOT_INPUT_A, 1);
inv.decrStackSize(SLOT_INPUT_B, 1); inv.decrStackSize(SLOT_INPUT_B, 1);
@ -173,7 +172,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
@Override @Override
public boolean canCraft() { public boolean canCraft() {
return canCraft; return canCraft && isActive();
} }
@Override @Override
@ -239,21 +238,6 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
@Override @Override
public boolean isActive() { public boolean isActive() {
return currentRecipe != null; return currentRecipe != null && super.isActive();
}
@Override
public boolean manageFluids() {
return false;
}
@Override
public boolean manageSolids() {
return false;
}
@Override
public boolean allowAction(IAction action) {
return false;
} }
} }

View file

@ -15,15 +15,21 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import buildcraft.BuildCraftCore;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionReceptor;
import buildcraft.api.power.ILaserTarget; import buildcraft.api.power.ILaserTarget;
import buildcraft.core.IMachine;
import buildcraft.core.TileBuildCraft; import buildcraft.core.TileBuildCraft;
import buildcraft.core.inventory.SimpleInventory; import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.utils.AverageUtil; import buildcraft.core.utils.AverageUtil;
public abstract class TileLaserTableBase extends TileBuildCraft implements ILaserTarget, IInventory { public abstract class TileLaserTableBase extends TileBuildCraft implements ILaserTarget, IInventory, IActionReceptor, IMachine {
public double clientRequiredEnergy = 0; public double clientRequiredEnergy = 0;
protected SimpleInventory inv = new SimpleInventory(getSizeInventory(), "inv", 64); protected SimpleInventory inv = new SimpleInventory(getSizeInventory(), "inv", 64);
protected ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
private double energy = 0; private double energy = 0;
private int recentEnergyAverage; private int recentEnergyAverage;
private AverageUtil recentEnergyAverageUtil = new AverageUtil(20); private AverageUtil recentEnergyAverageUtil = new AverageUtil(20);
@ -191,4 +197,33 @@ public abstract class TileLaserTableBase extends TileBuildCraft implements ILase
iCrafting.sendProgressBarUpdate(container, 4, lRecentEnergy & 0xFFFF); iCrafting.sendProgressBarUpdate(container, 4, lRecentEnergy & 0xFFFF);
iCrafting.sendProgressBarUpdate(container, 5, (lRecentEnergy >>> 16) & 0xFFFF); iCrafting.sendProgressBarUpdate(container, 5, (lRecentEnergy >>> 16) & 0xFFFF);
} }
@Override
public boolean isActive() {
return lastMode != ActionMachineControl.Mode.Off;
}
@Override
public boolean manageFluids() {
return false;
}
@Override
public boolean manageSolids() {
return false;
}
@Override
public boolean allowAction(IAction action) {
return action == BuildCraftCore.actionOn || action == BuildCraftCore.actionOff;
}
@Override
public void actionActivated(IAction action) {
if (action == BuildCraftCore.actionOn) {
lastMode = ActionMachineControl.Mode.On;
} else if (action == BuildCraftCore.actionOff) {
lastMode = ActionMachineControl.Mode.Off;
}
}
} }