Merge new update in

This commit is contained in:
Andrew-71 2023-08-25 14:28:30 +03:00
parent 5032895c13
commit d7e3ee995d
121 changed files with 5595 additions and 10 deletions

View file

@ -0,0 +1,108 @@
package su.a71.new_soviet.blocks;
import net.minecraft.block.*;
import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;
public class CheckerBlock extends Block implements Waterloggable {
public static final int MAX_PICKLES = 4;
public static final IntProperty CHECKERS;
public static final BooleanProperty WATERLOGGED;
protected static final VoxelShape ONE_CHECKER;
protected static final VoxelShape TWO_CHECKER;
protected static final VoxelShape THREE_CHECKER;
protected static final VoxelShape FOUR_CHECKER;
public CheckerBlock(AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(CHECKERS, 1)).with(WATERLOGGED, true));
}
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockState blockState = ctx.getWorld().getBlockState(ctx.getBlockPos());
if (blockState.isOf(this)) {
return (BlockState)blockState.with(CHECKERS, Math.min(4, (Integer)blockState.get(CHECKERS) + 1));
} else {
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
boolean bl = fluidState.getFluid() == Fluids.WATER;
return (BlockState)super.getPlacementState(ctx).with(WATERLOGGED, bl);
}
}
protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) {
return !floor.getCollisionShape(world, pos).getFace(Direction.UP).isEmpty() || floor.isSideSolidFullSquare(world, pos, Direction.UP);
}
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockPos blockPos = pos.down();
return this.canPlantOnTop(world.getBlockState(blockPos), world, blockPos);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
} else {
if ((Boolean)state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
}
public boolean canReplace(BlockState state, ItemPlacementContext context) {
return !context.shouldCancelInteraction() && context.getStack().isOf(this.asItem()) && (Integer) state.get(CHECKERS) < 4 || super.canReplace(state, context);
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
switch ((Integer)state.get(CHECKERS)) {
case 1:
default:
return ONE_CHECKER;
case 2:
return TWO_CHECKER;
case 3:
return THREE_CHECKER;
case 4:
return FOUR_CHECKER;
}
}
public FluidState getFluidState(BlockState state) {
return (Boolean)state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{CHECKERS, WATERLOGGED});
}
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
return false;
}
static {
CHECKERS = IntProperty.of("checkers", 1, 4);;
WATERLOGGED = Properties.WATERLOGGED;
ONE_CHECKER = Block.createCuboidShape(2.0, 0.0, 2.0, 14.0, 4.0, 14.0);
TWO_CHECKER = Block.createCuboidShape(2.0, 0.0, 2.0, 14.0, 8.0, 14.0);
THREE_CHECKER = Block.createCuboidShape(2.0, 0.0, 2.0, 14.0, 12.0, 14.0);
FOUR_CHECKER = Block.createCuboidShape(2.0, 0.0, 2.0, 14.0, 16.0, 14.0);
}
}

View file

@ -0,0 +1,50 @@
package su.a71.new_soviet.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldView;
public class ChessBlock extends HorizontalFacingBlock {
private VoxelShape blockShape;
public ChessBlock(AbstractBlock.Settings settings, VoxelShape blockShape) {
super(settings.notSolid().nonOpaque().noBlockBreakParticles().pistonBehavior(PistonBehavior.DESTROY).strength(0.1f, 2f));
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
this.blockShape = blockShape;
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.HORIZONTAL_FACING);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
return VoxelShapes.union(blockShape, Block.createCuboidShape(4,0,4,12,1,12), Block.createCuboidShape(5,1,5,11,4,11), Block.createCuboidShape(6,0,6,10,13,10));
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) {
return !floor.getCollisionShape(world, pos).getFace(Direction.UP).isEmpty() || floor.isSideSolidFullSquare(world, pos, Direction.UP);
}
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockPos blockPos = pos.down();
return this.canPlantOnTop(world.getBlockState(blockPos), world, blockPos);
}
}

View file

