Merge pull request #2483 from MatthiasMann/itemconduit_shiftclick_upgrades

allow shift clicking item conduit upgrades (filters, speed, etc)
This commit is contained in:
CrazyPants committed 2015-05-21 22:31:34 +08:00
commit 8deff082af
5 files changed
+142 -23

No files matched your search

@@ -45,6 +45,7 @@ import crazypants.enderio.conduit.gui.GuiExternalConnection;
import crazypants.enderio.conduit.gui.GuiExternalConnectionSelector;
import crazypants.enderio.conduit.gui.PacketFluidFilter;
import crazypants.enderio.conduit.gui.PacketOpenConduitUI;
import crazypants.enderio.conduit.gui.PacketSlotVisibility;
import crazypants.enderio.conduit.gui.item.PacketExistingItemFilterSnapshot;
import crazypants.enderio.conduit.gui.item.PacketModItemFilter;
import crazypants.enderio.conduit.liquid.PacketFluidLevel;
@@ -88,6 +89,7 @@ public class BlockConduitBundle extends BlockEio implements IGuiHandler, IFacade
PacketHandler.INSTANCE.registerMessage(PacketRedstoneConduitOutputStrength.class, PacketRedstoneConduitOutputStrength.class, PacketHandler.nextID(),
Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketOpenConduitUI.class, PacketOpenConduitUI.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketSlotVisibility.class, PacketSlotVisibility.class, PacketHandler.nextID(), Side.SERVER);
BlockConduitBundle result = new BlockConduitBundle();
result.init();
@@ -10,12 +10,15 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.EnderIO;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.conduit.gui.item.InventoryUpgrades;
import crazypants.enderio.conduit.item.IItemConduit;
import crazypants.enderio.conduit.item.SpeedUpgrade;
import crazypants.enderio.network.PacketHandler;
import crazypants.util.ItemUtil;
public class ExternalConnectionContainer extends Container {
@@ -26,6 +29,7 @@ public class ExternalConnectionContainer extends Container {
private static final int outputFilterUpgradeSlot = 36;
private static final int inputFilterUpgradeSlot = 37;
private static final int speedUpgradeSlot = 38;
private static final int functionUpgradeSlot = 39;
private Slot slotSpeedUpgrades;
private Slot slotFunctionUpgrades;
@@ -128,20 +132,17 @@ public class ExternalConnectionContainer extends Container {
return slot != null && slot.getHasStack();
}
public void setInputSlotsVisible(boolean visible) {
public void setInoutSlotsVisible(boolean inputVisible, boolean outputVisible) {
if(itemConduit == null) {
return;
}
setSlotsVisible(visible, inputFilterUpgradeSlot, inputFilterUpgradeSlot + 1);
setSlotsVisible(visible, speedUpgradeSlot, speedUpgradeSlot + 1);
}
public void setOutputSlotsVisible(boolean visible) {
if(itemConduit == null) {
return;
setSlotsVisible(inputVisible, inputFilterUpgradeSlot, inputFilterUpgradeSlot + 1);
setSlotsVisible(inputVisible, speedUpgradeSlot, speedUpgradeSlot + 1);
setSlotsVisible(outputVisible, outputFilterUpgradeSlot, outputFilterUpgradeSlot + 1);
World world = itemConduit.getBundle().getWorld();
if(world.isRemote) {
PacketHandler.INSTANCE.sendToServer(new PacketSlotVisibility(inputVisible, outputVisible));
}
setSlotsVisible(visible, outputFilterUpgradeSlot, outputFilterUpgradeSlot + 1);
}
public void setInventorySlotsVisible(boolean visible) {
@@ -169,10 +170,7 @@ public class ExternalConnectionContainer extends Container {
@Override
public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
ItemStack st = par4EntityPlayer.inventory.getItemStack();
if(st != null && st.getItem() == EnderIO.itemExtractSpeedUpgrade) {
SpeedUpgrade speedUpgrade = EnderIO.itemExtractSpeedUpgrade.getSpeedUpgrade(st);
speedUpgradeSlotLimit = speedUpgrade.maxStackSize;
}
setSpeedUpgradeSlotLimit(st);
try {
return super.slotClick(par1, par2, par3, par4EntityPlayer);
} catch (Exception e) {
@@ -182,9 +180,88 @@ public class ExternalConnectionContainer extends Container {
}
}
private void setSpeedUpgradeSlotLimit(ItemStack st) {
if(st != null && st.getItem() == EnderIO.itemExtractSpeedUpgrade) {
SpeedUpgrade speedUpgrade = EnderIO.itemExtractSpeedUpgrade.getSpeedUpgrade(st);
speedUpgradeSlotLimit = speedUpgrade.maxStackSize;
}
}
private boolean mergeItemStackSpecial(ItemStack origStack, Slot targetSlot) {
if (!targetSlot.isItemValid(origStack)) {
return false;
}
setSpeedUpgradeSlotLimit(origStack);
ItemStack curStack = targetSlot.getStack();
int maxStackSize = Math.min(origStack.getMaxStackSize(), targetSlot.getSlotStackLimit());
if(curStack == null) {
curStack = origStack.copy();
curStack.stackSize = Math.min(origStack.stackSize, maxStackSize);
origStack.stackSize -= curStack.stackSize;
targetSlot.putStack(curStack);
targetSlot.onSlotChanged();
return true;
} else if(ItemUtil.areStackMergable(curStack, origStack)) {
int mergedSize = curStack.stackSize + origStack.stackSize;
if(mergedSize <= maxStackSize) {
origStack.stackSize = 0;
curStack.stackSize = mergedSize;
targetSlot.onSlotChanged();
return true;
} else if(curStack.stackSize < maxStackSize) {
origStack.stackSize -= maxStackSize - curStack.stackSize;
curStack.stackSize = maxStackSize;
targetSlot.onSlotChanged();
return true;
}
}
return false;
}
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
return null;
ItemStack copystack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
if(slot != null && slot.getHasStack()) {
ItemStack origStack = slot.getStack();
copystack = origStack.copy();
boolean merged = false;
if (slotIndex < outputFilterUpgradeSlot) {
for (int targetSlotIdx = outputFilterUpgradeSlot; targetSlotIdx <= functionUpgradeSlot; targetSlotIdx++) {
Slot targetSlot = (Slot) inventorySlots.get(targetSlotIdx);
if(targetSlot.xDisplayPosition >= 0 && mergeItemStackSpecial(origStack, targetSlot)) {
merged = true;
break;
}
}
} else {
merged = mergeItemStack(origStack, 0, outputFilterUpgradeSlot, false);
}
if(!merged) {
return null;
}
slot.onSlotChange(origStack, copystack);
if(origStack.stackSize == 0) {
slot.putStack((ItemStack) null);
} else {
slot.onSlotChanged();
}
if(origStack.stackSize == copystack.stackSize) {
return null;
}
slot.onPickupFromSlot(entityPlayer, origStack);
}
return copystack;
}
private class FilterSlot extends Slot {
@@ -72,8 +72,7 @@ public class GuiExternalConnection extends GuiContainerBase {
ySize = 166 + 29;
xSize = 206;
container.setInputSlotsVisible(false);
container.setOutputSlotsVisible(false);
container.setInoutSlotsVisible(false, false);
container.setInventorySlotsVisible(false);
List<IConduit> cons = new ArrayList<IConduit>(bundle.getConduits());
@@ -0,0 +1,44 @@
package crazypants.enderio.conduit.gui;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayerMP;
public class PacketSlotVisibility implements IMessage, IMessageHandler<PacketSlotVisibility, IMessage> {
private boolean inputVisible;
private boolean outputVisible;
public PacketSlotVisibility() {
}
public PacketSlotVisibility(boolean inputVisible, boolean outputVisible) {
this.inputVisible = inputVisible;
this.outputVisible = outputVisible;
}
@Override
public void fromBytes(ByteBuf bb) {
int value = bb.readUnsignedByte();
inputVisible = (value & 1) != 0;
outputVisible = (value & 2) != 0;
}
@Override
public void toBytes(ByteBuf bb) {
int value = (inputVisible ? 1 : 0) | (outputVisible ? 2 : 0);
bb.writeByte(value);
}
@Override
public IMessage onMessage(PacketSlotVisibility message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
if(player.openContainer instanceof ExternalConnectionContainer) {
ExternalConnectionContainer ecc = (ExternalConnectionContainer) player.openContainer;
ecc.setInoutSlotsVisible(message.inputVisible, message.outputVisible);
}
return null;
}
}
@@ -227,15 +227,13 @@ public class ItemSettings extends BaseSettingsPanel {
} else if(showInput) {
activeFilter = itemConduit.getInputFilter(gui.getDir());
gui.getContainer().setInventorySlotsVisible(true);
gui.getContainer().setInputSlotsVisible(true);
gui.getContainer().setOutputSlotsVisible(false);
gui.getContainer().setInoutSlotsVisible(true, false);
if(activeFilter != null) {
filterGui = getFilterGui(activeFilter, true);
}
} else if(showOutput) {
activeFilter = itemConduit.getOutputFilter(gui.getDir());
gui.getContainer().setInputSlotsVisible(false);
gui.getContainer().setOutputSlotsVisible(true);
gui.getContainer().setInoutSlotsVisible(false, true);
gui.getContainer().setInventorySlotsVisible(true);
if(activeFilter != null) {
filterGui = getFilterGui(activeFilter, false);
@@ -426,8 +424,7 @@ public class ItemSettings extends BaseSettingsPanel {
@Override
public void deactivate() {
gui.getContainer().setInventorySlotsVisible(false);
gui.getContainer().setInputSlotsVisible(false);
gui.getContainer().setOutputSlotsVisible(false);
gui.getContainer().setInoutSlotsVisible(false, false);
rsB.detach();
colorB.detach();
roundRobinB.detach();