Jump to content

lendrick

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by lendrick

  1. I'd like to set up a shop NPC with a dialog that triggers the trader screen. Is there any way to do this?
  2. Worked on this a little more. For anyone finding this forum thread later on, the TileEntity data is only available once ItemBlock.placeBlockAt() is called. Here's my code in my ItemBlock subclass. @Override public boolean placeBlockAt(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) { // TODO Auto-generated method stub sideLog(java.util.logging.Level.WARNING, "placeBlockAt"); boolean b = super.placeBlockAt(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata); TileEntity te = world.getBlockTileEntity(x, y, z); if(te != null) { sideLog(java.util.logging.Level.WARNING, "placeBlockAt: block has TileEntity"); } NBTTagCompound data = itemStack.getTagCompound(); if (data != null && te != null && te instanceof TileEntityDeepStorageTank) { ((TileEntityDeepStorageTank)te).readFromNBT(data); } return b; }
  3. Figured out my mistake. It wasn't in the ItemBlock class itself; rather, when you register a block with a corresponding ItemBlock, rather than this: GameRegistry.registerBlock(blockDeepStorageTank, "deepStorageTank"); GameRegistry.registerItem(itemBlockDeepStorageTank, "deepStorageTankItem"); you do this: GameRegistry.registerBlock(blockDeepStorageTank, ItemBlockDeepStorageTank.class, "deepStorageTank"); The method is being called correctly now.
  4. I'm trying to save TileEntity information when a block is broken. In my block's removeBlockByPlayer() function, I spawn a BlockItem with the TileEntity information copied to it. Here's the relevant code from my Block subclass: public boolean removeBlockByPlayer(World world, EntityPlayer player, int x, int y, int z) { sideLog(java.util.logging.Level.WARNING, "removeBlockByPlayer"); if (!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) { ItemStack itemStack = new ItemStack(DeepStorageTanks.itemBlockDeepStorageTank); LiquidTank dst = null; TileEntity te = world.getBlockTileEntity(x, y, z); if(te instanceof TileEntityDeepStorageTank) { dst = ((TileEntityDeepStorageTank)te).tank; } if (dst != null && dst.containsValidLiquid() && dst.getLiquid().amount > 0) { NBTTagCompound tag = new NBTTagCompound(); tag.setTag("tank", dst.getLiquid().writeToNBT(new NBTTagCompound())); itemStack.setTagCompound(tag); } EntityItem entityitem = new EntityItem(world, x, y, z, itemStack); entityitem.delayBeforeCanPickup = 10; //world.spawnEntityInWorld(entityitem); } return world.setBlockToAir(x, y, z); } For some reason, when I place the resulting ItemBlock, the onItemUse() function (see below) is not firing. @Override public boolean onItemUse(ItemStack itemStack, EntityPlayer par2EntityPlayer, World world, int x, int y, int z, int par7, float par8, float par9, float par10) { sideLog(java.util.logging.Level.WARNING, "onItemUse"); boolean s = super.onItemUse(itemStack, par2EntityPlayer, world, x, y, z, par7, par8, par9, par10); NBTTagCompound data = itemStack.getTagCompound(); TileEntity te = world.getBlockTileEntity(x, y, z); if (data != null && te != null && te instanceof TileEntityDeepStorageTank) { ((TileEntityDeepStorageTank)te).readFromNBT(data); } return s; } I'm not entirely sure what the issue is, but I never see anything in the log from onItemUse. (Note that I know that removeBlockByPlayer() is being called when the block is broken because I had a logging function in it until recently.) Any ideas what might be going on?
  5. If I want the item to actually render like a block, is that going to be a huge ordeal of building a custom renderer or something, or is there some shortcut way to make it render the item as if it's an existing block?
  6. I swear I tried that, but I must not have. Thanks for your help!
  7. I'm still kind of in the dark here. Block doesn't have an onItemUse function, so does that mean I need to create a custom Item class that, when placed, spawns the block and inserts the entity data? I don't see any way to get the itemstack from inside the Block class when the block is placed.
  8. I'm having some trouble getting my block to be textured. I had it working initially but then I moved the texture directory somewhere else and it broke, and now I have no clue where it was initially. I've tried following the instructions in the tutorials as closely as possible, but I had to dig back through the history to get a 1.5.2 tutorial and I'm not sure if the current version of the eclipse page (which tells you what to do to get the textures into the project) is correct for 1.5.2 or not. I'm getting these messages in the log: 2013-08-17 13:53:41 [WARNING] [Minecraft-Client] TextureManager.createTexture called for file mods/DeepStorageTanks/textures/blocks/dst_top.png, but that file does not exist. Ignoring. 2013-08-17 13:53:41 [WARNING] [Minecraft-Client] TextureManager.createTexture called for file mods/DeepStorageTanks/textures/blocks/dst_bottom.png, but that file does not exist. Ignoring. 2013-08-17 13:53:42 [WARNING] [Minecraft-Client] TextureManager.createTexture called for file mods/DeepStorageTanks/textures/blocks/dst_side.png, but that file does not exist. Ignoring. Here's my source code: https://github.com/lendrick/deep-storage-tanks The relevant file: https://github.com/lendrick/deep-storage-tanks/blob/master/lendrick/deepstoragetanks/block/BlockDeepStorageTank.java Can anyone take a look and help me figure out what I'm doing wrong?
  9. I'm trying to figure out how to maintain TileEntity data when breaking and placing a block. The OpenBlocks source code has some clues in it (spawning an EntityItem with the appropriate data stored in it), but when I place the block again, the data is lost. I'm assuming that there's something I need to do with the item is placed, but I'm not sure what. Any ideas?
  10. That worked, thank you. One other question: When I have a liquid flowing into the tank, the amount of liquid in the tank changes every tick, which means I'm sending an update packet every tick. This is a huge waste of bandwidth, as I think the GUI could update once per second and be perfectly usable. Is there some standard way of scheduling update packets?
  11. I apologize that I'm posting something similar to what's been asked before, but I've seen a few other topics on this and I've looked at the tutorials, but the tutorials feel kind of incomplete and the forum topics seem to assume more knowledge on this than I have. I'm trying to build a mod called Deep Storage Tanks, which provides a single block liquid tank that holds up to 2 billion millibuckets (similar to the way a Deep Storage Unit from MFR works, but for liquid). Storing and removing the liquid from the tank works fine, but I'm trying to build a simple GUI that will tell you what liquid is in the tank and how much of it is there, and the GUI always says that the tank is empty regardless of what's in it. As far as I can tell, this is an issue of syncing the tile entity between the client and the server -- that is, the server has the correct amount of fluid in it, but the tile entity on the client side just has an empty tank. Note that at the moment I'm not trying to allow the player to do anything to the block from the GUI, so the sync only needs to be from the server to the player, and not vice-versa (most examples seem to center around sending a packet from the player to the server). I'm also a bit confused about how exactly markBlockForUpdate (or whatever that function is called) works. What mechanism does it actually use to send a data packet? I've inspected the source to some other modules, but it hasn't been particularly helpful. Buildcraft, for instance, has multiple layers of abstraction, so it's difficult to tell what's going on in terms of network packets without poking through a ton of different files and getting lost. Looking around, I'm getting some conflicting information about how to deal with this. One forum post seemed to suggest that I only need to override TileEntity.getDescriptionPacket() and TileEntity.onDataPacket(), while the tutorials seem to indicate that I need a packet handler class. It's also not clear whether I should use Packet250CustomPayload or the packet class that appears to be meant for TileEntities. I'm also curious if there's some standard way to send a data packet about a LiquidStack or if I need to build that myself (which is what I'm trying to do at the moment, but I'd perfer to avoid reinventing the wheel if possible). Here's my code if anyone wants to look at it. It's MIT licensed, so feel free to use it for whatever. https://github.com/lendrick/deep-storage-tanks
×
×
  • Create New...

Important Information

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