Jump to content

bongotezz

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by bongotezz

  1. I don't know the answers you're looking for but i would be interested in the code to put text on the signs. That sounds awesome.
  2. I don't know about structure block data but you can generate structures from MC edit schematics. I'm working on a mod that does that now.
  3. See what happens when you're a noob? I didn't even realize there was a specific class for door. Thanks a lot man.
  4. Hello I recently made some code to lock a chest by locking the tile entity. Does this work the same for doors? Do they have a tile entity that i can lock? If they do have tile entities is there 2 of them, one for the top block and one for the bottom? Thanks in advance.
  5. No, this is basic Java. You can't compare Strings using == . Thanks. It's been a long time since i've used Java and didn't remember that.
  6. This also works te.getName().equals("Test Chest") Even though == did not.
  7. Thanks everyone for your help. I decided to go a different route. Since the chests are locked and require a key to unlock i switched to testing for isLocked instead. It works even after logging out.
  8. Well, i switched it to NBT and actually made it worse. Now when i press ESC to exit the game it crashes with an error in the AnvilChunckLoader class and highlights this line of code that's not mine. this.pendingAnvilChunksCoordinates.remove(chunkpos); Maybe i'm not understanding NBT. Here's how i set it up. public static void fillInventoryChest(int x, int y, int z, World world, int itemID, int amount, int meta, int slot) { BlockPos blockPos = new BlockPos(x,y,z); Item item = new Item(); item = Item.getItemById(itemID); ItemStack i = new ItemStack(item, amount, meta); i.setStackDisplayName("displayName"); TileEntityChest te = (TileEntityChest)world.getTileEntity(blockPos); te.setInventorySlotContents(slot, i); te.setCustomName("TestChest"); NBTTagCompound underworld = te.getTileData(); underworld.setBoolean("underworld", true); te.writeToNBT(underworld); LockCode code = new LockCode("displayName"); te.setLockCode(code); te.markDirty(); } //end fill chest and here's how i'm testing for it public class ModEvents { @SubscribeEvent (priority = EventPriority.HIGHEST) public void NoBlockBreaking(BlockEvent.BreakEvent event) { System.out.println("test"); if(event.getState().getBlock()==Blocks.CHEST) { System.out.println("Inside IF"); World world = event.getWorld(); BlockPos blockPos = event.getPos(); TileEntityChest te = (TileEntityChest)world.getTileEntity(blockPos); boolean x = false; NBTTagCompound underworld; underworld = te.getTileData(); x = underworld.getBoolean("underworld"); if(x) { System.out.println("about to cancel"); event.setCanceled(true); } } } }
  9. I tried markDirty while testing. It came up in my google search. It didn't make any difference because it looks like the name saved. If i read the name even after logging out and in the name is correct. The problem seems to be that after the log out and log in the if statement is not returning true even though it should.
  10. Thanks for your reply. I will now have to learn about NBT. I thought making the chests my mod spawns in unbreakable would be easy but i've had to learn a ton to get this close. Figuring out NBT should be fun. Any good guides you're familiar with?
  11. So i did some further testing and i'm now thinking this is either a Minecraft bug, a Forge bug, or some kind of lack of understanding something on my part. here's my debugging code @SubscribeEvent (priority = EventPriority.HIGHEST) public void NoBlockBreaking(BlockEvent.BreakEvent event) { System.out.println("test"); if(event.getState().getBlock()==Blocks.CHEST) { System.out.println("Inside IF"); World world = event.getWorld(); BlockPos blockPos = event.getPos(); TileEntityChest te = (TileEntityChest)world.getTileEntity(blockPos); String boxName = te.getName(); String name = "Test Chest"; System.out.println("te.getName" + boxName + "is there a space?"); System.out.println("String" + name + "is there a space?"); if(boxName == name) { System.out.println("about to cancel"); event.setCanceled(true); } } } The text output from the first test - spawn the chest into the world and try to break it. The first time it's spawned it works properly. i cannot break the chest. [01:54:52] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:19]: test [01:54:52] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:22]: Inside IF [01:54:52] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:30]: te.getNameTest Chestis there a space? [01:54:52] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:31]: StringTest Chestis there a space? [01:54:52] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:36]: about to cancel Now i log out and back in and here's the output. I try to break the chest and it breaks just fine. It's not supposed to. [01:56:23] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:19]: test [01:56:23] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:22]: Inside IF [01:56:23] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:30]: te.getNameTest Chestis there a space? [01:56:23] [server thread/INFO] [sTDOUT]: [com.bongotezz.tutorialmod.events.ModEvents:NoBlockBreaking:31]: StringTest Chestis there a space? It's exactly the same except the chest now breaks and the last println is not called. For some reason after i log out and back in the IF statement fails even though the 2 strings are the same.
  12. After some additional testing it looks like the tile entity does not save its name that i give it. "edit" And further testing shows that i'm wrong on this.
  13. I created an event to stop people from breaking specifically named chests. The even works find until i log out and back in again. It then no longer works. Code for filling and naming the tile entity. public static void fillInventoryChest(int x, int y, int z, World world, int itemID, int amount, int meta, int slot) { BlockPos blockPos = new BlockPos(x,y,z); Item item = new Item(); item = Item.getItemById(itemID); ItemStack i = new ItemStack(item, amount, meta); i.setStackDisplayName("displayName"); TileEntityChest te = (TileEntityChest)world.getTileEntity(blockPos); te.setInventorySlotContents(slot, i); te.setCustomName("Test Chest"); LockCode code = new LockCode("displayName"); te.setLockCode(code); } Code for the event @SubscribeEvent public void NoBlockBreaking(BlockEvent.BreakEvent event) { if(event.getState().getBlock()==Blocks.CHEST) { World world = event.getWorld(); BlockPos blockPos = event.getPos(); TileEntityChest te = (TileEntityChest)world.getTileEntity(blockPos); if(te.getName()=="Test Chest") { event.setCanceled(true); } } } registering the even @EventHandler public void postInit(FMLPostInitializationEvent event) { MinecraftForge.EVENT_BUS.register(new ModEvents()); proxy.postInit(event); } Anyone know what i'm missing? Thanks in advance.
  14. Thanks for this tip. I was able to learn how to use events to stop chest that my mod places from being broken. Other chests remain normal. I did it by naming the chest's tileEntityChest while filling it and then checking for it in the event. If it has the same name the block break gets cancelled. If anyone wants more details just let me know.
  15. Hey, if you'd like you can reference my OpenSource test-things mod for making your chest. https://github.com/EscapeMC/Things-Mod-1.10.2/tree/master/src/main/java/com/github/escapemc/thingsmod Good luck! Thanks man. I'll check it out.
  16. I don't know anything about events yet. There's so much to learn. I've been at this for 12 whole days. I should know everything by now. Honestly i'm surprised by how much progress i've made so far. Thanks for your help and suggestions. Back to the tutorials.
  17. It looks like i will need to create my own chest block then. Time to learn some new things.
  18. Aww man. It looks like it set all chests to unbreakable
  19. Thanks for replying. I came back to let people know that i figured it out. Here's the code in case anyone is curious how i did it. It appears to work. It's locked and can be opened with a specially named item and a diamond axe cannot break it in survival. public static void lockChest(int x, int y, int z, World world, String unlockCode) { BlockPos blockPos = new BlockPos(x,y,z); world.getBlockState(blockPos).getBlock().setBlockUnbreakable(); TileEntityChest te = (TileEntityChest)world.getTileEntity(blockPos); LockCode code = new LockCode(unlockCode); te.setLockCode(code); }// end lock chest
  20. Is there a way to set a chest in the world to unbreakable? I want people to get the key to unlock it. I don't want them using an axe. Thanks.
  21. TileEntityChest te = (TileEntityChest)worldObj.getTileEntity(BlockPos); te.setInventorySlotContents(index, stack); Thanks. One last question. I have the x y and z coordinates of the chest. How do i convert that into a BlockPos? I think i found it in net.minecraft.util.math.BlockPos;
  22. TileEntityChest te = (TileEntityChest)worldObj.getTileEntity(BlockPos); te.setInventorySlotContents(index, stack); Thanks. One last question. I have the x y and z coordinates of the chest. How do i convert that into a BlockPos?
  23. I have a chest that my mod spawns in. It's empty and i want to put items in it. I have the exact coordinates, the world, and i know the exact vanilla item that i want to put into it and what slot i want it in. How do i add the item to the chest? Thanks.
  24. I found the following in some code on github. short width = tagCompound.func_74765_d("Width"); short length = tagCompound.func_74765_d("Length"); short height = tagCompound.func_74765_d("Height"); tagCompound is an NBTTagCompound as shown in the method below. public ISchematic readFromNBT(NBTTagCompound tagCompound) Is anyone familiar with this func_74765_d? I can't seem to find this anywhere in the NBTTagCompound class.
×
×
  • Create New...

Important Information

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