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

91 lines
4.0 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.MapCodec
* com.mojang.serialization.codecs.RecordCodecBuilder
*/
package net.minecraft.world.level.block;
import com.mojang.datafixers.kinds.App;
import com.mojang.datafixers.kinds.Applicative;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.ScheduledTickAccess;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SignBlock;
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.level.block.state.properties.WoodType;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
public class StandingSignBlock
extends SignBlock {
public static final MapCodec<StandingSignBlock> CODEC = RecordCodecBuilder.mapCodec(i -> i.group((App)WoodType.CODEC.fieldOf("wood_type").forGetter(SignBlock::type), StandingSignBlock.propertiesCodec()).apply((Applicative)i, StandingSignBlock::new));
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
public MapCodec<StandingSignBlock> codec() {
return CODEC;
}
public StandingSignBlock(WoodType type, BlockBehaviour.Properties properties) {
super(type, properties.sound(type.soundType()));
this.registerDefaultState((BlockState)((BlockState)((BlockState)this.stateDefinition.any()).setValue(ROTATION, 0)).setValue(WATERLOGGED, false));
}
@Override
protected boolean canSurvive(BlockState state, LevelReader level, BlockPos pos) {
return level.getBlockState(pos.below()).isSolid();
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
FluidState replacedFluidState = context.getLevel().getFluidState(context.getClickedPos());
return (BlockState)((BlockState)this.defaultBlockState().setValue(ROTATION, RotationSegment.convertToSegment(context.getRotation() + 180.0f))).setValue(WATERLOGGED, replacedFluidState.getType() == Fluids.WATER);
}
@Override
protected BlockState updateShape(BlockState state, LevelReader level, ScheduledTickAccess ticks, BlockPos pos, Direction directionToNeighbour, BlockPos neighbourPos, BlockState neighbourState, RandomSource random) {
if (directionToNeighbour == Direction.DOWN && !this.canSurvive(state, level, pos)) {
return Blocks.AIR.defaultBlockState();
}
return super.updateShape(state, level, ticks, pos, directionToNeighbour, neighbourPos, neighbourState, random);
}
@Override
public float getYRotationDegrees(BlockState state) {
return RotationSegment.convertToDegrees(state.getValue(ROTATION));
}
@Override
protected BlockState rotate(BlockState state, Rotation rotation) {
return (BlockState)state.setValue(ROTATION, rotation.rotate(state.getValue(ROTATION), 16));
}
@Override
protected BlockState mirror(BlockState state, Mirror mirror) {
return (BlockState)state.setValue(ROTATION, mirror.mirror(state.getValue(ROTATION), 16));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(ROTATION, WATERLOGGED);
}
}