Hi I'm trying to make a silly mod where eating an apple will teleport you to whatever block you're looking at.
I'm creating an event for this but I don't know how to call the apple eating or how to track the block you're looking at.
I'm probably doing all this wrong but this is what I got so far. Might have to scrap it all, I know, that's fine.
@Mod.EventBusSubscriber(modid = HolyApples.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class ModClientEvents {
@SubscribeEvent
public static void onEatApple(LivingEvent event) {
LivingEntity player = event.getEntityLiving();
if (player.getHeldItemMainhand().getItem() == Items.APPLE) {
World world = player.getEntityWorld();
if (player.onFoodEaten(world, Items.APPLE, ?));
}
}
}
First of all, remote the 'value = Dist.CLIENT', since then the code will only run on the client, which is not what you want (here is the forge documentation on sides). Second, subscribe to the LivingEntityUseItemEvent.Finish event instead of LivingEvent. You can then use for example the attemptTeleport() method on the entity to teleport it.
Hi I'm trying to make a silly mod where eating an apple will teleport you to whatever block you're looking at.
I'm creating an event for this but I don't know how to call the apple eating or how to track the block you're looking at.
I'm probably doing all this wrong but this is what I got so far. Might have to scrap it all, I know, that's fine.
First of all, remote the 'value = Dist.CLIENT', since then the code will only run on the client, which is not what you want (here is the forge documentation on sides). Second, subscribe to the LivingEntityUseItemEvent.Finish event instead of LivingEvent. You can then use for example the attemptTeleport() method on the entity to teleport it.