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;
|
2021-12-15 16:24:53 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.world.InteractionResult;
|
|
|
|
import net.minecraft.world.entity.vehicle.AbstractMinecart;
|
|
|
|
import net.minecraft.world.item.context.UseOnContext;
|
|
|
|
import net.minecraft.world.level.Level;
|
|
|
|
import net.minecraft.world.level.block.BaseRailBlock;
|
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() {
|
2021-12-15 16:24:53 +01:00
|
|
|
super("mover_cart", new Properties().stacksTo(1));
|
2019-01-22 16:10:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
@Override
|
2021-12-15 16:24:53 +01:00
|
|
|
public InteractionResult useOn(UseOnContext context) {
|
2021-12-15 16:30:22 +01:00
|
|
|
var level = context.getLevel();
|
|
|
|
var pos = context.getClickedPos();
|
2021-12-15 16:24:53 +01:00
|
|
|
if (BaseRailBlock.isRail(level.getBlockState(pos))) {
|
2021-12-04 15:40:09 +01:00
|
|
|
if (!level.isClientSide) {
|
2021-12-15 16:24:53 +01:00
|
|
|
AbstractMinecart cart = new EntityMoverMinecart(ModEntities.MOVER_CART, level, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
|
|
|
level.addFreshEntity(cart);
|
2019-01-22 16:10:27 +01:00
|
|
|
}
|
2021-12-15 16:24:53 +01:00
|
|
|
context.getPlayer().getItemInHand(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
|
|
|
}
|
|
|
|
}
|