82 lines
3.2 KiB
Java
82 lines
3.2 KiB
Java
package net.minecraft.world.item;
|
|
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.ScaffoldingBlock;
|
|
import net.minecraft.network.protocol.Packet;
|
|
import net.minecraft.network.protocol.game.ClientboundChatPacket;
|
|
import net.minecraft.network.chat.ChatType;
|
|
import net.minecraft.ChatFormatting;
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
public class ScaffoldingBlockItem extends BlockItem {
|
|
public ScaffoldingBlockItem(final Block bpe, final Properties a) {
|
|
super(bpe, a);
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public BlockPlaceContext updatePlacementContext(final BlockPlaceContext bcn) {
|
|
final BlockPos fk3 = bcn.getClickedPos();
|
|
final Level bjt4 = bcn.getLevel();
|
|
BlockState byg5 = bjt4.getBlockState(fk3);
|
|
final Block bpe6 = this.getBlock();
|
|
if (byg5.getBlock() == bpe6) {
|
|
Direction fp7;
|
|
if (bcn.isSecondaryUseActive()) {
|
|
fp7 = (bcn.isInside() ? bcn.getClickedFace().getOpposite() : bcn.getClickedFace());
|
|
}
|
|
else {
|
|
fp7 = ((bcn.getClickedFace() == Direction.UP) ? bcn.getHorizontalDirection() : Direction.UP);
|
|
}
|
|
int integer8 = 0;
|
|
final BlockPos.MutableBlockPos a9 = new BlockPos.MutableBlockPos(fk3).move(fp7);
|
|
while (integer8 < 7) {
|
|
if (!bjt4.isClientSide && !Level.isInWorldBounds(a9)) {
|
|
final Player ayg10 = bcn.getPlayer();
|
|
final int integer9 = bjt4.getMaxBuildHeight();
|
|
if (ayg10 instanceof ServerPlayer && a9.getY() >= integer9) {
|
|
final ClientboundChatPacket mm12 = new ClientboundChatPacket(new TranslatableComponent("build.tooHigh", new Object[] { integer9 }).withStyle(ChatFormatting.RED), ChatType.GAME_INFO);
|
|
((ServerPlayer)ayg10).connection.send(mm12);
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
else {
|
|
byg5 = bjt4.getBlockState(a9);
|
|
if (byg5.getBlock() != this.getBlock()) {
|
|
if (byg5.canBeReplaced(bcn)) {
|
|
return BlockPlaceContext.at(bcn, a9, fp7);
|
|
}
|
|
break;
|
|
}
|
|
else {
|
|
a9.move(fp7);
|
|
if (!fp7.getAxis().isHorizontal()) {
|
|
continue;
|
|
}
|
|
++integer8;
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
if (ScaffoldingBlock.getDistance(bjt4, fk3) == 7) {
|
|
return null;
|
|
}
|
|
return bcn;
|
|
}
|
|
|
|
@Override
|
|
protected boolean mustSurvive() {
|
|
return false;
|
|
}
|
|
}
|