mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-20 12:19:55 +00:00
Merge pull request #1924 from MatthiasMann/farmstation_locked_slots
save locked slots state when picking up a Farming Station
This commit is contained in:
commit
136bc71d14
6 files changed
+55
-51
No files matched your search
@@ -14,10 +14,13 @@ import crazypants.enderio.gui.ToggleButtonEIO;
|
||||
import crazypants.enderio.machine.gui.GuiPoweredMachineBase;
|
||||
import crazypants.render.ColorUtil;
|
||||
import crazypants.render.RenderUtil;
|
||||
import crazypants.util.Lang;
|
||||
import crazypants.vecmath.Vector4f;
|
||||
|
||||
public class GuiFarmStation extends GuiPoweredMachineBase<TileFarmStation> {
|
||||
|
||||
|
||||
private static final int LOCK_ID = 1234;
|
||||
|
||||
public GuiFarmStation(InventoryPlayer par1InventoryPlayer, TileFarmStation machine) {
|
||||
super(machine, new FarmStationContainer(par1InventoryPlayer, machine));
|
||||
}
|
||||
@@ -30,25 +33,23 @@ public class GuiFarmStation extends GuiPoweredMachineBase<TileFarmStation> {
|
||||
int x = getGuiLeft() + 36;
|
||||
int y = getGuiTop() + 36;
|
||||
|
||||
buttonList.add(createButton(x, y));
|
||||
buttonList.add(createButton(x + 52, y));
|
||||
buttonList.add(createButton(x, y + 20));
|
||||
buttonList.add(createButton(x + 52, y + 20));
|
||||
id = 0;
|
||||
buttonList.add(createLockButton(TileFarmStation.minSupSlot + 0, x, y));
|
||||
buttonList.add(createLockButton(TileFarmStation.minSupSlot + 1, x + 52, y));
|
||||
buttonList.add(createLockButton(TileFarmStation.minSupSlot + 2, x, y + 20));
|
||||
buttonList.add(createLockButton(TileFarmStation.minSupSlot + 3, x + 52, y + 20));
|
||||
}
|
||||
|
||||
private int id = 0;
|
||||
private IconButtonEIO createButton(int x, int y) {
|
||||
return new ToggleButtonEIO(this, id, x, y, IconEIO.FARM_UNLOCK, IconEIO.FARM_LOCK).setSelected(getTileEntity().lockedSlots.contains(id++ + getTileEntity().minSupSlot));
|
||||
private IconButtonEIO createLockButton(int slot, int x, int y) {
|
||||
return new ToggleButtonEIO(this, LOCK_ID+slot, x, y, IconEIO.FARM_UNLOCK, IconEIO.FARM_LOCK).setSelected(getTileEntity().isSlotLocked(slot));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawForegroundImpl(int mouseX, int mouseY) {
|
||||
super.drawForegroundImpl(mouseX, mouseY);
|
||||
|
||||
if(inventorySlots.inventorySlots.size() >= getTileEntity().maxSupSlot && !isConfigOverlayEnabled()) {
|
||||
for (int i : getTileEntity().lockedSlots) {
|
||||
if (i < inventorySlots.inventorySlots.size()) { // hack to allow old broken farms to be opened
|
||||
if(!isConfigOverlayEnabled()) {
|
||||
for(int i=TileFarmStation.minSupSlot ; i<=TileFarmStation.maxSupSlot ; i++) {
|
||||
if(getTileEntity().isSlotLocked(i)) {
|
||||
Slot slot = inventorySlots.getSlot(i);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
RenderUtil.renderQuad2D(slot.xDisplayPosition, slot.yDisplayPosition, 0, 16, 16, new Vector4f(0, 0, 0, 0.5));
|
||||
@@ -81,8 +82,8 @@ public class GuiFarmStation extends GuiPoweredMachineBase<TileFarmStation> {
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton b) {
|
||||
if (b instanceof ToggleButtonEIO) {
|
||||
getTileEntity().toggleLockedState(b.id);
|
||||
if (b.id >= LOCK_ID+TileFarmStation.minSupSlot && b.id <= LOCK_ID+TileFarmStation.maxSupSlot) {
|
||||
getTileEntity().toggleLockedState(b.id - LOCK_ID);
|
||||
}
|
||||
super.actionPerformed(b);
|
||||
}
|
||||
@@ -92,7 +93,8 @@ public class GuiFarmStation extends GuiPoweredMachineBase<TileFarmStation> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPowerOutputLabel() {
|
||||
return "Base Use: ";
|
||||
return Lang.localize("farm.gui.baseUse");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.BitSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
@@ -10,8 +9,6 @@ import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemAxe;
|
||||
import net.minecraft.item.ItemHoe;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
@@ -39,6 +36,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
|
||||
public enum ToolType {
|
||||
HOE {
|
||||
@Override
|
||||
boolean match(ItemStack item) {
|
||||
for (ItemStack stack : Config.farmHoes) {
|
||||
if (stack.getItem() == item.getItem()) {
|
||||
@@ -83,15 +81,13 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
private BlockCoord lastScanned;
|
||||
private EntityPlayerMP farmerJoe;
|
||||
|
||||
private int farmSize = Config.farmDefaultSize;
|
||||
private static final int minToolSlot = 0;
|
||||
private static final int maxToolSlot = 1;
|
||||
|
||||
private int minToolSlot = 0;
|
||||
private int maxToolSlot = 1;
|
||||
|
||||
int minSupSlot = maxToolSlot + 1;
|
||||
int maxSupSlot = minSupSlot + 4;
|
||||
public static final int minSupSlot = maxToolSlot + 1;
|
||||
public static final int maxSupSlot = minSupSlot + 4;
|
||||
|
||||
List<Integer> lockedSlots = new ArrayList<Integer>();
|
||||
private final BitSet lockedSlots = new BitSet();
|
||||
|
||||
private final int upgradeBonusSize = 2;
|
||||
|
||||
@@ -108,7 +104,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
}
|
||||
|
||||
public int getFarmSize() {
|
||||
return farmSize + getUpgradeDist();
|
||||
return Config.farmDefaultSize + getUpgradeDist();
|
||||
}
|
||||
|
||||
public void actionPerformed(boolean isAxe) {
|
||||
@@ -408,7 +404,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private boolean isOutputFull() {
|
||||
@@ -424,10 +419,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
public boolean hasSeed(ItemStack seeds, BlockCoord bc) {
|
||||
int slot = getSupplySlotForCoord(bc);
|
||||
ItemStack inv = inventory[slot];
|
||||
if(inv != null && (inv.stackSize > 1 || !isSlotLocked(slot)) && inv.isItemEqual(seeds)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return inv != null && (inv.stackSize > 1 || !isSlotLocked(slot)) && inv.isItemEqual(seeds);
|
||||
}
|
||||
|
||||
public ItemStack takeSeedFromSupplies(ItemStack stack, BlockCoord forBlock) {
|
||||
@@ -555,19 +547,15 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
return new BlockCoord(nextX, lastScanned.y, nextZ);
|
||||
}
|
||||
|
||||
public void toggleLockedState(int buttonID) {
|
||||
public void toggleLockedState(int slot) {
|
||||
if (worldObj.isRemote) {
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketFarmLockedSlot(this, buttonID));
|
||||
}
|
||||
buttonID += minSupSlot;
|
||||
if (lockedSlots.contains(buttonID)) {
|
||||
lockedSlots.remove((Integer) buttonID); // hard cast otherwise it removes by index
|
||||
} else {
|
||||
lockedSlots.add(buttonID);
|
||||
PacketHandler.INSTANCE.sendToServer(new PacketFarmLockedSlot(this, slot));
|
||||
}
|
||||
lockedSlots.flip(slot);
|
||||
}
|
||||
|
||||
public boolean isSlotLocked(int slot) {
|
||||
return lockedSlots.contains(slot);
|
||||
return lockedSlots.get(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -627,11 +615,17 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
public void readCustomNBT(NBTTagCompound nbtRoot) {
|
||||
super.readCustomNBT(nbtRoot);
|
||||
currentTask = createTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCommon(NBTTagCompound nbtRoot) {
|
||||
super.readCommon(nbtRoot);
|
||||
lockedSlots.clear();
|
||||
for (int i : nbtRoot.getIntArray("lockedSlots")) {
|
||||
lockedSlots.add(i);
|
||||
lockedSlots.set(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IPoweredTask createTask() {
|
||||
return new ContinuousTask(getPowerUsePerTick());
|
||||
}
|
||||
@@ -640,11 +634,18 @@ public class TileFarmStation extends AbstractPoweredTaskEntity {
|
||||
public void writeCustomNBT(NBTTagCompound nbtRoot) {
|
||||
super.writeCustomNBT(nbtRoot);
|
||||
nbtRoot.setBoolean("isActive", isActive());
|
||||
int[] locked = new int[lockedSlots.size()];
|
||||
for (int i = 0; i < lockedSlots.size(); i++) {
|
||||
locked[i] = lockedSlots.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
if(!lockedSlots.isEmpty()) {
|
||||
int[] locked = new int[lockedSlots.cardinality()];
|
||||
for (int i=0,bit=-1; (bit=lockedSlots.nextSetBit(bit+1)) >= 0; i++) {
|
||||
locked[i] = bit;
|
||||
}
|
||||
nbtRoot.setIntArray("lockedSlots", locked);
|
||||
}
|
||||
nbtRoot.setIntArray("lockedSlots", locked);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public abstract class GuiPoweredMachineBase<T extends AbstractPoweredMachineEnti
|
||||
}
|
||||
|
||||
protected void updatePowerBarTooltip(List<String> text) {
|
||||
text.add(getPowerOutputLabel() + PowerDisplayUtil.formatPower(getPowerOutputValue()) + " " + PowerDisplayUtil.abrevation()
|
||||
text.add(getPowerOutputLabel() + " " + PowerDisplayUtil.formatPower(getPowerOutputValue()) + " " + PowerDisplayUtil.abrevation()
|
||||
+ PowerDisplayUtil.perTickStr());
|
||||
text.add(PowerDisplayUtil.formatStoredPower(getTileEntity().getEnergyStored(), getTileEntity().getCapacitor().getMaxEnergyStored()));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user