Jump to content

TheOGSeabass

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by TheOGSeabass

  1. Just coming back to say thanks again, after reading through the doc and looking through the IItemHandler interface, how to use the TileEntity makes way more sense. If anyone else is looking through this, you can see a great example of a TileEntity and Block being connected and having an "onBlockActivated" behaviour in the "JukeboxBlock" and "JukeboxTileEntity" minecraft classes. Looking through those is super useful for getting an idea of how a simple TileEntity can be used to interact with the game.
  2. Ahhh thank you so much! That sounds about right too, I have trouble figuring out what class to implement stuff in sometimes so that's a huge help. And thank you so much for this and linking the doc as well, I'll definitely go that route!
  3. I've managed to create my TileEntity class for a block I'm working with and I sort of understand the read and write methods I've overridden, but I'd also like to know if there is any way to get information back from the TileEntity on the client side. I want to be able to do something like this: private final ItemStackHandler itemHandler = createHandler(); private final LazyOptional<IItemHandler> handler = LazyOptional.of( () -> itemHandler); private Item contained; private Item toDrop; private ItemStackHandler createHandler(){ return new ItemStackHandler(1){ @Override protected void onContentsChanged(int slot){ markDirty(); } @Nonnull @Override public boolean isItemValid(int slot, @Nonnull ItemStack item){ if(item.getItem() instanceof SwordItem){ return true; } return false; } @Nonnull @Override public ItemStack insertItem(int slot, @Nonnull ItemStack item, boolean simulate){ return super.insertItem(slot,item,simulate); } }; } @Override public void read(BlockState blockState, CompoundNBT nbt){ super.read(blockState,nbt); itemHandler.deserializeNBT(nbt.getCompound("contained")); } @Override public CompoundNBT write(CompoundNBT nbt){ CompoundNBT ourNBT = super.write(nbt); this.toDrop = (Item)ourNBT.get("contained"); ourNBT.put("contained",itemHandler.serializeNBT()); this.contained = ((Item)ourNBT.get("contained")); return ourNBT; } The modded block should basically drop the item it is containing when the player right clicks the block with a new item, then store the new Item. I use an event for this, and my only problem is figuring out how I can call back something stored in the TileEntity. I know in my code casting the (Item)ourNBT.get("contained") CompoundNBT to an Item doesn't work, but this is kind of just laying out my thought process. If anyone could give me some insight into what I'm missing and what I'm doing wrong I'd be super thankful! Also if my entire idea with using events to do this is flawed, then I'd be happy to hear that too haha.
  4. Ahh I see, thanks so much for letting me know! I'm gonna try out sending a packet anyways but if anything weird goes on that's really nice to know. 🙂
  5. Thanks so much! I'm going to look up some stuff on sending packets because I have super little experience with that but this was super helpful!
  6. I've been building some fun blocks to add in game, one of which is a mound which can contain a sword sticking out of it that you can pick up. I've figured out how to add these mounds and work with them, but when the "PlayerInteractEvent.RightClickBlock" event is fired on these mounds, I want them to drop the sword they are holding. The "FullMound" class I have to register these mounds has an instance variable to store the sword which is given to them, so I can easily call back the sword, but I would like to know of a seamless way to make a dropped item version of these swords drop in-game. I know I can probably add the sword to the list of drops of the "Mound" block, then destroy the block to drop the sword, then update the state of that block before the player sees that the mound block disappeared for a bit. I just want to know if there is any more seamless way to drop an item in-game when an event is called. This is what I was trying but this doesn't do anything because I think I'm looking in the wrong places for a solution. The ".getContained()" method shown here gets the Item stored in the mound if that helps. new ItemEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(), mound.getContained().getDefaultInstance()); This may be a server-client thing that I'm too much of a noob to understand, but any help is appreciated!
  7. The above recommendation is really solid, modding tutorials are unfortunately few and far between if we look at things like Youtube, but there are some dedicated courses that exist on websites like Udemy for Minecraft modding! Otherwise the first and most important step is to understand coding in java at least a bit.
×
×
  • Create New...

Important Information

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