How to make a block hold custom data?

Hello!

I’m trying to make a tile entity hold a class I’ve made. The tile entity already has functions that get called when right clicked, so I want to stop those from from calling as well. How do I give an already defined block new functionality and data to store?

Typically you would use the DataAPI The Data API — Sponge 7.2.0 documentation however I don’t believe that it works with TileEntities (I maybe wrong in which case use that)

So I would store it seperatly such as a map that contains the key of the location of the block with the value being your custom class.

As for cancelling a tile entity function. Assuming that the block agrees with Forge’s event cancelling (all vanilla blocks do) then you can cancel the interaction event between a player and the block

How do I cancel the interaction event between the player and block specifically? I have a listener set up to detect when the player right clicks and what they right click on. Is it something like that?

You are correct. Im assuming its not working, so my question is what block is it and from what mod?

It’s the pixelmon:poke_gift block. I’m just trying to use a version of it as a container that will store/give a single pokemon

I have this code:
@Listener public void onUse(InteractBlockEvent.Secondary event) { BlockSnapshot bss = event.getTargetBlock(); bss.getExtendedState().getType() }

That will detect what block is being interacted with, but I don’t know what code to put in here to stop the normal code path of the block that goes through.

event.setCancelled(true);

That worked perfectly. Thank you so much dude!

1 Like