minecraft-source/src/net/minecraft/world/item/EndCrystalItem.java

57 lines
2.1 KiB
Java

package net.minecraft.world.item;
import net.minecraft.world.level.dimension.end.EndDragonFight;
import java.util.List;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.dimension.end.TheEndDimension;
import net.minecraft.world.entity.boss.enderdragon.EndCrystal;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.InteractionResult;
public class EndCrystalItem extends Item {
public EndCrystalItem(final Properties a) {
super(a);
}
@Override
public InteractionResult useOn(final UseOnContext bfw) {
final Level bjt3 = bfw.getLevel();
final BlockPos fk4 = bfw.getClickedPos();
final BlockState byg5 = bjt3.getBlockState(fk4);
if (byg5.getBlock() != Blocks.OBSIDIAN && byg5.getBlock() != Blocks.BEDROCK) {
return InteractionResult.FAIL;
}
final BlockPos fk5 = fk4.above();
if (!bjt3.isEmptyBlock(fk5)) {
return InteractionResult.FAIL;
}
final double double7 = fk5.getX();
final double double8 = fk5.getY();
final double double9 = fk5.getZ();
final List<Entity> list13 = bjt3.getEntities(null, new AABB(double7, double8, double9, double7 + 1.0, double8 + 2.0, double9 + 1.0));
if (!list13.isEmpty()) {
return InteractionResult.FAIL;
}
if (!bjt3.isClientSide) {
final EndCrystal auo14 = new EndCrystal(bjt3, double7 + 0.5, double8, double9 + 0.5);
auo14.setShowBottom(false);
bjt3.addFreshEntity(auo14);
if (bjt3.dimension instanceof TheEndDimension) {
final EndDragonFight cbj15 = ((TheEndDimension)bjt3.dimension).getDragonFight();
cbj15.tryRespawn();
}
}
bfw.getItemInHand().shrink(1);
return InteractionResult.SUCCESS;
}
@Override
public boolean isFoil(final ItemStack bek) {
return true;
}
}