@ -0,0 +1,57 @@
package su.a71.new_soviet.blocks;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldView;
import su.a71.new_soviet.util.Shapes;
public class ChessBlockKnight extends HorizontalFacingBlock {
public ChessBlockKnight(Settings settings) {
super(settings.notSolid().nonOpaque().noBlockBreakParticles().pistonBehavior(PistonBehavior.DESTROY).strength(0.1f, 2f));
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.HORIZONTAL_FACING);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
Direction dir = state.get(FACING);
return switch (dir) {
case NORTH -> VoxelShapes.union(Block.createCuboidShape(4,0,4,12,1,12), Block.createCuboidShape(5,1,5,11,4,11), Block.createCuboidShape(6,0,6,10,13,10), Block.createCuboidShape(5.5,9,1.5,10.5,13,9.5), Block.createCuboidShape(7.5,8,6,8.5,17,11));
case SOUTH -> VoxelShapes.union(Block.createCuboidShape(4,0,4,12,1,12), Block.createCuboidShape(5,1,5,11,4,11), Block.createCuboidShape(6,0,6,10,13,10), Block.createCuboidShape(5.5,9,6.5,10.5,13,14.5), Block.createCuboidShape(7.5,8,5,8.5,17,10));
case EAST -> VoxelShapes.union(Block.createCuboidShape(4,0,4,12,1,12), Block.createCuboidShape(5,1,5,11,4,11), Block.createCuboidShape(6,0,6,10,13,10), Block.createCuboidShape(6.5,9,5.5,14.5,13,10.5), Block.createCuboidShape(5,8,7.5,10,17,8.5));
case WEST -> VoxelShapes.union(Block.createCuboidShape(4,0,4,12,1,12), Block.createCuboidShape(5,1,5,11,4,11), Block.createCuboidShape(6,0,6,10,13,10), Block.createCuboidShape(1.5,9,5.5,9.5,13,10.5), Block.createCuboidShape(6,8,7.5,11,17,8.5));
default -> VoxelShapes.fullCube();
};
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) {
return !floor.getCollisionShape(world, pos).getFace(Direction.UP).isEmpty() || floor.isSideSolidFullSquare(world, pos, Direction.UP);
}
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockPos blockPos = pos.down();
return this.canPlantOnTop(world.getBlockState(blockPos), world, blockPos);
}
}

View file

