71 lines
2.8 KiB
Java
71 lines
2.8 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import net.minecraft.world.entity.EntitySelector;
|
|
import net.minecraft.world.phys.AABB;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import net.minecraft.world.phys.Vec3;
|
|
import net.minecraft.stats.Stat;
|
|
import net.minecraft.stats.Stats;
|
|
import net.minecraft.world.phys.HitResult;
|
|
import net.minecraft.world.level.ClipContext;
|
|
import net.minecraft.world.InteractionResultHolder;
|
|
import net.minecraft.world.InteractionHand;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.entity.vehicle.Boat;
|
|
import net.minecraft.world.entity.Entity;
|
|
import java.util.function.Predicate;
|
|
|
|
public class BoatItem extends Item {
|
|
private static final Predicate<Entity> ENTITY_PREDICATE;
|
|
private final Boat.Type type;
|
|
|
|
public BoatItem(final Boat.Type b, final Properties a) {
|
|
super(a);
|
|
this.type = b;
|
|
}
|
|
|
|
@Override
|
|
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
|
|
final ItemStack bek5 = ayg.getItemInHand(ajh);
|
|
final HitResult cvf6 = Item.getPlayerPOVHitResult(bjt, ayg, ClipContext.Fluid.ANY);
|
|
if (cvf6.getType() == HitResult.Type.MISS) {
|
|
return InteractionResultHolder.<ItemStack>pass(bek5);
|
|
}
|
|
final Vec3 cvi7 = ayg.getViewVector(1.0f);
|
|
final double double8 = 5.0;
|
|
final List<Entity> list10 = bjt.getEntities(ayg, ayg.getBoundingBox().expandTowards(cvi7.scale(5.0)).inflate(1.0), BoatItem.ENTITY_PREDICATE);
|
|
if (!list10.isEmpty()) {
|
|
final Vec3 cvi8 = ayg.getEyePosition(1.0f);
|
|
for (final Entity akn13 : list10) {
|
|
final AABB cvc14 = akn13.getBoundingBox().inflate(akn13.getPickRadius());
|
|
if (cvc14.contains(cvi8)) {
|
|
return InteractionResultHolder.<ItemStack>pass(bek5);
|
|
}
|
|
}
|
|
}
|
|
if (cvf6.getType() != HitResult.Type.BLOCK) {
|
|
return InteractionResultHolder.<ItemStack>pass(bek5);
|
|
}
|
|
final Boat azw11 = new Boat(bjt, cvf6.getLocation().x, cvf6.getLocation().y, cvf6.getLocation().z);
|
|
azw11.setType(this.type);
|
|
azw11.yRot = ayg.yRot;
|
|
if (!bjt.noCollision(azw11, azw11.getBoundingBox().inflate(-0.1))) {
|
|
return InteractionResultHolder.<ItemStack>fail(bek5);
|
|
}
|
|
if (!bjt.isClientSide) {
|
|
bjt.addFreshEntity(azw11);
|
|
if (!ayg.abilities.instabuild) {
|
|
bek5.shrink(1);
|
|
}
|
|
}
|
|
ayg.awardStat(Stats.ITEM_USED.get(this));
|
|
return InteractionResultHolder.<ItemStack>success(bek5);
|
|
}
|
|
|
|
static {
|
|
ENTITY_PREDICATE = EntitySelector.NO_SPECTATORS.and(Entity::isPickable);
|
|
}
|
|
}
|