Further improved the routing GUI by allowing an amount to be typed into the amount bar

This commit is contained in:
WayofTime 2016-08-31 16:19:20 -04:00
parent 4a21e6cbf0
commit fd684588d4
7 changed files with 152 additions and 77 deletions

View file

@ -8,6 +8,7 @@ Version 2.0.4-57
- Implemented a bit of framework for some T5 shenanigans.
- Fixed the Incense Altar so it properly detected the south sides of the altar.
- Updated the Filtered Item Routing Nodes' GUI so that it behaved less like ass. Also added the necessary nbt porting code.
- Further improved the routing GUI by allowing an amount to be typed into the amount bar.
- Updated the toggleable sigils so they drain the user's LP based on the user's total ticks existed instead of the world time. This is to solve the doDaylightCycle glitch in this scenario.
------------------------------------------------------

View file

@ -1,7 +1,5 @@
package WayofTime.bloodmagic.client.gui;
import io.netty.buffer.Unpooled;
import java.io.IOException;
import net.minecraft.client.gui.GuiButton;
@ -9,21 +7,20 @@ import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketBuffer;
import net.minecraft.network.play.client.CPacketCustomPayload;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.ItemRouterAmountPacketProcessor;
import WayofTime.bloodmagic.network.ItemRouterButtonPacketProcessor;
import WayofTime.bloodmagic.tile.container.ContainerItemRoutingNode;
import WayofTime.bloodmagic.tile.routing.TileFilteredRoutingNode;
import WayofTime.bloodmagic.util.GhostItemHelper;
@SideOnly(Side.CLIENT)
public class GuiItemRoutingNode extends GuiContainer
@ -82,9 +79,9 @@ public class GuiItemRoutingNode extends GuiContainer
this.buttonList.add(this.decrementButton = new GuiButton(7, left + 133, top + 50, 9, 18, "<"));
disableDirectionalButton(inventory.currentActiveSlot);
this.textBox = new GuiTextField(0, this.fontRendererObj, left + 90, top + 73, 64, 12);
this.textBox = new GuiTextField(0, this.fontRendererObj, left + 94, top + 37, 70, 12);
this.textBox.setEnableBackgroundDrawing(false);
this.textBox.setText("Test");
this.textBox.setText("");
}
@Override
@ -92,26 +89,38 @@ public class GuiItemRoutingNode extends GuiContainer
{
if (this.textBox.textboxKeyTyped(typedChar, keyCode))
{
// System.out.println(typedChar + ", " + keyCode);
// this.renameItem();
if (container.lastGhostSlotClicked != -1)
{
// this.renameItem();
String str = this.textBox.getText();
int amount = 0;
if (!str.isEmpty())
{
try
{
Integer testVal = Integer.decode(str);
if (testVal != null)
{
amount = testVal.intValue();
}
} catch (NumberFormatException d)
{
}
}
// inventory.setGhostItemAmount(container.lastGhostSlotClicked, amount);
setValueOfGhostItemInSlot(container.lastGhostSlotClicked, amount);
}
} else
{
super.keyTyped(typedChar, keyCode);
}
}
private void renameItem()
private void setValueOfGhostItemInSlot(int ghostItemSlot, int amount)
{
String s = this.textBox.getText();
Slot slot = this.container.getSlot(1);
if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && s.equals(slot.getStack().getDisplayName()))
{
s = "";
}
// this.container.updateItemName(s);
this.mc.thePlayer.connection.sendPacket(new CPacketCustomPayload("MC|ItemName", (new PacketBuffer(Unpooled.buffer())).writeString(s)));
BloodMagicPacketHandler.INSTANCE.sendToServer(new ItemRouterAmountPacketProcessor(ghostItemSlot, amount, inventory.getPos(), inventory.getWorld()));
}
/**
@ -122,6 +131,19 @@ public class GuiItemRoutingNode extends GuiContainer
{
super.mouseClicked(mouseX, mouseY, mouseButton);
this.textBox.mouseClicked(mouseX, mouseY, mouseButton);
if (container.lastGhostSlotClicked != -1)
{
Slot slot = container.getSlot(container.lastGhostSlotClicked + 1);
ItemStack stack = slot.getStack();
if (stack != null)
{
int amount = GhostItemHelper.getItemGhostAmount(stack);
this.textBox.setText("" + amount);
} else
{
this.textBox.setText("");
}
}
}
/**
@ -131,10 +153,6 @@ public class GuiItemRoutingNode extends GuiContainer
public void drawScreen(int mouseX, int mouseY, float partialTicks)
{
super.drawScreen(mouseX, mouseY, partialTicks);
GlStateManager.disableLighting();
GlStateManager.disableBlend();
this.textBox.drawTextBox();
}
/**
@ -183,7 +201,7 @@ public class GuiItemRoutingNode extends GuiContainer
}
}
this.fontRendererObj.drawStringWithShadow(s, 9, 73, 0xFFFFFF);
this.fontRendererObj.drawStringWithShadow(s.substring(0, Math.min(16, s.length())), 81, 19, 0xFFFFFF);
}
@Override
@ -193,6 +211,9 @@ public class GuiItemRoutingNode extends GuiContainer
ResourceLocation soulForgeGuiTextures = new ResourceLocation(Constants.Mod.MODID + ":textures/gui/routingNode.png");
this.mc.getTextureManager().bindTexture(soulForgeGuiTextures);
this.drawTexturedModalRect(left, top, 0, 0, this.xSize, this.ySize);
GlStateManager.disableLighting();
GlStateManager.disableBlend();
this.textBox.drawTextBox();
}
// @Override

View file

@ -22,6 +22,7 @@ public class BloodMagicPacketHandler
INSTANCE.registerMessage(SigilHoldingPacketProcessor.class, SigilHoldingPacketProcessor.class, 4, Side.SERVER);
INSTANCE.registerMessage(KeyProcessor.class, KeyProcessor.class, 5, Side.SERVER);
INSTANCE.registerMessage(DemonAuraPacketProcessor.class, DemonAuraPacketProcessor.class, 6, Side.CLIENT);
INSTANCE.registerMessage(ItemRouterAmountPacketProcessor.class, ItemRouterAmountPacketProcessor.class, 7, Side.SERVER);
}
public static void sendToAllAround(IMessage message, TileEntity te, int range)

View file

@ -0,0 +1,77 @@
package WayofTime.bloodmagic.network;
import WayofTime.bloodmagic.tile.routing.TileFilteredRoutingNode;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.relauncher.Side;
public class ItemRouterAmountPacketProcessor implements IMessage, IMessageHandler<ItemRouterAmountPacketProcessor, IMessage>
{
private int ghostItemSlot;
private int amount;
private int dimension;
private BlockPos pos;
public ItemRouterAmountPacketProcessor()
{
}
public ItemRouterAmountPacketProcessor(int ghostItemSlot, int amount, BlockPos pos, World world)
{
this.ghostItemSlot = ghostItemSlot;
this.amount = amount;
this.pos = pos;
this.dimension = world.provider.getDimension();
}
@Override
public void fromBytes(ByteBuf buffer)
{
PacketBuffer buff = new PacketBuffer(buffer);
dimension = buff.readInt();
pos = buff.readBlockPos();
ghostItemSlot = buff.readInt();
amount = buff.readInt();
}
@Override
public void toBytes(ByteBuf buffer)
{
PacketBuffer buff = new PacketBuffer(buffer);
buff.writeInt(dimension);
buff.writeBlockPos(pos);
buff.writeInt(ghostItemSlot);
buff.writeInt(amount);
}
@Override
public IMessage onMessage(ItemRouterAmountPacketProcessor message, MessageContext ctx)
{
if (ctx.side == Side.SERVER)
{
message.onMessageFromClient();
}
return null;
}
public void onMessageFromClient()
{
World world = DimensionManager.getWorld(dimension);
if (world != null)
{
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileFilteredRoutingNode)
{
((TileFilteredRoutingNode) tile).setGhostItemAmount(ghostItemSlot, amount);
}
}
}
}

View file

@ -2,11 +2,6 @@ package WayofTime.bloodmagic.tile.container;
import javax.annotation.Nullable;
import WayofTime.bloodmagic.item.inventory.ItemInventory;
import WayofTime.bloodmagic.item.routing.IItemFilterProvider;
import WayofTime.bloodmagic.tile.routing.TileFilteredRoutingNode;
import WayofTime.bloodmagic.util.GhostItemHelper;
import WayofTime.bloodmagic.util.Utils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
@ -14,6 +9,10 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import WayofTime.bloodmagic.item.inventory.ItemInventory;
import WayofTime.bloodmagic.item.routing.IItemFilterProvider;
import WayofTime.bloodmagic.tile.routing.TileFilteredRoutingNode;
import WayofTime.bloodmagic.util.GhostItemHelper;
public class ContainerItemRoutingNode extends Container
{
@ -80,70 +79,34 @@ public class ContainerItemRoutingNode extends Container
lastGhostSlotClicked = slot.getSlotIndex();
System.out.println(lastGhostSlotClicked);
if ((dragType == 0 || dragType == 1) && (clickTypeIn == ClickType.PICKUP || clickTypeIn == ClickType.QUICK_MOVE))
if ((dragType == 0 || dragType == 1))
{
ItemStack slotStack = slot.getStack();
ItemStack heldStack = inventoryPlayer.getItemStack();
if (dragType == 0)
if (dragType == 0) //Left mouse click-eth
{
if (clickTypeIn == ClickType.PICKUP)
{
if (heldStack == null && slotStack != null)
{
GhostItemHelper.incrementGhostAmout(slotStack, 1);
slot.putStack(slotStack);
} else if (heldStack != null)
//I clicked on the slot with an empty hand. Selecting!
} else if (heldStack != null && slotStack == null)
{
if (!((SlotGhostItem) slot).canBeAccessed())
{
return super.slotClick(slotId, dragType, clickTypeIn, player);
}
if (slotStack != null && Utils.canCombine(slotStack, heldStack))
{
GhostItemHelper.incrementGhostAmout(slotStack, heldStack.stackSize);
slot.putStack(slotStack);
} else
{
ItemStack copyStack = heldStack.copy();
GhostItemHelper.setItemGhostAmount(copyStack, copyStack.stackSize);
copyStack.stackSize = 1;
slot.putStack(copyStack);
}
}
} else
{
if (slotStack != null)
{
GhostItemHelper.setItemGhostAmount(slotStack, GhostItemHelper.getItemGhostAmount(slotStack) / 2);
if (GhostItemHelper.getItemGhostAmount(slotStack) <= 0)
{
slot.putStack(null);
} else
{
slot.putStack(slotStack);
}
ItemStack copyStack = heldStack.copy();
GhostItemHelper.setItemGhostAmount(copyStack, 0);
copyStack.stackSize = 1;
slot.putStack(copyStack);
}
}
} else
//Right mouse click-eth away
{
if (clickTypeIn == ClickType.PICKUP)
{
if (slotStack != null)
{
GhostItemHelper.decrementGhostAmount(slotStack, 1);
if (GhostItemHelper.getItemGhostAmount(slotStack) < 0)
{
slot.putStack(null);
} else
{
slot.putStack(slotStack);
}
}
} else
{
slot.putStack(null);
}
slot.putStack(null);
}
}
}

View file

@ -8,6 +8,7 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.EnumFacing;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.item.inventory.ItemInventory;
import WayofTime.bloodmagic.util.GhostItemHelper;
public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedInventory
{
@ -28,6 +29,17 @@ public class TileFilteredRoutingNode extends TileRoutingNode implements ISidedIn
return getStackInSlot(index);
}
public void setGhostItemAmount(int ghostItemSlot, int amount)
{
ItemStack stack = itemInventory.getStackInSlot(ghostItemSlot);
if (stack != null)
{
GhostItemHelper.setItemGhostAmount(stack, amount);
}
this.markDirty();
}
@Override
public boolean isInventoryConnectedToSide(EnumFacing side)
{

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB