Jump to content

McJty

Members
  • Posts

    129
  • Joined

  • Last visited

Everything posted by McJty

  1. Hi all, I have several classes and stuff that are now put in my only mod (RFTools) but I'm planning on making other mods and I would reuse the classes I made in there without having to copy it all over everytime. What's the best way to make such an API mod which is shared by my other mods? I currently have several projects (for my mods) set up using IntelliJ and gradle. People have been telling me to use Maven but it is not clear to me how that would work? Thanks,
  2. Solved. In case you're wondering. You have to do this on the server. So I send a message from my GUI to the server. That fetches the inventory and then in the reply of my message I send back the list of items. Works perfectly.
  3. Hi all, I made a block that scans the surroundings and finds all inventories. That part works fine. In it's GUI it shows a list of all inventories that it found. Now I want to add the functionality that when the user clicks on an inventory it should show all items that are in that inventory. It partially works for all inventories for which the tile entity happens to be up-to-date on the client. But for most inventories that's not the case. How can I reliably get the contents of an inventory at x,y,z from the client side? Is there a way to access the server-side tile entity(inventory)? Any other way I can solve this problem? Thanks!
  4. *If* Minecraft modding should die (big if, personally I doubt that this will happen) then you could also look at http://minetest.net/ which is looking more promising then Terasology IMHO.
  5. Hi all. I'm trying to implement a block that has a custom inventory. It has 10 ghost slots (for a crafting grid), the player inventory + hotbar as well as an internal inventory for holding items. The problem that I'm having is that Minecraft crashes (stack overflow) when I press shift-click on an item in the player inventory. I'm assuming Mc is trying to move that stack of item/item to some slot and this fails. The code can be found here: https://github.com/McJty/RFTools/tree/master/src/main/java/com/mcjty/rftools/blocks/crafter The crash looks as follows: Any ideas what I could be doing wrong or how I can debug this? Thanks,
  6. Thanks! That was the explanation I was looking for. Now it works!
  7. Ok, I have examined the furnace code a bit and I think it does something fundamentally different from what I have been to do in tutorials. First I see that the important parts in the ContainerFurnace code that handle synchronizing the GUI have to do with ContainerFurnace.detectAndSendChanges() and also addCraftingToCrafters(). These functions basically update various variables (like furnaceCookTime, lastCookTime and so on) in the TileEntityFurnace instance. I assume they are updating the server side version of this tile entity there. Then in GuiFurnace these tile entity variables are used to display the progress. Here is the source of my confusion. The way I do GUI's the tile entity instances on client side are different (copies?) from the tile entities on the server so when I change status variables in the server version they are not automatically synced to the tile entity that the GUI is currently looking at. Apparently this is not the case for how the furnace works. So I decided to have a look on how the GUI is actually opened and found out this code (last parameter is the tile entity): this.mc.displayGuiScreen(new GuiFurnace(this.inventory, p_146101_1_)); This is called from within BlockFurnace.onBlockActivated() when world.isRemote is false (so that means it is called on the server). Of course that way the GuiFurnace() instance is allocated with a reference to the server version of the tile entity. That way the GUI can correctly see all changes to that tile entity. So now I'm wondering if I'm doing GUI's the wrong way. In my way of doing things (which I got from various tutorials on the web) I have a GuiProxy class which basically has this code: public Object getServerGuiElement(int guiid, EntityPlayer entityPlayer, World world, int x, int y, int z) { if (guiid == RFTools.GUI_CRAFTER) { TileEntity te = world.getTileEntity(x, y, z); if (te instanceof CrafterBlockTileEntity) { CrafterBlockTileEntity crafterBlockTileEntity = (CrafterBlockTileEntity) te; return new CrafterContainer(entityPlayer, crafterBlockTileEntity, 0, 0); } } return null; } @Override public Object getClientGuiElement(int guiid, EntityPlayer entityPlayer, World world, int x, int y, int z) { if (guiid == RFTools.GUI_CRAFTER) { TileEntity te = world.getTileEntity(x, y, z); if (te instanceof CrafterBlockTileEntity) { CrafterBlockTileEntity crafterBlockTileEntity = (CrafterBlockTileEntity) te; CrafterContainer testContainer = new CrafterContainer(entityPlayer, crafterBlockTileEntity, 256, 184); return new GuiCrafter(crafterBlockTileEntity, testContainer); } } return null; } So my GuiCrafter class is instantiated on the client side with a client version of the tile entity. Am I doing my GUI's wrong? Thanks!
  8. For 1.7.10. I'm making a block that supports RF and implements IEnergyHandler. The block also has a GUI. When the GUI is open I want the GUI to automatically show the current RF in the block but it isn't updating automatically because the client side tileentity doesn't seem to be updated. How can I properly get the GUI to update the RF in real time? I have a Container for my tile entity. Thanks
  9. Yes, the readNBT/writeNBT actually contain the right values that should be synchronized. But how do I call markBlockForUpdate() on the client side? The tile entity on the server side is now doing markBlockForUpdate() but I guess that's only server side. I don't know how to trigger it on the client side as well?
  10. Ah no, it isn't completely solved. I have the tile entity which will check the RF value every 20 ticks and then it does this: worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); In my block implementation I have this: @Override public IIcon getIcon(IBlockAccess blockAccess, int x, int y, int z, int side) { TileEntity tileEntity = blockAccess.getTileEntity(x, y, z); int meta = blockAccess.getBlockMetadata(x, y, z); int k = getOrientation(meta); ... } But this function is not called as a result of the server side doing markBlockForUpdate. I also have this code in the tile entity which is related to this: @Override public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } And I can see that these functions are called (with correct values) after markBlockForUpdate. But getIcon isn't called and the block doesn't render. I have to manually place another block adjacent to it to force a rerender. Anything I'm missing? Thanks,
  11. Never mind, Apparently there is another version of getIcon with more info. I'll use that :-)
  12. Hi, I have a block in which I would like to have used 6 bits of metadata. 3 bits for the orientation of the block and 3 bits to store information needed for rendering the front side of the object (shows the amount of RF level in a block). Unfortunately metadata is limited to 4 bits so I can't do that. So I would like to add the information of the RF level to the tile entity (which I already have in any case) and keep the metadata for the orientation. However how do I use this in my getIcon() method: @Override public IIcon getIcon(int side, int meta) { int k = getOrientation(meta); if (side == k) { RFMonitorBlockTileEntity tileEntity = ... how to get my tile entity here? ... int rflevel = tileEntity.getRFLevel(); switch (rflevel) { case 1: return iconFront0; case 2: return iconFront1; case 3: return iconFront2; case 4: return iconFront3; case 5: return iconFront4; default: return iconFront; } } else { return iconSide; } } How can I access my tile entity from getIcon()? I don't have my world and I don't have a coordinate in that method. Thanks,
  13. Well I need a tile entity here because I need somewhere to remember which block my monitor will monitor. Additionally my monitor block doesn't have to be directly adjacent to the block it is monitoring. When you use it you get a GUI where you can select the block you want to monitor from all nearby blocks (currently that means all blocks in a 3x3x3 area centered around the monitor). Not sure if diagonals are considered as adjacent here?
  14. I got it to work but to my surprise I noticed that both the client side and server side version of my tile entity are ticking. And it seems that on the client side the energy RF state of the tile entity of the block I'm monitoring (in this case a thermal expansion machine) gets outdated after a while too. So now I do the updateEntity() of my tile entity only if world.isRemote is false (i.e. on the server) and it now works perfectly. Thanks for the help.
  15. Well the other block doesn't belong to my mod. The purpose of my monitor is to monitor any other RF supporting block from all other mods that support RF. Thanks for the info
  16. Ok thanks that works. But now I'm doubting if that's actually what I want in this particular case. I'm making a block that monitors the amount of RF that is in another block (it will do more in the future but that's what it does now). So I want one side of the block to change texture depending on the capacity of another RF block. I already implemented Block.getIcon() so that the front of the block has a different texture but now I want that texture to change depending on the RF capacity of another block. I'm not sure if getIcon() is called every frame. I suspect not. So I probably need to have my tile entity do this check and then somehow notify the client that this texture has to be changed. I suppose that the tile entity can use the metadata for this and then I have to update the block on the client side somehow? Thanks,
  17. I am trying to make a block that will need to do some work every second. Reading tutorials on the web seem to indicate that I should call setTickRandom(true) and then I'll get a random tick. First that doesn't seem to work. My updateTick() is never called and secondly I don't really like random. Other sources say I should call world.scheduleBlockUpdate(x, y, z, this, tickRate(world)); after placing the block (onBlockAdded) and then again every tick. Is that the way to go? I also want to ensure the block ticks as the world is loaded and the chunk it is in is loaded. What are good recommendations for implementing this kind of functionality? Thanks!
  18. Ok, thanks to your help I managed to get a bit further but I'm still stuck with a problem. The problem I have now is that when my GUI updates a value in the tile entity (does this by sending a message) the server version of the tile entity is updated correctly (and saved when I exit the game) but the client tile entity does not reflect this change (even though I call markBlockForUpdate). I have to save and load the world again before the client tile entity is updated. Here is (in summary) what I have done: I made a simple message channel and registered my message with: INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("rftools"); INSTANCE.registerMessage(PacketRFMonitor.class, PacketRFMonitor.class, nextID(), Side.SERVER); PacketRFMonitor basically looks like this: public class PacketRFMonitor implements IMessage, IMessageHandler<PacketRFMonitor, IMessage> { @Override public void fromBytes(ByteBuf buf) { ... } @Override public void toBytes(ByteBuf buf) { ... } @Override public IMessage onMessage(PacketRFMonitor message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().playerEntity; TileEntity te = player.worldObj.getTileEntity(message.x, message.y, message.z); if(!(te instanceof RFMonitorBlockTileEntity)) { System.out.println("createPowerMonitotPacket: TileEntity is not a RFMonitorBlockTileEntity!"); return null; } RFMonitorBlockTileEntity monitorBlockTileEntity = (RFMonitorBlockTileEntity) te; monitorBlockTileEntity.setMonitor(message.monitor); player.worldObj.markBlockForUpdate(x, y, z); return null; } } In my tile entity class I have the following: public class RFMonitorBlockTileEntity extends TileEntity { private int monitorX = -1; private int monitorY = -1; // Invalid y coordinate so we know it is not initialized yet private int monitorZ = -1; ... setters and getters .... @Override public Packet getDescriptionPacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag); } @Override public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) { readFromNBT(packet.func_148857_g()); } @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); monitorX = tagCompound.getInteger("monitorX"); monitorY = tagCompound.getInteger("monitorY"); monitorZ = tagCompound.getInteger("monitorZ"); } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); tagCompound.setInteger("monitorX", monitorX); tagCompound.setInteger("monitorY", monitorY); tagCompound.setInteger("monitorZ", monitorZ); } } Then in my GUI code I have this: private void sendChangeToServer(Coordinate c) { PacketHandler.INSTANCE.sendToServer(new PacketRFMonitor(monitorBlockTileEntity.xCoord, monitorBlockTileEntity.yCoord, monitorBlockTileEntity.zCoord, c)); } My full source code can be seen on github: https://github.com/McJty/RFTools As far as I know I have done everything correctly but apparently not. I can of course manually change the client tile entity in the gui code but I have been told not to do that and I prefer to do things the proper way. Any ideas what could be wrong here? Thanks!
  19. Ah sorry thanks. Didn't think of looking into networking code. This is a new programming area for me. Have to get used to it.
  20. Hmm sorry but I'm probably looking for something else or it is named differently that I'm expecting but I can't find any tutorial there that seems to match what I'm looking at?
  21. Yes I gathered that. But how? I can't find example code on this (at least example code that still works in this version of forge)
  22. Hi all, How can I (with 1.7.10) synchronize changes to the client TileEntity to the server? I have a GUI where I want to modify some settings in my tileentity and I want it to be saved on the server side. I found some tutorials on the web but they are for older versions and I have trouble adapting them to latest forge. Any help here? Thanks
  23. I still haven't been able to solve this problem. No matter what I do. But I do think that I'm going at this totally wrong now. The Block instance of which I'm trying to get the name is actually just a generic block from EnderIO which is meant to hold conduits (since you can combine multiple conduits in a single block with EnderIO). I'm getting this block using world.getBlock(x,y,z) so that's just a static block which has no knowledge about what conduits are actually inside it since that's not what a Block is supposed to hold. I suspect the actual data of what conduits are inside it is stored elsewhere. Perhaps NBT data or tile entity or so but I'm not certain where that would be and how to get the correct name from that then. Any ideas? I actually have a similar problem with Thermal Expansion energy cells. The block that I get from world.getBlock() seems to be a generic energy cell for which the returned name is always 'Creative Energy Cell' even though it is not a creative energy cell. I again suspect the actual type of the energy cell is stored elsewhere. This problem is now actually worsened because in the GUI of my mod I also try to render the block and this hits me with the same problems. Thanks for all suggestions you can give me here. Edit: I partially fixed the issue for the energy cell by using the world.getBlockMetadata() and give that to the itemstack before calling getDisplayName(). Now the name of the energy cell is correct but this didn't help for the EnderIO conduits.
  24. What is itemRender? I found an ItemRenderer class but it doesn't have a zLevel member that I can set.
×
×
  • Create New...

Important Information

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