2019-01-22 16:10:27 +01:00
|
|
|
package de.ellpeck.naturesaura.items;
|
|
|
|
|
|
|
|
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;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.util.InteractionResult;
|
2019-01-22 16:10:27 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.level.Level;
|
2019-01-22 16:10:27 +01:00
|
|
|
|
|
|
|
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
|
2021-12-04 15:40:09 +01:00
|
|
|
public InteractionResult onItemUse(ItemUseContext context) {
|
|
|
|
Level level = context.getLevel();
|
2019-11-04 19:08:49 +01:00
|
|
|
BlockPos pos = context.getPos();
|
2021-12-04 15:40:09 +01:00
|
|
|
if (AbstractRailBlock.isRail(level.getBlockState(pos))) {
|
|
|
|
if (!level.isClientSide) {
|
|
|
|
AbstractMinecartEntity cart = new EntityMoverMinecart(ModEntities.MOVER_CART, level, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
|
|
|
level.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);
|
2021-12-04 15:40:09 +01:00
|
|
|
return InteractionResult.SUCCESS;
|
2019-01-22 16:10:27 +01:00
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
return InteractionResult.PASS;
|
2019-01-22 16:10:27 +01:00
|
|
|
}
|
|
|
|
}
|