Do chores related to code quality

This commit is contained in:
Andrew-71 2023-09-25 10:51:32 +03:00
parent 2a6898b664
commit 2a695c6029
25 changed files with 126 additions and 174 deletions

View file

@ -1,18 +1,18 @@
aquamarine recipe
whitewash recipe
concrete recipe
concrete with bars recipe
parquet recipe
linoleum recipe
metal plating recipe
crate recipe
po-2 recipe
no wallpaper recipes (intended?)
no handrail recipe
no nutrient block recipe (intended? compressed bread?)
light bulb recipe
sigarette recipe
siren recipe
no landmine recipe - intended
switch recipe
checkers and chess recipe
* aquamarine recipe
* whitewash recipe
* concrete recipe
* concrete with bars recipe
* parquet recipe
* linoleum recipe
* metal plating recipe
* crate recipe
* po-2 recipe
* no wallpaper recipes (intended?)
* no handrail recipe
* no nutrient block recipe (intended? compressed bread?)
* light bulb recipe
* cigarette recipe
* siren recipe
* no landmine recipe - intended
* switch recipe
* checkers and chess recipe

View file

@ -15,12 +15,12 @@ import su.a71.new_soviet.entities.TVBlockEntity;
@Environment(EnvType.CLIENT)
public class TVBlockEntityRenderer implements BlockEntityRenderer<TVBlockEntity> {
private static TextRenderer textRenderer;
// private static TextRenderer textRenderer;
private static final Vec3d TEXT_OFFSET = new Vec3d(0.0, 0.3333333432674408, 0.046666666865348816);
public TVBlockEntityRenderer(BlockEntityRendererFactory.Context ctx) {
textRenderer = ctx.getTextRenderer();
// textRenderer = ctx.getTextRenderer();
}
@Override

View file

@ -17,18 +17,21 @@ public class Config {
private static void generateDefault() {
INSTANCE = new Config();
NewSoviet.LOG.info("Generated config file at config/new_soviet.json");
File file = new File("config/new_soviet.json");
if(!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
if(!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
NewSoviet.LOG.error("Error making dir for config, using default");
INSTANCE = new Config(); // Something went wrong with mkdir
return;
}
INSTANCE = new Config();
try {
FileWriter writer = new FileWriter(file);
writer.write(NewSoviet.GSON.toJson(INSTANCE));
writer.close();
} catch (Exception e) {
INSTANCE = new Config();
NewSoviet.LOG.error("Error creating config, using default", e);
}
}

View file

@ -8,7 +8,6 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
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.math.random.Random;
@ -28,25 +27,25 @@ public class CeilingFanBlock extends Block implements Waterloggable {
public CeilingFanBlock(Block.Settings settings) {
super(settings);
this.setDefaultState((BlockState)this.getDefaultState().with(ON, false).with(WATERLOGGED, false));
this.setDefaultState(this.getDefaultState().with(ON, false).with(WATERLOGGED, false));
}
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
return (BlockState)this.getDefaultState()
return this.getDefaultState()
.with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos()))
.with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
if (!world.isClient) {
boolean bl = (Boolean)state.get(ON);
boolean bl = state.get(ON);
if (bl != world.isReceivingRedstonePower(pos)) {
if (bl) {
world.scheduleBlockTick(pos, this, 4);
} else {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
world.setBlockState(pos, state.cycle(ON), 2);
}
}
}
@ -61,13 +60,13 @@ public class CeilingFanBlock extends Block implements Waterloggable {
}
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if ((Boolean)state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
if (state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, state.cycle(ON), 2);
}
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{ON, WATERLOGGED});
builder.add(ON, WATERLOGGED);
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {

View file

@ -2,7 +2,6 @@ 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;
@ -10,18 +9,15 @@ 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;
@ -31,18 +27,18 @@ public class CheckerBlock extends Block implements Waterloggable {
public CheckerBlock(AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(CHECKERS, 1)).with(WATERLOGGED, true));
this.setDefaultState(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));
return blockState.with(CHECKERS, Math.min(4, 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);
return super.getPlacementState(ctx).with(WATERLOGGED, bl);
}
}
@ -59,7 +55,7 @@ public class CheckerBlock extends Block implements Waterloggable {
if (!state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
} else {
if ((Boolean)state.get(WATERLOGGED)) {
if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
@ -68,29 +64,24 @@ public class CheckerBlock extends Block implements Waterloggable {
}
public boolean canReplace(BlockState state, ItemPlacementContext context) {
return !context.shouldCancelInteraction() && context.getStack().isOf(this.asItem()) && (Integer) state.get(CHECKERS) < 4 || super.canReplace(state, context);
return !context.shouldCancelInteraction() && context.getStack().isOf(this.asItem()) && 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;
}
return switch (state.get(CHECKERS)) {
default -> ONE_CHECKER;
case 2 -> TWO_CHECKER;
case 3 -> THREE_CHECKER;
case 4 -> FOUR_CHECKER;
};
}
public FluidState getFluidState(BlockState state) {
return (Boolean)state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{CHECKERS, WATERLOGGED});
builder.add(CHECKERS, WATERLOGGED);
}
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
@ -98,7 +89,7 @@ public class CheckerBlock extends Block implements Waterloggable {
}
static {
CHECKERS = IntProperty.of("checkers", 1, 4);;
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);

View file

@ -1,10 +1,8 @@
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;
@ -16,7 +14,7 @@ import net.minecraft.world.WorldView;
public class ChessBlock extends HorizontalFacingBlock {
private VoxelShape blockShape;
private final VoxelShape blockShape;
public ChessBlock(AbstractBlock.Settings settings, VoxelShape blockShape) {
super(settings.notSolid().nonOpaque().noBlockBreakParticles().pistonBehavior(PistonBehavior.DESTROY).strength(0.1f, 2f));

View file

@ -1,6 +1,5 @@
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;
@ -15,7 +14,6 @@ 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 {

View file

@ -131,7 +131,7 @@ public class HandrailBlock extends HorizontalFacingBlock implements BlockEntityP
SHAPE2 = new Shapes.HorizontalShape(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.HorizontalShape(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.HorizontalShape(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)));
ROTATION = IntProperty.of("rotate", 1, 3);;
ROTATION = IntProperty.of("rotate", 1, 3);
WATERLOGGED = Properties.WATERLOGGED;
}
}

View file

@ -121,7 +121,7 @@ public class LandMineBlock extends HorizontalFacingBlock implements Waterloggabl
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
return (BlockState)this.getDefaultState().with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
return this.getDefaultState().with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {

View file

@ -3,7 +3,6 @@ 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.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
@ -41,13 +40,13 @@ public class SirenBlock extends HorizontalFacingBlock implements Waterloggable {
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
if (!world.isClient) {
boolean bl = (Boolean)state.get(ON);
boolean bl = state.get(ON);
if (bl != world.isReceivingRedstonePower(pos)) {
if (bl) {
world.scheduleBlockTick(pos, this, 4);
} else {
world.playSound((PlayerEntity)null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SIREN_SOUND, SoundCategory.NEUTRAL, getSirenVolume(world, pos), 1f);
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SIREN_SOUND, SoundCategory.NEUTRAL, getSirenVolume(world, pos), 1f);
world.setBlockState(pos, state.cycle(ON), 2);
world.scheduleBlockTick(pos, this, 140);
}
}
@ -57,18 +56,13 @@ public class SirenBlock extends HorizontalFacingBlock implements Waterloggable {
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
Direction dir = state.get(FACING);
switch(dir) {
case NORTH:
return Block.createCuboidShape(3.5, 2, 11, 12.5, 15, 16);
case SOUTH:
return Block.createCuboidShape(3.5, 2, 0, 12.5, 15, 5);
case EAST:
return Block.createCuboidShape(0, 2, 3.5, 5, 15, 12.5);
case WEST:
return Block.createCuboidShape(11, 2, 3.5, 16, 15, 12.5);
default:
return VoxelShapes.fullCube();
}
return switch (dir) {
case NORTH -> Block.createCuboidShape(3.5, 2, 11, 12.5, 15, 16);
case SOUTH -> Block.createCuboidShape(3.5, 2, 0, 12.5, 15, 5);
case EAST -> Block.createCuboidShape(0, 2, 3.5, 5, 15, 12.5);
case WEST -> Block.createCuboidShape(11, 2, 3.5, 16, 15, 12.5);
default -> VoxelShapes.fullCube();
};
}
@Override
@ -80,17 +74,17 @@ public class SirenBlock extends HorizontalFacingBlock implements Waterloggable {
}
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
Direction direction = (Direction)state.get(FACING);
Direction direction = state.get(FACING);
BlockPos blockPos = pos.offset(direction.getOpposite());
BlockState blockState = world.getBlockState(blockPos);
return direction.getAxis().isHorizontal() && blockState.isSideSolidFullSquare(world, blockPos, direction);
}
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if ((Boolean)state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
if (state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, state.cycle(ON), 2);
} else {
world.playSound((PlayerEntity)null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SIREN_SOUND, SoundCategory.NEUTRAL, getSirenVolume(world, pos), 1f);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.SIREN_SOUND, SoundCategory.NEUTRAL, getSirenVolume(world, pos), 1f);
world.scheduleBlockTick(pos, this, 140);
}
}

View file

@ -40,15 +40,11 @@ public class StoveBlock extends BlockWithEntity {
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
Direction dir = state.get(FACING);
switch(dir) {
case NORTH, SOUTH:
return VoxelShapes.cuboid(0.0625f, 0.0f, 0.3125f, 0.9375f, 0.5625f, 0.6875f);
case EAST, WEST:
return VoxelShapes.cuboid(0.3125f, 0.0f, 0.0625f, 0.6875f, 0.5625f, 0.9375f);
default:
return VoxelShapes.fullCube();
}
return switch (state.get(FACING)) {
case NORTH, SOUTH -> VoxelShapes.cuboid(0.0625f, 0.0f, 0.3125f, 0.9375f, 0.5625f, 0.6875f);
case EAST, WEST -> VoxelShapes.cuboid(0.3125f, 0.0f, 0.0625f, 0.6875f, 0.5625f, 0.9375f);
default -> VoxelShapes.fullCube();
};
}
@Override
@ -57,11 +53,11 @@ public class StoveBlock extends BlockWithEntity {
}
public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(FACING, rotation.rotate((Direction)state.get(FACING)));
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(FACING)));
return state.rotate(mirror.getRotation(state.get(FACING)));
}
static {

View file

@ -4,7 +4,6 @@ import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.*;
import net.minecraft.block.enums.WallMountLocation;
import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.particle.DustParticleEffect;
import net.minecraft.sound.BlockSoundGroup;
@ -17,7 +16,6 @@ import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.Random;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
@ -26,6 +24,8 @@ import net.minecraft.world.event.GameEvent;
import su.a71.new_soviet.registration.NSE_Sounds;
import java.util.Objects;
public class SwitchBlock extends LeverBlock {
public static final BooleanProperty POWERED = Properties.POWERED;
protected static final VoxelShape NORTH_WALL_SHAPE = Block.createCuboidShape(5.5, 5.5, 15, 10.5, 10.5, 16);
@ -39,39 +39,29 @@ public class SwitchBlock extends LeverBlock {
public SwitchBlock(FabricBlockSettings fabricBlockSettings) {
super(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).notSolid().pistonBehavior(PistonBehavior.DESTROY).strength(1f, 2f).mapColor(MapColor.TERRACOTTA_WHITE).noCollision());
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(FACING, Direction.NORTH)).with(POWERED, false)).with(FACE, WallMountLocation.WALL));
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(POWERED, false).with(FACE, WallMountLocation.WALL));
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
switch ((WallMountLocation)state.get(FACE)) {
switch (state.get(FACE)) {
case FLOOR: {
switch (state.get(FACING).getAxis()) {
case X: {
return FLOOR_X_AXIS_SHAPE;
}
if (Objects.requireNonNull(state.get(FACING).getAxis()) == Direction.Axis.X) {
return FLOOR_X_AXIS_SHAPE;
}
return FLOOR_Z_AXIS_SHAPE;
}
case WALL: {
switch (state.get(FACING)) {
case EAST: {
return EAST_WALL_SHAPE;
}
case WEST: {
return WEST_WALL_SHAPE;
}
case SOUTH: {
return SOUTH_WALL_SHAPE;
}
}
return NORTH_WALL_SHAPE;
return switch (state.get(FACING)) {
case EAST -> EAST_WALL_SHAPE;
case WEST -> WEST_WALL_SHAPE;
case SOUTH -> SOUTH_WALL_SHAPE;
default -> NORTH_WALL_SHAPE;
};
}
}
switch (state.get(FACING).getAxis()) {
case X: {
return CEILING_X_AXIS_SHAPE;
}
if (Objects.requireNonNull(state.get(FACING).getAxis()) == Direction.Axis.X) {
return CEILING_X_AXIS_SHAPE;
}
return CEILING_Z_AXIS_SHAPE;
}
@ -79,13 +69,13 @@ public class SwitchBlock extends LeverBlock {
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) {
BlockState blockState = (BlockState)state.cycle(POWERED);
state.cycle(POWERED);
return ActionResult.SUCCESS;
}
BlockState blockState = this.togglePower(state, world, pos);
float f = blockState.get(POWERED) ? 1f : 0.9f;
world.playSound(null, pos, NSE_Sounds.SWITCH_PRESS, SoundCategory.BLOCKS, 0.6f, f);
world.emitGameEvent((Entity)player, blockState.get(POWERED) ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, pos);
world.emitGameEvent(player, blockState.get(POWERED) ? GameEvent.BLOCK_ACTIVATE : GameEvent.BLOCK_DEACTIVATE, pos);
return ActionResult.CONSUME;
}
@ -98,14 +88,6 @@ public class SwitchBlock extends LeverBlock {
world.addParticle(new DustParticleEffect(DustParticleEffect.RED, alpha), d, e, f, 0.0, 0.0, 0.0);
}
@Override
public void randomDisplayTick(BlockState state, World world, BlockPos pos, Random random) {
if (state.get(POWERED) && random.nextFloat() < 0.25f) {
//SwitchBlock.spawnParticles(state, world, pos, 0.5f);
}
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACE, FACING, POWERED);

View file

@ -43,8 +43,7 @@ public class GoldenTableLampBlock extends LampBlock {
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
Direction dir = state.get(FACING);
return switch (dir) {
return switch (state.get(FACING)) {
case NORTH -> SHAPE.north();
case SOUTH -> SHAPE.south();
case EAST -> SHAPE.east();
@ -65,11 +64,11 @@ public class GoldenTableLampBlock extends LampBlock {
}
public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(FACING, rotation.rotate((Direction)state.get(FACING)));
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(FACING)));
return state.rotate(mirror.getRotation(state.get(FACING)));
}
static {

View file

@ -11,7 +11,6 @@ import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
@ -65,7 +64,7 @@ public abstract class LampBlock extends Block implements Waterloggable {
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient) {
world.setBlockState(pos, (BlockState)state.cycle(INVERTED), 2);
world.setBlockState(pos, state.cycle(INVERTED), 2);
}
float f = state.get(ON) ? 1f : 0.9f;
world.playSound(null, pos, NSE_Sounds.SWITCH_PRESS, SoundCategory.BLOCKS, 0.6f, f);
@ -73,7 +72,7 @@ public abstract class LampBlock extends Block implements Waterloggable {
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{ON, WATERLOGGED, INVERTED});
builder.add(ON, WATERLOGGED, INVERTED);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
@ -94,20 +93,20 @@ public abstract class LampBlock extends Block implements Waterloggable {
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
if (!world.isClient) {
boolean bl = (Boolean)state.get(ON);
boolean bl = state.get(ON);
if (bl != world.isReceivingRedstonePower(pos)) {
if (bl) {
world.scheduleBlockTick(pos, this, 4);
} else {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
world.setBlockState(pos, state.cycle(ON), 2);
}
}
}
}
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if ((Boolean)state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
if (state.get(ON) && !world.isReceivingRedstonePower(pos)) {
world.setBlockState(pos, state.cycle(ON), 2);
}
}

View file

@ -9,7 +9,6 @@ import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
@ -24,7 +23,6 @@ import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.blocks.lamps.LampBlock;
import su.a71.new_soviet.registration.NSE_Items;
import su.a71.new_soviet.registration.NSE_Sounds;
@ -47,7 +45,7 @@ public class LightBulbLampBlock extends LampBlock {
@Nullable
public BlockState getPlacementState(ItemPlacementContext ctx) {
return (BlockState)this.getDefaultState()
return this.getDefaultState()
.with(BROKEN, false);
}
@ -57,12 +55,12 @@ public class LightBulbLampBlock extends LampBlock {
if (world.isReceivingRedstonePower(pos) == state.get(INVERTED) || (NewSoviet.RANDOM.nextBetween(1, 32) == 1)) {
if (!player.isCreative())
player.getInventory().getMainHandStack().decrement(1);
world.setBlockState(pos, (BlockState)state.with(BROKEN, false));
world.setBlockState(pos, state.with(BROKEN, false));
return ActionResult.SUCCESS;
} else {
player.getItemCooldownManager().set(NSE_Items.LIGHT_BULB, 10);
player.sendMessage(Text.translatable("block.new_soviet.light_bulb_block.energized").formatted(Formatting.YELLOW), true);
world.playSound((PlayerEntity)null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.ELECTRIC_HIT, SoundCategory.AMBIENT, 0.8f, 1f);
world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.ELECTRIC_HIT, SoundCategory.AMBIENT, 0.8f, 1f);
if (!player.isCreative()) {
player.damage(world.getDamageSources().lightningBolt(), NewSoviet.RANDOM.nextBetween(1, 4));
}
@ -79,14 +77,14 @@ public class LightBulbLampBlock extends LampBlock {
@Override
public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) {
if (!state.get(BROKEN)) {
world.playSound((PlayerEntity)null, hit.getBlockPos().getX(), hit.getBlockPos().getY(), hit.getBlockPos().getZ(), NSE_Sounds.LIGHT_BULB_BROKEN_SOUND, SoundCategory.NEUTRAL, 0.8f, 1f);
world.playSound(null, hit.getBlockPos().getX(), hit.getBlockPos().getY(), hit.getBlockPos().getZ(), NSE_Sounds.LIGHT_BULB_BROKEN_SOUND, SoundCategory.NEUTRAL, 0.8f, 1f);
}
world.setBlockState(hit.getBlockPos(), (BlockState)state.with(BROKEN, true), 2);
world.setBlockState(hit.getBlockPos(), state.with(BROKEN, true), 2);
super.onProjectileHit(world, state, hit, projectile);
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{ON, BROKEN, WATERLOGGED, INVERTED});
builder.add(ON, BROKEN, WATERLOGGED, INVERTED);
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {

View file

@ -10,7 +10,7 @@ import net.minecraft.world.WorldView;
import su.a71.new_soviet.blocks.lamps.LampBlock;
public class TableLampBlock extends LampBlock {
protected final VoxelShape SHAPE = getStandingShape();;
protected final VoxelShape SHAPE = getStandingShape();
public TableLampBlock(AbstractBlock.Settings settings) {
super(settings, true, null);

View file

@ -36,7 +36,7 @@ public class LampPostBaseBlock extends Block implements Waterloggable {
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
if (state.get(Properties.ATTACHED)) {
return SHAPE_ATTACHED;
};
}
return SHAPE_BASE;
}

View file

@ -9,7 +9,6 @@ import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
@ -37,8 +36,7 @@ public class LampPostLampBlock extends Block implements Waterloggable {
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
Direction dir = state.get(FACING);
return switch (dir) {
return switch (state.get(FACING)) {
case NORTH -> SHAPE.north();
case SOUTH -> SHAPE.south();
case EAST -> SHAPE.east();
@ -70,7 +68,7 @@ public class LampPostLampBlock extends Block implements Waterloggable {
}
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{WATERLOGGED, Properties.HORIZONTAL_FACING});
builder.add(WATERLOGGED, Properties.HORIZONTAL_FACING);
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
@ -90,11 +88,11 @@ public class LampPostLampBlock extends Block implements Waterloggable {
}
public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(FACING, rotation.rotate((Direction)state.get(FACING)));
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(FACING)));
return state.rotate(mirror.getRotation(state.get(FACING)));
}
static {

View file

@ -171,9 +171,9 @@ public class BlockLootTables extends FabricBlockLootTableProvider {
addDrop(NSE_Blocks.MEAT_EYE);
addDrop(NSE_Blocks.MEAT_TEETH);
addDrop(NSE_Blocks.CHISELED_BIRCH_DOOR, doorDrops(NSE_Blocks.CHISELED_BIRCH_DOOR));
addDrop(NSE_Blocks.CHISELED_MANGROVE_DOOR, doorDrops(NSE_Blocks.CHISELED_MANGROVE_DOOR));;
addDrop(NSE_Blocks.CHISELED_MANGROVE_DOOR, doorDrops(NSE_Blocks.CHISELED_MANGROVE_DOOR));
addDrop(NSE_Blocks.CHISELED_OAK_DOOR, doorDrops(NSE_Blocks.CHISELED_OAK_DOOR));
addDrop(NSE_Blocks.CHISELED_SPRUCE_DOOR, doorDrops(NSE_Blocks.CHISELED_SPRUCE_DOOR));;
addDrop(NSE_Blocks.CHISELED_SPRUCE_DOOR, doorDrops(NSE_Blocks.CHISELED_SPRUCE_DOOR));
addDrop(NSE_Blocks.BEIGE_WALLPAPER);
addDrop(NSE_Blocks.BROWN_WALLPAPER);
addDrop(NSE_Blocks.GREEN_WALLPAPER);

View file

@ -39,7 +39,7 @@ public class ModelGenerator extends FabricModelProvider {
public void registerCube(BlockStateModelGenerator blockStateModelGenerator, Block block, String texturePath) {
TextureMap textureMap = TextureMap.all(Registries.BLOCK.getId(block).withPath((path) -> "block/" + texturePath + "/" + path));
Identifier model_id = Models.CUBE_ALL.upload(block, textureMap, blockStateModelGenerator.modelCollector);
blockStateModelGenerator.blockStateCollector.accept(blockStateModelGenerator.createSingletonBlockState(block, model_id));
blockStateModelGenerator.blockStateCollector.accept(BlockStateModelGenerator.createSingletonBlockState(block, model_id));
}
public void registerSlabStairs(BlockStateModelGenerator blockStateModelGenerator, Block parent, StairsBlock stairs, SlabBlock slab, String texturePath) {

View file

@ -19,11 +19,9 @@ import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import org.jetbrains.annotations.Nullable;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.registration.NSE_Items;
import su.a71.new_soviet.registration.NSE_Sounds;
import java.util.List;
import java.util.Objects;
// FIXME: 26.08.2023 This whole class is making my head hurt, fix!!!
public class CigaretteItem extends Item {

View file

@ -34,13 +34,11 @@ public class DiceItem extends Item {
if (!world.isClient) {
StringBuilder output = new StringBuilder();
for (var i = 0; i < itemStack.getCount(); i++) {
world.playSound((PlayerEntity)null, user.getX(), user.getY(), user.getZ(), NSE_Sounds.DICE_SOUND, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
world.playSound(null, user.getX(), user.getY(), user.getZ(), NSE_Sounds.DICE_SOUND, SoundCategory.NEUTRAL, 0.5F, 0.4F / (world.getRandom().nextFloat() * 0.4F + 0.8F));
output.append(NewSoviet.RANDOM.nextBetween(1, this.getSides())).append(", ");
}
if (Config.INSTANCE.shouldAnnounceDice()) {
world.getPlayers().forEach(player -> {
player.sendMessage(Text.translatable(itemStack.getCount() == 1 ? "item.new_soviet.dice.thrown_announce" : "item.new_soviet.dice.thrown_multiple_announce", user.getDisplayName()).append(" " + output.subSequence(0, output.length() - 2)), false);
});
world.getPlayers().forEach(player -> player.sendMessage(Text.translatable(itemStack.getCount() == 1 ? "item.new_soviet.dice.thrown_announce" : "item.new_soviet.dice.thrown_multiple_announce", user.getDisplayName()).append(" " + output.subSequence(0, output.length() - 2)), false));
} else {
user.sendMessage(Text.translatable(itemStack.getCount() == 1 ? "item.new_soviet.dice.thrown" : "item.new_soviet.dice.thrown_multiple").append(" " + output.subSequence(0, output.length() - 2)), true);
}

View file

@ -19,6 +19,7 @@ import net.minecraft.util.Identifier;
import java.util.Optional;
import java.util.function.Supplier;
import su.a71.new_soviet.NewSoviet;
public class NSE_BaseRegistration {
@ -28,9 +29,7 @@ public class NSE_BaseRegistration {
if (tab == null) return; // Sanity check for hidden items
Optional<RegistryKey<ItemGroup>> key = Registries.ITEM_GROUP.getKey(tab);
key.ifPresent(itemGroupRegistryKey -> ItemGroupEvents.modifyEntriesEvent(itemGroupRegistryKey).register(content -> {
content.add(supplier.get());
}));
key.ifPresent(itemGroupRegistryKey -> ItemGroupEvents.modifyEntriesEvent(itemGroupRegistryKey).register(content -> content.add(supplier.get())));
}
public static void registerBlock(String name, Supplier<? extends Block> supplier, ItemGroup tab) {
@ -44,6 +43,8 @@ public class NSE_BaseRegistration {
return Registry.register(Registries.SOUND_EVENT, id, SoundEvent.of(id));
}
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T extends BlockEntityType> T registerBlockEntity(String name, FabricBlockEntityTypeBuilder.Factory<? extends BlockEntity> factory, net.minecraft.block.Block... blocks) {
return (T) Registry.register(
Registries.BLOCK_ENTITY_TYPE,

View file

@ -19,13 +19,13 @@ public enum NSE_ToolMaterials implements ToolMaterial
private final int enchantability;
private final Lazy<Ingredient> repairIngredient;
private NSE_ToolMaterials(int miningLevel, int itemDurability, float miningSpeed, float attackDamage, int enchantability, Supplier<Ingredient> repairIngredient) {
NSE_ToolMaterials(int miningLevel, int itemDurability, float miningSpeed, float attackDamage, int enchantability, Supplier<Ingredient> repairIngredient) {
this.miningLevel = miningLevel;
this.itemDurability = itemDurability;
this.miningSpeed = miningSpeed;
this.attackDamage = attackDamage;
this.enchantability = enchantability;
this.repairIngredient = new Lazy<Ingredient>(repairIngredient);
this.repairIngredient = new Lazy<>(repairIngredient);
}
@Override

View file

@ -96,7 +96,7 @@ public class Shapes {
}
public VoxelShape west() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (VoxelShape o : ShapesListW) {
shape = VoxelShapes.union(shape, o);
}
@ -104,7 +104,7 @@ public class Shapes {
}
public VoxelShape south() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (VoxelShape shapesList : ShapesListS) {
shape = VoxelShapes.union(shape, shapesList);
}
@ -112,7 +112,7 @@ public class Shapes {
}
public VoxelShape east() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (VoxelShape o : ShapesListE) {
shape = VoxelShapes.union(shape, o);
}
@ -148,7 +148,7 @@ public class Shapes {
}
public VoxelShape west() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (VoxelShape o : ShapesListW) {
shape = VoxelShapes.union(shape, o);
}
@ -156,7 +156,7 @@ public class Shapes {
}
public VoxelShape south() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (VoxelShape shapesList : ShapesListS) {
shape = VoxelShapes.union(shape, shapesList);
}
@ -164,7 +164,7 @@ public class Shapes {
}
public VoxelShape east() {
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);;
VoxelShape shape = Block.createCuboidShape(0, 0,0,0,0,0);
for (VoxelShape o : ShapesListE) {
shape = VoxelShapes.union(shape, o);
}