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

112 lines
4.3 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.datafixers.kinds.App
* com.mojang.datafixers.kinds.Applicative
* com.mojang.serialization.Codec
* com.mojang.serialization.MapCodec
* com.mojang.serialization.codecs.RecordCodecBuilder
* it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap
*/
package net.minecraft.world.level.block;
import com.mojang.datafixers.kinds.App;
import com.mojang.datafixers.kinds.Applicative;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import java.util.Map;
import net.minecraft.core.BlockPos;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.AbstractSkullBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
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.IntegerProperty;
import net.minecraft.world.level.block.state.properties.RotationSegment;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
public class SkullBlock
extends AbstractSkullBlock {
public static final MapCodec<SkullBlock> CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)Type.CODEC.fieldOf("kind").forGetter(AbstractSkullBlock::getType), SkullBlock.propertiesCodec()).apply((Applicative)i, SkullBlock::new));
public static final int MAX = RotationSegment.getMaxSegmentIndex();
private static final int ROTATIONS = MAX + 1;
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
private static final VoxelShape SHAPE = Block.column(8.0, 0.0, 8.0);
private static final VoxelShape SHAPE_PIGLIN = Block.column(10.0, 0.0, 8.0);
public MapCodec<? extends SkullBlock> codec() {
return CODEC;
}
protected SkullBlock(Type type, BlockBehaviour.Properties properties) {
super(type, properties);
this.registerDefaultState((BlockState)this.defaultBlockState().setValue(ROTATION, 0));
}
@Override
protected VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
return this.getType() == Types.PIGLIN ? SHAPE_PIGLIN : SHAPE;
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return (BlockState)super.getStateForPlacement(context).setValue(ROTATION, RotationSegment.convertToSegment(context.getRotation()));
}
@Override
protected BlockState rotate(BlockState state, Rotation rotation) {
return (BlockState)state.setValue(ROTATION, rotation.rotate(state.getValue(ROTATION), ROTATIONS));
}
@Override
protected BlockState mirror(BlockState state, Mirror mirror) {
return (BlockState)state.setValue(ROTATION, mirror.mirror(state.getValue(ROTATION), ROTATIONS));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
builder.add(ROTATION);
}
public static interface Type
extends StringRepresentable {
public static final Map<String, Type> TYPES = new Object2ObjectArrayMap();
public static final Codec<Type> CODEC = Codec.stringResolver(StringRepresentable::getSerializedName, TYPES::get);
}
public static enum Types implements Type
{
SKELETON("skeleton"),
WITHER_SKELETON("wither_skeleton"),
PLAYER("player"),
ZOMBIE("zombie"),
CREEPER("creeper"),
PIGLIN("piglin"),
DRAGON("dragon");
private final String name;
private Types(String name) {
this.name = name;
TYPES.put(name, this);
}
@Override
public String getSerializedName() {
return this.name;
}
}
}