Hi, i'm trying to spawn my custom dolphine when i right-click a dolphin, in order to do this when the event fires i remove the vanilla dolphin, instantiate my own and make player ride it.
Here is the code:
@SubscribeEvent
public static void onDolphinInteract(PlayerInteractEvent.EntityInteract e) {
if(e.getTarget() instanceof DolphinEntity && e.getTarget() != null) {
World worldIn = e.getWorld();
DolphinEntity dolphinEntity = (DolphinEntity) e.getTarget();
ClientPlayerEntity player = Minecraft.getInstance().player;
if(player != null && player.getRidingEntity() == null) {
dolphinEntity.remove();
RidableDolphinEnitity sobstitue = new RidableDolphinEnitity(worldIn);
sobstitue.setPosition(dolphinEntity.lastTickPosX, dolphinEntity.lastTickPosY, dolphinEntity.lastTickPosZ);
worldIn.addEntity(sobstitue);
player.startRiding(sobstitue);
}
}
}
But when i test it and i right-click the dolphine disappear and i'm freezed, where i'm wrong?