51 lines
No EOL
2 KiB
Java
51 lines
No EOL
2 KiB
Java
package su.a71.new_soviet.blocks;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.block.DoorBlock;
|
|
import net.minecraft.block.TrapdoorBlock;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import net.minecraft.item.ItemPlacementContext;
|
|
import net.minecraft.state.StateManager;
|
|
import net.minecraft.state.property.BooleanProperty;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import net.minecraft.util.math.Direction;
|
|
import net.minecraft.world.World;
|
|
import net.minecraft.world.WorldAccess;
|
|
|
|
public class WallpaperBlock extends Block {
|
|
public static final BooleanProperty HAS_BASEBOARD = BooleanProperty.of("has_baseboard");
|
|
|
|
public WallpaperBlock(Settings settings) {
|
|
super(settings);
|
|
this.setDefaultState(this.stateManager.getDefaultState().with(HAS_BASEBOARD, false));
|
|
}
|
|
|
|
@Override
|
|
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
|
builder.add(HAS_BASEBOARD);
|
|
}
|
|
|
|
@Override
|
|
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
|
BlockPos pos = ctx.getBlockPos();
|
|
boolean hasBaseboard = isFullBlock(ctx.getWorld(), pos);
|
|
return this.getDefaultState().with(HAS_BASEBOARD, hasBaseboard);
|
|
}
|
|
|
|
@Override
|
|
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
|
|
|
|
BlockState updatedBlockState = state.with(HAS_BASEBOARD, isFullBlock(world, pos));
|
|
world.setBlockState(pos, updatedBlockState);
|
|
|
|
}
|
|
|
|
private boolean isFullBlock(WorldAccess world, BlockPos pos) {
|
|
pos = pos.down();
|
|
BlockState state = world.getBlockState(pos);
|
|
Block block = state.getBlock();
|
|
//return (!state.getCollisionShape(world, pos).getFace(Direction.UP).isEmpty() || state.isSideSolidFullSquare(world, pos, Direction.UP)) && !(block instanceof WallpaperBlock);
|
|
return block.isShapeFullCube(state, world, pos) && !(block instanceof WallpaperBlock) && (!block.isTransparent(state, world, pos));
|
|
}
|
|
} |