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;
|
2020-01-21 23:02:39 +01:00
|
|
|
import de.ellpeck.naturesaura.entities.ModEntities;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.AbstractRailBlock;
|
|
|
|
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
|
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;
|
2019-01-22 16:10:27 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2020-01-26 01:41:49 +01:00
|
|
|
public class ItemMoverMinecart extends ItemImpl {
|
2019-01-22 16:10:27 +01:00
|
|
|
|
2020-01-26 01:41:49 +01:00
|
|
|
public ItemMoverMinecart() {
|
2020-02-07 23:50:16 +01:00
|
|
|
super("mover_cart", new Properties().maxStackSize(1));
|
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) {
|
2020-01-23 19:20:47 +01:00
|
|
|
AbstractMinecartEntity cart = new EntityMoverMinecart(ModEntities.MOVER_CART, 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
|
|
|
}
|
|
|
|
}
|