So I've been trying and trying and trying so hard to figure out how to make an item interactible, I know an item has a hitbox, so part of me wonders if I could use that, but there are two problems I stumbled into, one, you cannot use the SubscribeEvent annotation when using player interact event, and two there doesn't seem to be a way to get the item of the hitbox, I've tried using things like blockpos and using the values of player eye postition
and the hitbox player is looking at and setting those vslues to it I think I have code that would work if I could just get in but I don't know and I've tried everything I can think of, for reference, here's the code I have so far:
@Mod.EventBusSubscriber(modid - magicalcraft.modid, bus = mod.EventBusSubscriber.bus.MOD);
public class ModEventBusEvents
{
//Once game loads will error
@SubscribeEvent
//will error once game loads if more than one argument
public static void registerDroppedItemClick(PlayerInteractEvent event)
{
PlayerInteractEvent.EntityInteract interactEvent = (PLayerInteractEvent.EntityInteract) event;
//get the item the player is holding
Itemstack item =
event.getEntity().getItemInHand(event.getHand());
//get the target of the player's click
Entity entity interactEvent.getTarget();
EntityTypes?> type = entity.getType();
//Make sure the entity player is interacting with is an item
if (type.is((Holderset<EntityType<?>>_EntityType_ITEM))
{
//Ensure that the item is also the specific item I wish to change
if (Objects.equals(entity.getTags().tostring(), Items.BO0K.getDescriptionId()))
{
//make sure player used the correct item
if (item.is(ModItems.SCEPTER.get())
{
entity.remove(Entity.RemovalReason.DISCARDED);
entity.spawnAtLocation(ModItems.TOME.get());
}
}
}
}
}
Here's the error I get once the game boots up: