2025-11-24 22:52:51 +03:00

104 lines
4.4 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.serialization.MapCodec
*/
package net.minecraft.world.level.block;
import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.FrontAndTop;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.GameMasterBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.JigsawBlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.phys.BlockHitResult;
public class JigsawBlock
extends Block
implements EntityBlock,
GameMasterBlock {
public static final MapCodec<JigsawBlock> CODEC = JigsawBlock.simpleCodec(JigsawBlock::new);
public static final EnumProperty<FrontAndTop> ORIENTATION = BlockStateProperties.ORIENTATION;
public MapCodec<JigsawBlock> codec() {
return CODEC;
}
protected JigsawBlock(BlockBehaviour.Properties properties) {
super(properties);
this.registerDefaultState((BlockState)((BlockState)this.stateDefinition.any()).setValue(ORIENTATION, FrontAndTop.NORTH_UP));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(ORIENTATION);
}
@Override
protected BlockState rotate(BlockState state, Rotation rotation) {
return (BlockState)state.setValue(ORIENTATION, rotation.rotation().rotate(state.getValue(ORIENTATION)));
}
@Override
protected BlockState mirror(BlockState state, Mirror mirror) {
return (BlockState)state.setValue(ORIENTATION, mirror.rotation().rotate(state.getValue(ORIENTATION)));
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction front = context.getClickedFace();
Direction top = front.getAxis() == Direction.Axis.Y ? context.getHorizontalDirection().getOpposite() : Direction.UP;
return (BlockState)this.defaultBlockState().setValue(ORIENTATION, FrontAndTop.fromFrontAndTop(front, top));
}
@Override
public BlockEntity newBlockEntity(BlockPos worldPosition, BlockState blockState) {
return new JigsawBlockEntity(worldPosition, blockState);
}
@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hitResult) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (blockEntity instanceof JigsawBlockEntity && player.canUseGameMasterBlocks()) {
player.openJigsawBlock((JigsawBlockEntity)blockEntity);
return InteractionResult.SUCCESS;
}
return InteractionResult.PASS;
}
public static boolean canAttach(StructureTemplate.JigsawBlockInfo source, StructureTemplate.JigsawBlockInfo target) {
Direction sourceFront = JigsawBlock.getFrontFacing(source.info().state());
Direction targetFront = JigsawBlock.getFrontFacing(target.info().state());
Direction sourceTop = JigsawBlock.getTopFacing(source.info().state());
Direction targetTop = JigsawBlock.getTopFacing(target.info().state());
JigsawBlockEntity.JointType jointType = source.jointType();
boolean rollable = jointType == JigsawBlockEntity.JointType.ROLLABLE;
return sourceFront == targetFront.getOpposite() && (rollable || sourceTop == targetTop) && source.target().equals(target.name());
}
public static Direction getFrontFacing(BlockState state) {
return state.getValue(ORIENTATION).front();
}
public static Direction getTopFacing(BlockState state) {
return state.getValue(ORIENTATION).top();
}
}