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

36 lines
1.2 KiB
Java
Raw Normal View History

2019-01-22 16:10:27 +01:00
package de.ellpeck.naturesaura.items;
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;
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;
public class ItemMoverMinecart extends ItemImpl {
public ItemMoverMinecart() {
super("mover_cart");
this.setMaxStackSize(1);
}
@Nonnull
@Override
2019-10-20 22:30:49 +02:00
public ActionResultType onItemUse(PlayerEntity player, World world, BlockPos pos, Hand hand, Direction side, float hitX, float hitY, float hitZ) {
if (AbstractRailBlock.isRailBlock(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-01-22 16:10:27 +01:00
world.spawnEntity(cart);
}
player.getHeldItem(hand).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
}
}