Implement On/Off actions for the all tables
This commit is contained in:
parent
492b2805bf
commit
082794a7d2
4 changed files with 48 additions and 73 deletions
|
@ -32,13 +32,9 @@ import net.minecraft.util.IChatComponent;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.gates.IAction;
|
||||
import buildcraft.api.gates.IActionReceptor;
|
||||
import buildcraft.api.power.ILaserTarget;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.TileBuffer;
|
||||
import buildcraft.core.inventory.InvUtils;
|
||||
import buildcraft.core.inventory.InventoryCopy;
|
||||
|
@ -56,7 +52,7 @@ import buildcraft.core.utils.CraftingHelper;
|
|||
import buildcraft.core.utils.StringUtils;
|
||||
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 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 InternalPlayer internalPlayer;
|
||||
private IRecipe currentRecipe;
|
||||
private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
|
||||
private TileBuffer[] cache;
|
||||
private InventoryCraftResult craftResult;
|
||||
private InternalInventoryCrafting internalInventoryCrafting;
|
||||
|
@ -252,7 +247,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
craftSlot = new SlotCrafting(internalPlayer, internalInventoryCrafting, craftResult, 0, 0, 0);
|
||||
updateRecipe();
|
||||
}
|
||||
if (!!worldObj.isRemote) {
|
||||
if (worldObj.isRemote) {
|
||||
return;
|
||||
}
|
||||
if (lastMode == ActionMachineControl.Mode.Off) {
|
||||
|
@ -445,22 +440,7 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return requiresLaserEnergy();
|
||||
}
|
||||
|
||||
@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;
|
||||
return requiresLaserEnergy() && super.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -483,15 +463,6 @@ public class TileAdvancedCraftingTable extends TileLaserTableBase implements IIn
|
|||
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
|
||||
public boolean hasCustomInventoryName() {
|
||||
return false;
|
||||
|
|
|
@ -26,13 +26,13 @@ import net.minecraftforge.common.util.Constants;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftSilicon;
|
||||
import buildcraft.api.gates.IAction;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.network.PacketIds;
|
||||
import buildcraft.core.network.PacketNBT;
|
||||
import buildcraft.core.recipes.AssemblyRecipeManager;
|
||||
import buildcraft.core.recipes.AssemblyRecipeManager.AssemblyRecipe;
|
||||
import buildcraft.core.triggers.ActionMachineControl;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
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);
|
||||
|
||||
if (currentRecipe.canBeDone(this)) {
|
||||
|
@ -297,27 +297,12 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
|
|||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return currentRecipe != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean manageFluids() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean manageSolids() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowAction(IAction action) {
|
||||
return false;
|
||||
return currentRecipe != null && super.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraft() {
|
||||
return currentRecipe != null;
|
||||
return isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,19 +14,18 @@ import net.minecraft.item.ItemStack;
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.gates.IAction;
|
||||
import buildcraft.api.recipes.BuildcraftRecipes;
|
||||
import buildcraft.api.recipes.IIntegrationRecipeManager.IIntegrationRecipe;
|
||||
import buildcraft.core.IMachine;
|
||||
import buildcraft.core.inventory.ITransactor;
|
||||
import buildcraft.core.inventory.InventoryMapper;
|
||||
import buildcraft.core.inventory.SimpleInventory;
|
||||
import buildcraft.core.inventory.StackHelper;
|
||||
import buildcraft.core.inventory.Transactor;
|
||||
import buildcraft.core.triggers.ActionMachineControl;
|
||||
import buildcraft.core.utils.StringUtils;
|
||||
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_B = 1;
|
||||
|
@ -116,7 +115,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
|
|||
|
||||
canCraft = true;
|
||||
|
||||
if (getEnergy() >= currentRecipe.getEnergyCost()) {
|
||||
if (getEnergy() >= currentRecipe.getEnergyCost() && lastMode != ActionMachineControl.Mode.Off) {
|
||||
setEnergy(0);
|
||||
inv.decrStackSize(SLOT_INPUT_A, 1);
|
||||
inv.decrStackSize(SLOT_INPUT_B, 1);
|
||||
|
@ -173,7 +172,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
|
|||
|
||||
@Override
|
||||
public boolean canCraft() {
|
||||
return canCraft;
|
||||
return canCraft && isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -239,21 +238,6 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
|
|||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return currentRecipe != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean manageFluids() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean manageSolids() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowAction(IAction action) {
|
||||
return false;
|
||||
return currentRecipe != null && super.isActive();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,21 @@ import net.minecraft.inventory.IInventory;
|
|||
import net.minecraft.item.ItemStack;
|
||||
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.core.IMachine;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.inventory.SimpleInventory;
|
||||
import buildcraft.core.triggers.ActionMachineControl;
|
||||
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;
|
||||
protected SimpleInventory inv = new SimpleInventory(getSizeInventory(), "inv", 64);
|
||||
protected ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
|
||||
private double energy = 0;
|
||||
private int recentEnergyAverage;
|
||||
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, 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue