Jump to content

ccsimon

Members
  • Posts

    24
  • Joined

  • Last visited

Everything posted by ccsimon

  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..
  16. Does it work when registering the textures with the modid? this.icons[i] = reg.registerIcon([YourMod].modid + ":" + "LightCrystal" + "_" + i);
  17. Isn't this line this.icons[i] = reg.registerIcon(this.getTextureName() + "_" + i); registering strings like "LightCrystal_0_0", "LightCrystal_0_1", etc.? It'll probably work if you change it to this.icons[i] = reg.registerIcon("LightCrystal" + "_" + i);
  18. I want to make a scrollable list of buttons (which then edits the itemstack in an slot), but I really dont know where to begin... Any hints or something? Thanks
  19. Ohh.. really didn't think about this client-server-thing (it's been a few months since I *tried* to write mods ) Now at least this part is working as it should ~Simon p.s. I'm a little bit afraid to ask, but how do I store variables etc. in the ItemStack? (I don't know why, but currently I have no clue...)
  20. Hi there, currently I'm playing around with rotation/position of the player, but I don't really get it why this method is called two times insted of just once; for another item I used a very inefficient way (at least I think it could be done better): Now back to my actual question: why is this method called twice (e.g. when just checking the players rotation if the player right-clicks a certain item)? Also, I don't get what the upper two values stand for (if you'd keep turning right they would probably go to the max value of a float)... Thanks, Simon
  21. Well, I think I didn't try enough, because now I figured it out (I changed the GuiHandler to return the Container from the same block every time you click another (with relative coords)). Anyways, thanks for the help
  22. Okay, I know what you mean, but how do I choose a master TileEntity from the blocks?
  23. Hello there, recently i started modding with Forge (1.7.2) and yesterday I had the idea to create Multiblocks; the Multiblock itself isn't really the problem, I actually got a GUI and everything else set up, more the inventory of the Multiblock, because each block has its own inventory , so if i place a stack of wood in one Block, I could put another stack e.g. of cobblestone in the inventory below. So now my question is how to let multiple blocks/tileentities access one inventory... Thanks for any replies Simon
×
×
  • Create New...

Important Information

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