Jump to content

Fox152236

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by Fox152236

  1. Hey guys, First time posting here, only been working on this mod for a few weeks (it's my first) So I'm afraid this might be a bit of a noobish question, so don't be too harsh... So I've read anything I can find on how to open a GUI and a container, and I think I have it all set up right, at least for the most part. The only problem is it's not working (Obviously, or I wouldn't be here) but the way it's not working is throwing me for a loop. Every time I open the GUI, the container is off by a certain amount, which varies depending on the number of slots I add to the container. It pulls items out of slots other than the one being clicked, from other slots the player inventory might have, such as armor slots. So, after a lot of testing, it looks like, to me at least, that although the GUI is being drawn correctly, the container that's being used isn't my container, but the default player inventory one, since the container works perfectly when the ContainerPlayer code is slapped onto my container's constructor. Gui Handler public class ClassismGUIHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { System.out.println(player); return new ClassismSkillTreeContainer(player.inventory, new ClassismClassHandler()); } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { System.out.println(player); return new ClassismGuiSkillTree (player.inventory, new ClassismClassHandler()); } } Keybinder public class ClassismKeybindHandler { public static final int CUSTOM_INV = 0; private static final String[] desc = {"key.tut_inventory.desc"}; private static final int[] keyValues = {Keyboard.KEY_I}; private boolean skillopen=false; public final KeyBinding[] keys; public ClassismKeybindHandler() { keys = new KeyBinding[desc.length]; for (int i = 0; i < desc.length; ++i) { keys[i] = new KeyBinding(desc[i], keyValues[i], "key.tutorial.category"); ClientRegistry.registerKeyBinding(keys[i]); } } @SubscribeEvent public void onKeyInput(KeyInputEvent event) { if (!FMLClientHandler.instance().isGUIOpen(GuiChat.class)) { if (keys[CUSTOM_INV].isPressed()&&keys[CUSTOM_INV]!=null) { skillopen=true; } } } @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent event) { if(skillopen) { event.player.openGui(ClassismMod.instance, 0, event.player.worldObj,(int) event.player.posX, (int)event.player.posY, (int)event.player.posZ); skillopen=false; } } } Bound Event for alternative opening (Just for testing, not in final product) @SubscribeEvent public void tester(PlayerOpenContainerEvent event) { if(event.entityPlayer.openContainer.getClass()==ContainerFurnace.class) { event.entityPlayer.closeScreen(); event.entityPlayer.openGui(ClassismMod.instance, 0, event.entityPlayer.worldObj,(int) event.entityPlayer.posX, (int)event.entityPlayer.posY, (int)event.entityPlayer.posZ); } } Gui for my Container @SideOnly(Side.CLIENT) public class ClassismGuiSkillTree extends GuiContainer { public final int xTextSize = 176; public final int yTextSize = 166; int posX; int posY; ResourceLocation loc= new ResourceLocation("classismMod:textures/blocks/inventoryskills.png"); public ClassismGuiSkillTree(InventoryPlayer p, ClassismClassHandler c) { super(new ClassismSkillTreeContainer(p,c)); } @Override public void drawScreen(int x, int y, float f) { super.drawScreen(x, y, f); } @Override public void initGui() { posX = (this.width - xTextSize) / 2; posY = (this.height - yTextSize) / 2; this.guiTop=posY; this.guiLeft=posX; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.renderEngine.bindTexture(loc); this.drawTexturedModalRect(posX, posY, 0, 0, xTextSize, yTextSize); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); ClassismSkillButton b=new ClassismSkillButton(0, posX+ 40, posY + 40, 20, 20, "", "classismMod:textures/blocks/whatwhat.png"); this.buttonList.add(b); this.drawEntityOnScreen(posX+35,posY+74,30,(float)(posX+ 75 - 50) - mouseX,(float)(posY+ 75 - 50) - mouseY ,mc.thePlayer); } public static void drawEntityOnScreen(int p_147046_0_, int p_147046_1_, int p_147046_2_, float p_147046_3_, float p_147046_4_, EntityLivingBase p_147046_5_) { GlStateManager.enableColorMaterial(); GlStateManager.pushMatrix(); GlStateManager.translate((float)p_147046_0_, (float)p_147046_1_, 50.0F); GlStateManager.scale((float)(-p_147046_2_), (float)p_147046_2_, (float)p_147046_2_); GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); float f2 = p_147046_5_.renderYawOffset; float f3 = p_147046_5_.rotationYaw; float f4 = p_147046_5_.rotationPitch; float f5 = p_147046_5_.prevRotationYawHead; float f6 = p_147046_5_.rotationYawHead; GlStateManager.rotate(135.0F, 0.0F, 1.0F, 0.0F); RenderHelper.enableStandardItemLighting(); GlStateManager.rotate(-135.0F, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(-((float)Math.atan((double)(p_147046_4_ / 40.0F))) * 20.0F, 1.0F, 0.0F, 0.0F); p_147046_5_.renderYawOffset = (float)Math.atan((double)(p_147046_3_ / 40.0F)) * 20.0F; p_147046_5_.rotationYaw = (float)Math.atan((double)(p_147046_3_ / 40.0F)) * 40.0F; p_147046_5_.rotationPitch = -((float)Math.atan((double)(p_147046_4_ / 40.0F))) * 20.0F; p_147046_5_.rotationYawHead = p_147046_5_.rotationYaw; p_147046_5_.prevRotationYawHead = p_147046_5_.rotationYaw; GlStateManager.translate(0.0F, 0.0F, 0.0F); RenderManager rendermanager = Minecraft.getMinecraft().getRenderManager(); rendermanager.setPlayerViewY(180.0F); rendermanager.setRenderShadow(false); rendermanager.renderEntityWithPosYaw(p_147046_5_, 0.0D, 0.0D, 0.0D, 0.0F, 1.0F); rendermanager.setRenderShadow(true); p_147046_5_.renderYawOffset = f2; p_147046_5_.rotationYaw = f3; p_147046_5_.rotationPitch = f4; p_147046_5_.prevRotationYawHead = f5; p_147046_5_.rotationYawHead = f6; GlStateManager.popMatrix(); RenderHelper.disableStandardItemLighting(); GlStateManager.disableRescaleNormal(); GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit); GlStateManager.disableTexture2D(); GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { } } The Container public class ClassismSkillTreeContainer extends Container { private final EntityPlayer thePlayer; public ClassismSkillTreeContainer(final InventoryPlayer playerInventory, ClassismClassHandler c) { this.thePlayer = playerInventory.player; int i; int j; for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 142)); } for (i = 0; i < 3; ++i) { for (j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(playerInventory, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18)); } } this.addSlotToContainer(new ClassismSkillSlot(c, 0, 144, 36)); } public void onContainerClosed(EntityPlayer playerIn) { super.onContainerClosed(playerIn); } public boolean canInteractWith(EntityPlayer playerIn) { return true; } public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(index); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (index == 0) { if (!this.mergeItemStack(itemstack1, 9, 45, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (index >= 1 && index < 5) { if (!this.mergeItemStack(itemstack1, 9, 45, false)) { return null; } } else if (index >= 5 && index < 9) { if (!this.mergeItemStack(itemstack1, 9, 45, false)) { return null; } } else if (itemstack.getItem() instanceof ItemArmor && !((Slot)this.inventorySlots.get(5 + ((ItemArmor)itemstack.getItem()).armorType)).getHasStack()) { int j = 5 + ((ItemArmor)itemstack.getItem()).armorType; if (!this.mergeItemStack(itemstack1, j, j + 1, false)) { return null; } } else if (index >= 9 && index < 36) { if (!this.mergeItemStack(itemstack1, 36, 45, false)) { return null; } } else if (index >= 36 && index < 45) { if (!this.mergeItemStack(itemstack1, 9, 36, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 9, 45, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(playerIn, itemstack1); } return itemstack; } } Oh, the other thing that's odd is that the order that I add the slots, for some reason, seems to matter. The bug changes it's behavior when I change the order that I add the slots in, regardless of which IInventory is passed as an argument. Again, thanks to anyone who reads all this or helps at all, and I'm sorry if this is a really stupid question. I'm sure I'm missing something simple, but I've been working on this for days and I just don't know what else to try. Thanks
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.