NaturesAura/src/main/java/de/ellpeck/naturesaura/items/MoverMinecart.java

39 lines
1.3 KiB
Java
Raw Normal View History

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