This commit is contained in:
tterrag1098 committed 2015-05-21 13:44:52 -04:00
commit 4a82b3c747
11 files changed
+260 -66

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();
@@ -96,6 +96,7 @@ public class InventoryDatabaseClient extends InventoryDatabase<ItemEntry> {
entry.count = 0;
}
clientItems.clear();
requestedItems.clear();
int count = cdi.readVariable();
while(count > 0) {
@@ -19,10 +19,8 @@ import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.BlockEio;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.painter.PainterUtil;
import crazypants.enderio.machine.painter.TileEntityPaintedBlock;
import crazypants.util.BlockCoord;
@@ -33,42 +31,41 @@ public class BlockFusedQuartz extends BlockEio {
private final static Type[] metaMapping = new Type[16];
public enum Type {
FUSED_QUARTZ("fusedQuartz", "enderio:fusedQuartz", "enderio:fusedQuartzFrame", "enderio:fusedQuartzItem"),
GLASS("fusedGlass", "enderio:fusedGlass", Config.clearGlassSameTexture ? "enderio:fusedQuartzFrame" : "enderio:fusedGlassFrame", "enderio:fusedGlassItem"),
ENLIGHTENED_FUSED_QUARTZ("enlightenedFusedQuartz", "enderio:fusedQuartz", "enderio:fusedQuartzFrame", "enderio:fusedQuartzItem"),
FUSED_QUARTZ("fusedQuartz", "enderio:fusedQuartz", "enderio:fusedQuartzFrame", "enderio:fusedQuartzItem", false, true, 0),
GLASS("fusedGlass", "enderio:fusedGlass", Config.clearGlassSameTexture ? "enderio:fusedQuartzFrame" : "enderio:fusedGlassFrame", "enderio:fusedGlassItem", false, false, 0),
ENLIGHTENED_FUSED_QUARTZ("enlightenedFusedQuartz", "enderio:fusedQuartz", "enderio:fusedQuartzFrame", "enderio:fusedQuartzItem", true, true, 0),
ENLIGHTENED_GLASS("enlightenedFusedGlass", "enderio:fusedGlass", Config.clearGlassSameTexture ? "enderio:fusedQuartzFrame" : "enderio:fusedGlassFrame",
"enderio:fusedGlassItem");
"enderio:fusedGlassItem", true, false, 0),
DARK_FUSED_QUARTZ("darkFusedQuartz", "enderio:fusedQuartz", "enderio:fusedQuartzFrame", "enderio:fusedQuartzItem", false, true, 255),
DARK_GLASS("darkFusedGlass", "enderio:fusedGlass", Config.clearGlassSameTexture ? "enderio:fusedQuartzFrame" : "enderio:fusedGlassFrame", "enderio:fusedGlassItem", false, false, 255);
final String unlocalisedName;
final String blockIcon;
final String frameIcon;
final String itemIcon;
final boolean enlightened;
final boolean blastResistance;
final int lightOpacity;
int connectedTextureMask;
private Type(String unlocalisedName, String blockIcon, String frameIcon, String itemIcon) {
private Type(String unlocalisedName, String blockIcon, String frameIcon, String itemIcon, boolean enlightened, boolean blastResistance, int lightOpacity) {
this.unlocalisedName = unlocalisedName;
this.frameIcon = frameIcon;
this.blockIcon = blockIcon;
this.itemIcon = itemIcon;
this.enlightened = enlightened;
this.blastResistance = blastResistance;
this.lightOpacity = lightOpacity;
connectedTextureMask = Config.clearGlassConnectToFusedQuartz ? ~0 : (1 << ordinal());
metaMapping[this.ordinal()] = this;
}
public boolean connectTo(int otherMeta) {
if(otherMeta == ordinal() || Config.clearGlassConnectToFusedQuartz) {
return true;
}
return (connectedTextureMask & (1 << otherMeta)) != 0;
}
switch (this) {
case FUSED_QUARTZ:
return otherMeta == ENLIGHTENED_FUSED_QUARTZ.ordinal();
case ENLIGHTENED_FUSED_QUARTZ:
return otherMeta == FUSED_QUARTZ.ordinal();
case GLASS:
return otherMeta == ENLIGHTENED_GLASS.ordinal();
case ENLIGHTENED_GLASS:
return otherMeta == GLASS.ordinal();
}
return false;
void setConnectedTexture(Type other) {
connectedTextureMask |= 1 << other.ordinal();
}
public static Type byMeta(int meta) {
@@ -76,6 +73,21 @@ public class BlockFusedQuartz extends BlockEio {
}
}
static {
Type.GLASS.setConnectedTexture(Type.ENLIGHTENED_GLASS);
Type.GLASS.setConnectedTexture(Type.DARK_GLASS);
Type.ENLIGHTENED_GLASS.setConnectedTexture(Type.GLASS);
Type.ENLIGHTENED_GLASS.setConnectedTexture(Type.DARK_GLASS);
Type.DARK_GLASS.setConnectedTexture(Type.GLASS);
Type.DARK_GLASS.setConnectedTexture(Type.ENLIGHTENED_GLASS);
Type.FUSED_QUARTZ.setConnectedTexture(Type.ENLIGHTENED_FUSED_QUARTZ);
Type.FUSED_QUARTZ.setConnectedTexture(Type.DARK_FUSED_QUARTZ);
Type.ENLIGHTENED_FUSED_QUARTZ.setConnectedTexture(Type.FUSED_QUARTZ);
Type.ENLIGHTENED_FUSED_QUARTZ.setConnectedTexture(Type.DARK_FUSED_QUARTZ);
Type.DARK_FUSED_QUARTZ.setConnectedTexture(Type.FUSED_QUARTZ);
Type.DARK_FUSED_QUARTZ.setConnectedTexture(Type.ENLIGHTENED_FUSED_QUARTZ);
}
public static BlockFusedQuartz create() {
BlockFusedQuartz result = new BlockFusedQuartz();
result.init();
@@ -103,7 +115,7 @@ public class BlockFusedQuartz extends BlockEio {
public float getExplosionResistance(Entity par1Entity, World world, int x, int y, int z, double explosionX, double explosionY, double explosionZ) {
int meta = world.getBlockMetadata(x, y, z);
Type type = Type.byMeta(meta);
if (type == Type.FUSED_QUARTZ || type == Type.ENLIGHTENED_FUSED_QUARTZ) {
if (type.blastResistance) {
return 2000;
} else {
return super.getExplosionResistance(par1Entity);
@@ -140,7 +152,9 @@ public class BlockFusedQuartz extends BlockEio {
@Override
public int getLightOpacity(IBlockAccess world, int x, int y, int z) {
return 0;
int meta = world.getBlockMetadata(x, y, z);
Type type = Type.byMeta(meta);
return type.lightOpacity;
}
@Override
@@ -150,10 +164,8 @@ public class BlockFusedQuartz extends BlockEio {
return super.getLightValue(world, x, y, z);
}
int meta = world.getBlockMetadata(x, y, z);
if(meta > 1) {
return 15;
}
return super.getLightValue(world, x, y, z);
Type type = Type.byMeta(meta);
return type.enlightened ? 15 : super.getLightValue(world, x, y, z);
}
@Override
@@ -239,13 +251,4 @@ public class BlockFusedQuartz extends BlockEio {
return false;
}
private ItemStack createItemStackForSourceBlock(int quartzBlockMeta, Block sourceBlock, int sourceBlockMetadata) {
if(sourceBlock == null) {
return null;
}
ItemStack result = new ItemStack(EnderIO.instance.itemFusedQuartzFrame, 1, quartzBlockMeta);
PainterUtil.setSourceBlock(result, sourceBlock, sourceBlockMetadata);
return result;
}
}
@@ -8,10 +8,10 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlockWithMetadata;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIOTab;
import crazypants.enderio.material.BlockFusedQuartz.Type;
import crazypants.util.Lang;
public class ItemFusedQuartz extends ItemBlockWithMetadata {
@@ -24,8 +24,8 @@ public class ItemFusedQuartz extends ItemBlockWithMetadata {
@Override
public String getUnlocalizedName(ItemStack par1ItemStack) {
int meta = par1ItemStack.getItemDamage();
meta = MathHelper.clamp_int(meta, 0, BlockFusedQuartz.Type.values().length - 1);
return "enderio.blockFusedQuartz." + BlockFusedQuartz.Type.values()[meta].unlocalisedName;
Type type = Type.byMeta(meta);
return "enderio.blockFusedQuartz." + type.unlocalisedName;
}
@Override
@@ -41,13 +41,16 @@ public class ItemFusedQuartz extends ItemBlockWithMetadata {
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) {
int meta = par1ItemStack.getItemDamage();
meta = MathHelper.clamp_int(meta, 0, BlockFusedQuartz.Type.values().length - 1);
if(meta == 0 || meta == 2) {
Type type = Type.byMeta(meta);
if (type.blastResistance) {
par3List.add(Lang.localize("blastResistant"));
}
if(meta > 1) {
if (type.enlightened) {
par3List.add(Lang.localize("lightEmitter"));
}
if (type.lightOpacity > 0) {
par3List.add(Lang.localize("lightBlocker"));
}
}