package de.ellpeck.naturesaura.items; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.entities.EntityMoverMinecart; import net.minecraft.block.AbstractRailBlock; import net.minecraft.entity.item.minecart.AbstractMinecartEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemUseContext; import net.minecraft.util.ActionResultType; import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import javax.annotation.Nonnull; public class MoverMinecart extends ItemImpl { public MoverMinecart() { super("mover_cart", new Properties().maxStackSize(1).group(NaturesAura.CREATIVE_TAB)); } @Nonnull @Override public ActionResultType onItemUse(ItemUseContext context) { World world = context.getWorld(); BlockPos pos = context.getPos(); if (AbstractRailBlock.isRail(world.getBlockState(pos))) { if (!world.isRemote) { AbstractMinecartEntity cart = new EntityMoverMinecart(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5); world.addEntity(cart); } context.getPlayer().getHeldItem(context.getHand()).shrink(1); return ActionResultType.SUCCESS; } return ActionResultType.PASS; } }