@ -0,0 +1,165 @@
package su.a71.new_soviet.blocks;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.enums.BlockHalf;
import net.minecraft.block.enums.StairShape;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.registry.tag.BlockTags;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.gen.feature.util.CaveSurface;
import su.a71.new_soviet.entity.TVBlockEntity;
import su.a71.new_soviet.registration.NSE_Blocks;
import su.a71.new_soviet.util.Shapes;
import java.util.List;
import java.util.Objects;
import static net.minecraft.block.StairsBlock.HALF;
import static net.minecraft.block.StairsBlock.SHAPE;
public class HandrailBlock extends HorizontalFacingBlock implements BlockEntityProvider {
protected static final Shapes.HorizontalShape2 SHAPE1;
protected static final Shapes.HorizontalShape2 SHAPE2;
protected static final Shapes.HorizontalShape2 SHAPE3;
public static final BooleanProperty WATERLOGGED;
public static final IntProperty ROTATE;
public HandrailBlock(Settings settings) {
super(settings.sounds(BlockSoundGroup.METAL).pistonBehavior(PistonBehavior.BLOCK).strength(1f, 2f));
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.HORIZONTAL_FACING, WATERLOGGED, ROTATE);
}
public FluidState getFluidState(BlockState state) {
return (Boolean)state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
Direction dir = state.get(FACING);
int rot = state.get(ROTATE);
return switch (dir) {
case NORTH -> switch (rot) {
case 1 -> SHAPE1.north();
case 2 -> SHAPE2.north();
case 3 -> SHAPE3.north();
default -> VoxelShapes.fullCube();
};
case SOUTH -> switch (rot) {
case 1 -> SHAPE1.south();
case 2 -> SHAPE2.south();
case 3 -> SHAPE3.south();
default -> VoxelShapes.fullCube();
};
case EAST -> switch (rot) {
case 1 -> SHAPE1.east();
case 2 -> SHAPE2.east();
case 3 -> SHAPE3.east();
default -> VoxelShapes.fullCube();
};
case WEST -> switch (rot) {
case 1 -> SHAPE1.west();
case 2 -> SHAPE2.west();
case 3 -> SHAPE3.west();
default -> VoxelShapes.fullCube();
};
default -> VoxelShapes.fullCube();
};
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
boolean bl = fluidState.getFluid() == Fluids.WATER;
int rot = 2;
BlockPos under = new BlockPos(ctx.getBlockPos().getX(), ctx.getBlockPos().getY() - 1, ctx.getBlockPos().getZ());
if (istruestairs1(ctx.getWorld().getBlockState(ctx.getBlockPos().down(1)), ctx)) {
rot = 1;
} else if (istruestairs2(ctx.getWorld().getBlockState(ctx.getBlockPos().down(1)), ctx)) {
rot = 3;
}
return (BlockState)this.getDefaultState()
.with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER)
.with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite())
.with(ROTATE, rot);
}
private boolean istruestairs1(BlockState blockState, ItemPlacementContext ctx) {
boolean output = false;
if (blockState.isIn(BlockTags.STAIRS)) {
boolean h = blockState.get(SHAPE) == StairShape.STRAIGHT;
if (h && blockState.get(HALF) == BlockHalf.BOTTOM && returnFacing(blockState.get(FACING).getName()) == ctx.getHorizontalPlayerFacing().getOpposite().getName()) {
output = true;
}
}
return output;
}
private boolean istruestairs2(BlockState blockState, ItemPlacementContext ctx) {
boolean output = false;
if (blockState.isIn(BlockTags.STAIRS)) {
boolean h = blockState.get(SHAPE) == StairShape.STRAIGHT;
if (h && blockState.get(HALF) == BlockHalf.BOTTOM && blockState.get(FACING).getName() == returnFacing(ctx.getHorizontalPlayerFacing().getOpposite().getName())) {
output = true;
}
}
return output;
}
private String returnFacing(String facing1) {
String facing2 = "north";
if (facing1 == "north") {
facing2 = "west";
} else if (facing1 == "west") {
facing2 = "south";
} else if (facing1 == "south") {
facing2 = "east";
}
return facing2;
}
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new TVBlockEntity(pos, state);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
} else {
if ((Boolean)state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
}
static {
SHAPE2 = new Shapes.HorizontalShape2(List.of(List.of(0.0, 0.0, 15.0, 16.0, 17.0, 16.0), List.of(0.0, 17.0, 14.5, 16.0, 19.0, 16.5)));
SHAPE1 = new Shapes.HorizontalShape2(List.of(List.of(0.0, 0.0, 15.0, 8.0, 18.0, 16.0), List.of(8.0, -8.0, 15.0, 16.0, 10.0, 16.0)));
SHAPE3 = new Shapes.HorizontalShape2(List.of(List.of(0.0, -8.0, 15.0, 8.0, 10.0, 16.0), List.of(8.0, 0.0, 15.0, 16.0, 18.0, 16.0)));
ROTATE = IntProperty.of("rotate", 1, 3);;
WATERLOGGED = Properties.WATERLOGGED;
}
}

View file

@ -14,8 +14,13 @@ import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import su.a71.new_soviet.entity.TVBlockEntity;
import su.a71.new_soviet.util.Shapes;
import java.util.List;
public class TVBlock extends HorizontalFacingBlock implements BlockEntityProvider {
protected static final Shapes.HorizontalShape SHAPE;
public TVBlock(AbstractBlock.Settings settings) {
super(settings.sounds(BlockSoundGroup.METAL).pistonBehavior(PistonBehavior.BLOCK).strength(1f, 2f));
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
@ -30,8 +35,10 @@ public class TVBlock extends HorizontalFacingBlock implements BlockEntityProvide
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
Direction dir = state.get(FACING);
return switch (dir) {
case NORTH, SOUTH -> VoxelShapes.cuboid(0.0f, 0.0f, 0.1875f, 1.0f, 0.8125f, 0.8125f);
case EAST, WEST -> VoxelShapes.cuboid(0.1875f, 0.0f, 0.0f, 0.8125f, 0.8125f, 1.0f);
case NORTH -> SHAPE.north();
case SOUTH -> SHAPE.south();
case EAST -> SHAPE.east();
case WEST -> SHAPE.west();
default -> VoxelShapes.fullCube();
};
}
@ -45,4 +52,8 @@ public class TVBlock extends HorizontalFacingBlock implements BlockEntityProvide
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new TVBlockEntity(pos, state);
}
static {
SHAPE = new Shapes.HorizontalShape(List.of(List.of(0.0, 1.0, 3.0, 16.0, 13.0, 13.0), List.of(2.0, 0.0, 4.0, 14.0, 1.0, 12.0), List.of(6.0, 13.0, 7.0, 10.0, 14.0, 9.0)));
}
}