Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

ccsimon

Members
  • Posts

    24
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed

ccsimon's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Well, I thought about using reflection, but I hoped for some (reflection-)integration in Forge itself; it seems like Reflection is my best bet right now. Anyway, thanks for the help!
  2. Hi, I'm trying to add a waypoint to JourneyMap with a custom button; now, because it appears that there is no easy way of accessing a field of another mod, I would appreciate some suggestions on how I may do this (It seems like the important class is journeymap.client.waypoint.WaypointStore, but how do I access it?). I'll be using this mod only privately, so it doesn't have to be the cleanest code. Thanks for helping!
  3. It still switches over to the NEI search box every 4-5 seconds
  4. In my modding environment I've got NEI (Not Enough Items) installed, but when I try to type in a text box in my GUI, it switches over to the NEI one every few seconds and types in both ones; how can I prevent this? This is my code for the text box so far: public void initGui(){ super.initGui(); inputText = new GuiTextField(fontRendererObj, guiTop + 10, guiLeft + 10, 80, 12); inputText.setFocused(true); inputText.setCanLoseFocus(false); inputText.setMaxStringLength(40); } @Override public void keyTyped(char c, int i){ super.keyTyped(c, i); if(inputText.isFocused()){ inputText.textboxKeyTyped(c, i); } } public void mouseClicked(int i, int j, int k){ super.mouseClicked(i, j, k); if(inputText.isFocused()) inputText.mouseClicked(i, j, k); } protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { Minecraft.getMinecraft().getTextureManager().bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); inputText.drawTextBox(); } Also, when pressing like e.g. 'E', it exits out of the inventory; of course, one solution to this would be something like if(i != Keyboard.KEY_E) super.keyTyped(c, i) but is there a better way?
  5. I think these are the methods I searched for, I'll try them in the afternoon. Thank you
  6. Well, the variable updating part works, but now it looks like it doesn't send that to the client because I either draw a red button when the value is 0, or a green one when it's 1, but in the gui the button is not updated at all. That's the line of code for drawing the button: this.drawTexturedModalRect(this.xPosition, this.yPosition, 176 + ((TileEntityAlertBlock)world.getTileEntity(this.TEx, this.TEy, this.TEz)).buttonState * 20, k * 20, this.width, this.height);
  7. Actually, I did do something with this block and packethandling before, but at that time, it wasn't necessary. (I tried it many different ways, the only thing which I didn't do was to go back using packethandlers.. ) Edit: so yeah, it does work now; thanks
  8. I'm trying to set the state of a GuiButton (and save it to NBT later), but when it triggers the '<TileEntity>.buttonClicked()'-function, the variable on the TileEntity itself is not saved (I assume it saves it in the 'copied'(?) TileEntity, not the actual one).. Here's my code so far: In GuiAlertBlock.java: public void actionPerformed(GuiButton button){ ((TileEntityAlertBlock)world.getTileEntity(this.x, this.y, this.z)).buttonClicked(); List<Entity> players = world.playerEntities; for(Entity e: players){ EntityPlayer player = (EntityPlayer)e; player.addChatMessage(new ChatComponentText(player.getDisplayName())); } } In TileEntityAlertBlock: public void buttonClicked(){ if(this.buttonState == this.BUTTON_OFF) this.buttonState = this.BUTTON_ON; else if(this.buttonState == this.BUTTON_ON) this.buttonState = this.BUTTON_OFF; System.out.println(); }
  9. Hi, how do I make a GuiButton use a custom texture instead of text? For example like this one (SimplyJetpacks): Thanks!
  10. Sorry delpi, I should've tried that; It worked... unexpectedly So yeah, I don't know what's up with that, but at least now it works.
  11. I don't think that's the issue, because when printing out like the enchantment-ID, it's correct, so it basically sends and receives the right messages
  12. So now, after I've gone through networking, I found something that I don't quite understand: I created a function to display buttons in a GUI for every enchantment available for the item in a specific slot; that's working pretty well, but for items with >5 possible enchantments, it only changes server-side until you pull it out or add an enchantment with one of the buttons with ID 0-4. (as one may have noticed, the client-server-thingy doesn't really like me ) What to do now? Here's the code: GUI class: public class GuiEnchantingTablePlus extends GuiContainer{ private ResourceLocation texture = new ResourceLocation(SimonsMod.MODID, "textures/gui/EnchantingTablePlus.png"); private int[] buttonListToolsID = new int[]{32, 33, 34, 35}; private int[] buttonListSwordID = new int[]{16, 17, 18, 19, 20, 21, 34}; private ItemStack tempItem; private World worldObj; private int posX; private int posY; private int posZ; private TileEntityEnchantingTablePlus teetp; private Item currentItem; private Set possibleEnchantmentIDs; public GuiEnchantingTablePlus(InventoryPlayer inventory, World world, int x, int y, int z) { super(new ContainerEnchantingTablePlus(inventory, world, x, y, z)); this.worldObj = world; this.posX = x; this.posY = y; this.posZ = z; this.xSize = 176; this.ySize = 166; } @Override protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { Minecraft.getMinecraft().getTextureManager().bindTexture(texture); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); } public boolean doesGuiPauseGame(){ return false; } public void initGui(){ super.initGui(); } public void actionPerformed(GuiButton button){ SimonsMod.simpleNW.sendToServer(new SimonsMessage(1, posX, posY, posZ, (Integer) possibleEnchantmentIDs.toArray()[button.id], 0)); System.out.println("ID: " + button.id + " EnchID: " + (Integer) possibleEnchantmentIDs.toArray()[button.id]); //for(int i = 0; i < Enchantment.enchantmentsList.length; i++) System.out.println(i + ": " + Enchantment.enchantmentsList[i]); } public void updateScreen(){ super.updateScreen(); this.buttonList.clear(); if(this.inventorySlots.getSlot(0) != null){ if(this.inventorySlots.getSlot(0).getHasStack()){ currentItem = this.inventorySlots.getSlot(0).getStack().getItem(); if(EnchantmentHelper.mapEnchantmentData(currentItem.getItemEnchantability(), new ItemStack(currentItem)).keySet() != null){ possibleEnchantmentIDs = EnchantmentHelper.mapEnchantmentData(currentItem.getItemEnchantability(), new ItemStack(currentItem)).keySet(); for(int i = 0; i < possibleEnchantmentIDs.size(); i++){ if(Enchantment.enchantmentsList[(Integer) possibleEnchantmentIDs.toArray()[i]] != null) this.buttonList.add(new GuiButton(i, guiLeft + 20 + i*30, guiTop + 30, 30, 20, StatCollector.translateToLocal(Enchantment.enchantmentsList[(Integer) possibleEnchantmentIDs.toArray()[i]].getName()))); } } } } } } Message class: public class SimonsMessage implements IMessage{ public int packetInt; public int posX; public int posY; public int posZ; public int enchID; public int enchLv; public SimonsMessage() {} public SimonsMessage(int a, int x, int y, int z, int enchID, int enchLv) { this.packetInt = a; this.posX = x; this.posY = y; this.posZ = z; this.enchID = enchID; this.enchLv = enchLv; } @Override public void fromBytes(ByteBuf buf) { this.packetInt = buf.readInt(); this.posX = buf.readInt(); this.posY = buf.readInt(); this.posZ = buf.readInt(); this.enchID = buf.readInt(); this.enchLv = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { buf.writeInt(this.packetInt); buf.writeInt(this.posX); buf.writeInt(this.posY); buf.writeInt(this.posZ); buf.writeInt(this.enchID); buf.writeInt(this.enchLv); } } MessageHandler class: public class SimonsMessageHandler implements IMessageHandler<SimonsMessage, IMessage>{ private boolean hasEnchantment = false; private ItemStack tempItem; private TileEntityEnchantingTablePlus teetp; private World worldObj; @Override public IMessage onMessage(SimonsMessage message, MessageContext ctx) { worldObj = ctx.getServerHandler().playerEntity.worldObj; switch(message.packetInt){ case 1: teetp = (TileEntityEnchantingTablePlus)worldObj.getTileEntity(message.posX, message.posY, message.posZ); if(teetp.getStackInSlot(0) != null){ tempItem = teetp.getStackInSlot(0).copy(); if(tempItem.hasTagCompound()){ for(int i = 0; i < tempItem.getEnchantmentTagList().tagCount(); i++){ if(message.enchID == tempItem.getEnchantmentTagList().getCompoundTagAt(i).getInteger("id")) hasEnchantment = true; } } if(!hasEnchantment){ tempItem.addEnchantment(Enchantment.enchantmentsList[message.enchID], 1); teetp.setInventorySlotContents(0, tempItem); } hasEnchantment = false; } break; } //System.out.println(message.packetInt); return null; } } P.S.: I'm just testing, so ignore the overcomplicated code... P.P.S.: The cosmetic part is still TODO, right now I'm just trying to get the code to work
  13. But how do I transmit the 'worldObj' to the server to access the TileEntity? (So far I only know about sending Integers, Strings and ItemStacks)?
  14. Hi, to continue my previous question: now that I got some buttons to work, I want one to change the ItemStack in the (currently only) slot, but as soon as I pull the item out of this slot, it loses its enchantments (so it just changes back to the previous item). I don't know if this has something to do with networking or if I just missed something (clearly it's something with this client-server-thing). That's inside my Gui's class: public void actionPerformed(GuiButton button){ switch(button.id){ case 0: teetp = worldObj.getTileEntity(posX, posY, posZ); if(teetp.getStackInSlot(0) != null){ tempItem = teetp.getStackInSlot(0).copy(); if(tempItem.getItem() instanceof ItemSword) { tempItem.addEnchantment(Enchantment.sharpness, 4); tempItem.addEnchantment(Enchantment.fireAspect, 1); } else if(tempItem.getItem() instanceof ItemPickaxe) { tempItem.addEnchantment(Enchantment.efficiency, 4); tempItem.addEnchantment(Enchantment.unbreaking, 3); } teetp.setInventorySlotContents(0, tempItem); } break; } } What did I do wrong?
  15. Thank you both very much; I think I can try and do something with this information..
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.