Skip to content

Commit

Permalink
♻️ Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CallMeEchoCodes committed Sep 3, 2024
1 parent 128b9a4 commit cfbcf7f
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 230 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ public ParticleTextureSheet getType() {
public void tick() {
super.tick();

if (this.age % 5 == 0 && this.random.nextInt(5) == 0) {
lightTicks -= this.random.nextBetween(10, 15);
} else {
lightTicks += 1;
}
if (this.age % 5 == 0 && this.random.nextInt(5) == 0) lightTicks -= this.random.nextBetween(10, 15);
else lightTicks += 1;

lightTicks = MathHelper.clamp(lightTicks, 0, 15);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,22 @@ protected int getBlockLight(FireflyEntity entity, BlockPos pos) {
}

private void renderVertex(VertexConsumer vertexConsumer, MatrixStack.Entry entry, float x, float y, float u, float v, FireflyEntity entity, int light) {
int color = ColorHelper.Argb.lerp(MathHelper.clampedLerp(0.0F, 15.0F, (1.0F - entity.getLightTicks() / 10.0F)) / 15.0F, 0xFF92CF40, 0xFF30352F);

float red = ColorHelper.Argb.getRed(color);
float green = ColorHelper.Argb.getGreen(color);
float blue = ColorHelper.Argb.getBlue(color);
float red;
float green;
float blue;

if (entity.hasCustomName() && "jeb_".equals(entity.getName().getString())) {
red = MathHelper.sin(entity.age * 0.1F) * 128.0F + 128.0F;
green = MathHelper.sin(entity.age * 0.1F + (float) Math.toRadians(120.0F)) * 128.0F + 128.0F;
blue = MathHelper.sin(entity.age * 0.1F + (float) Math.toRadians(240.0F)) * 128.0F + 128.0F;
} else {
int color = ColorHelper.Argb.lerp(MathHelper.clampedLerp(0.0F, 15.0F, (1.0F - entity.getLightTicks() / 10.0F)) / 15.0F, 0xFF92CF40, 0xFF30352F);

red = ColorHelper.Argb.getRed(color);
green = ColorHelper.Argb.getGreen(color);
blue = ColorHelper.Argb.getBlue(color);
}

vertexConsumer.vertex(entry, x - 0.5F, y - 0.25F, 0.0F)
.color(red / 255.0F, green / 255.0F, blue / 255.0F, 1.0F)
.texture(u, v)
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/dev/spiritstudios/hollow/Hollow.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void onInitialize() {
"call",
"melody",
"bass"
).forEach((name) -> {
).forEach(name -> {
for (int i = 0; i < 10; i++) {
Identifier id = Identifier.of(MODID, "horn.%s.%d".formatted(name, i));
Registry.register(
Expand All @@ -50,7 +50,6 @@ public void onInitialize() {
}
});


FabricDefaultAttributeRegistry.register(HollowEntityTypeRegistrar.FIREFLY, FireflyEntity.createFireflyAttributes());

HollowBiomeModifications.init();
Expand Down
35 changes: 18 additions & 17 deletions src/main/java/dev/spiritstudios/hollow/block/JarBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

public class JarBlock extends BlockWithEntity {
public static final MapCodec<JarBlock> CODEC = createCodec(JarBlock::new);

public JarBlock(AbstractBlock.Settings settings) {
super(settings);
}
public static final VoxelShape SHAPE = VoxelShapes.union(
createCuboidShape(5.5, 12, 5.5, 10.5, 15, 10.5),
createCuboidShape(3.5, 0, 3.5, 12.5, 14, 4.5),
Expand All @@ -35,8 +29,14 @@ public JarBlock(AbstractBlock.Settings settings) {
createCuboidShape(4.5, 0, 4.5, 11.5, 1, 11.5)
);

public JarBlock(AbstractBlock.Settings settings) {
super(settings);
}

@Override
public BlockRenderType getRenderType(BlockState state) { return BlockRenderType.MODEL; }
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}

@Nullable
@Override
Expand All @@ -54,22 +54,23 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) return ItemActionResult.SUCCESS;

JarBlockEntity blockEntity = (JarBlockEntity)world.getBlockEntity(pos);
Objects.requireNonNull(blockEntity).use(world, pos, player, hand);
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof JarBlockEntity jarBlockEntity) jarBlockEntity.use(world, pos, player, hand);
return ItemActionResult.CONSUME;
}

@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof JarBlockEntity) {
ItemScatterer.spawn(world, pos, (JarBlockEntity)blockEntity);
}
super.onStateReplaced(state, world, pos, newState, moved);
}
if (state.getBlock() == newState.getBlock()) return;

BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof JarBlockEntity jarBlockEntity) ItemScatterer.spawn(world, pos, jarBlockEntity);

super.onStateReplaced(state, world, pos, newState, moved);
}

@Override
protected MapCodec<? extends BlockWithEntity> getCodec() { return CODEC; }
protected MapCodec<? extends BlockWithEntity> getCodec() {
return CODEC;
}
}
18 changes: 5 additions & 13 deletions src/main/java/dev/spiritstudios/hollow/block/RootVinesBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ public BlockState getPlacementState(ItemPlacementContext ctx) {
if (blockState != null) {
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
return blockState.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
} else {
return null;
}
} else return null;
}

@Override
Expand All @@ -56,17 +54,11 @@ public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
public BlockState getStateForNeighborUpdate(
BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos
) {
if (direction == Direction.DOWN && neighborState.getBlock() == this) {
return state.with(UP, true);
}

if (direction == Direction.UP && !this.canPlaceAt(state, world, pos)) {
return Blocks.AIR.getDefaultState();
} else {
if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
if (direction == Direction.DOWN && neighborState.getBlock() == this) return state.with(UP, true);

if (direction == Direction.UP && !this.canPlaceAt(state, world, pos)) return Blocks.AIR.getDefaultState();
else {
if (state.get(WATERLOGGED)) world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
}
Expand Down
71 changes: 40 additions & 31 deletions src/main/java/dev/spiritstudios/hollow/block/StoneChestBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ public class StoneChestBlock extends BlockWithEntity implements Waterloggable {
public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED;

public static final MapCodec<StoneChestBlock> CODEC = createCodec(StoneChestBlock::new);

public static final VoxelShape SHAPE_SINGLE = VoxelShapes.union(
createCuboidShape(1, 1, 1, 15, 16, 15),
createCuboidShape(0, 0, 0, 16, 1, 16)
);

public static final VoxelShape SHAPE_LEFT_NORTH = VoxelShapes.union(
createCuboidShape(1, 1, 1, 16, 16, 15),
createCuboidShape(0, 0, 0, 16, 1, 16)
);
public static final VoxelShape SHAPE_LEFT_EAST = VoxelShapeHelper.rotateHorizontal(Direction.EAST, Direction.NORTH, SHAPE_LEFT_NORTH);
public static final VoxelShape SHAPE_LEFT_SOUTH = VoxelShapeHelper.rotateHorizontal(Direction.SOUTH, Direction.NORTH, SHAPE_LEFT_NORTH);
public static final VoxelShape SHAPE_LEFT_WEST = VoxelShapeHelper.rotateHorizontal(Direction.WEST, Direction.NORTH, SHAPE_LEFT_NORTH);

public static final VoxelShape SHAPE_RIGHT_NORTH = VoxelShapes.union(
createCuboidShape(0, 1, 1, 15, 16, 15),
createCuboidShape(0, 0, 0, 16, 1, 16)
);
public static final VoxelShape SHAPE_RIGHT_EAST = VoxelShapeHelper.rotateHorizontal(Direction.EAST, Direction.NORTH, SHAPE_RIGHT_NORTH);
public static final VoxelShape SHAPE_RIGHT_SOUTH = VoxelShapeHelper.rotateHorizontal(Direction.SOUTH, Direction.NORTH, SHAPE_RIGHT_NORTH);
public static final VoxelShape SHAPE_RIGHT_WEST = VoxelShapeHelper.rotateHorizontal(Direction.WEST, Direction.NORTH, SHAPE_RIGHT_NORTH);

public StoneChestBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState()
Expand All @@ -66,30 +66,37 @@ public StoneChestBlock(Settings settings) {
);
}

public static Direction getFacing(BlockState state) {
Direction direction = state.get(FACING);
return state.get(CHEST_TYPE) == ChestType.LEFT ? direction.rotateYClockwise() : direction.rotateYCounterclockwise();
}

@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
ChestType chestType = ChestType.SINGLE;
Direction direction = ctx.getHorizontalPlayerFacing().getOpposite();
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
boolean bl = ctx.shouldCancelInteraction();
Direction direction2 = ctx.getSide();
if (direction2.getAxis().isHorizontal() && bl) {
Direction direction3 = this.getNeighborChestDirection(ctx, direction2.getOpposite());
if (direction3 != null && direction3.getAxis() != direction2.getAxis()) {
direction = direction3;
chestType = direction3.rotateYCounterclockwise() == direction2.getOpposite() ? ChestType.RIGHT : ChestType.LEFT;
boolean shouldCancel = ctx.shouldCancelInteraction();
Direction side = ctx.getSide();

if (side.getAxis().isHorizontal() && shouldCancel) {
Direction neighborDirection = this.getNeighborChestDirection(ctx, side.getOpposite());
if (neighborDirection != null && neighborDirection.getAxis() != side.getAxis()) {
direction = neighborDirection;
chestType = neighborDirection.rotateYCounterclockwise() == side.getOpposite() ? ChestType.RIGHT : ChestType.LEFT;
}
}

if (chestType == ChestType.SINGLE && !bl) {
if (direction == this.getNeighborChestDirection(ctx, direction.rotateYClockwise())) {
if (chestType == ChestType.SINGLE && !shouldCancel)
if (direction == this.getNeighborChestDirection(ctx, direction.rotateYClockwise()))
chestType = ChestType.LEFT;
} else if (direction == this.getNeighborChestDirection(ctx, direction.rotateYCounterclockwise())) {
else if (direction == this.getNeighborChestDirection(ctx, direction.rotateYCounterclockwise()))
chestType = ChestType.RIGHT;
}
}

return this.getDefaultState().with(FACING, direction).with(CHEST_TYPE, chestType).with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);

return this.getDefaultState()
.with(FACING, direction)
.with(CHEST_TYPE, chestType)
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
}

@Nullable
Expand All @@ -99,8 +106,9 @@ private Direction getNeighborChestDirection(ItemPlacementContext ctx, Direction
}

@Override
public BlockRenderType getRenderType(BlockState state) { return BlockRenderType.MODEL; }

public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}

@Nullable
@Override
Expand All @@ -114,10 +122,14 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)
}

@Override
public BlockState rotate(BlockState state, BlockRotation rotation) { return state.with(FACING, rotation.rotate(state.get(FACING))); }
public BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}

@Override
public BlockState mirror(BlockState state, BlockMirror mirror) { return state.rotate(mirror.getRotation(state.get(FACING))); }
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}

@Override
public BlockState getStateForNeighborUpdate(
Expand All @@ -126,7 +138,7 @@ public BlockState getStateForNeighborUpdate(
if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}

if (direction == Direction.UP && neighborState.isAir()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof StoneChestBlockEntity stoneChest) {
Expand All @@ -149,16 +161,11 @@ && getFacing(neighborState) == direction.getOpposite()) {
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}

public static Direction getFacing(BlockState state) {
Direction direction = state.get(FACING);
return state.get(CHEST_TYPE) == ChestType.LEFT ? direction.rotateYClockwise() : direction.rotateYCounterclockwise();
}

@Override
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) return ItemActionResult.SUCCESS;

StoneChestBlockEntity blockEntity = (StoneChestBlockEntity)world.getBlockEntity(pos);
StoneChestBlockEntity blockEntity = (StoneChestBlockEntity) world.getBlockEntity(pos);
return Objects.requireNonNull(blockEntity).use(player, hand, hit.getSide());
}

Expand Down Expand Up @@ -197,12 +204,14 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt
if (state.getBlock() != newState.getBlock()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof StoneChestBlockEntity) {
ItemScatterer.spawn(world, pos, (StoneChestBlockEntity)blockEntity);
ItemScatterer.spawn(world, pos, (StoneChestBlockEntity) blockEntity);
}
super.onStateReplaced(state, world, pos, newState, moved);
}
}

@Override
protected MapCodec<? extends BlockWithEntity> getCodec() { return CODEC; }
protected MapCodec<? extends BlockWithEntity> getCodec() {
return CODEC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,27 @@ public BlockState getPlacementState(ItemPlacementContext ctx) {
ChestType chestType = ChestType.SINGLE;
Direction direction = ctx.getHorizontalPlayerFacing().getOpposite();
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
boolean bl = ctx.shouldCancelInteraction();
Direction direction2 = ctx.getSide();
if (direction2.getAxis().isHorizontal() && bl) {
Direction direction3 = this.getNeighborChestDirection(ctx, direction2.getOpposite());
if (direction3 != null && direction3.getAxis() != direction2.getAxis()) {
direction = direction3;
chestType = direction3.rotateYCounterclockwise() == direction2.getOpposite() ? ChestType.RIGHT : ChestType.LEFT;
boolean shouldCancel = ctx.shouldCancelInteraction();
Direction side = ctx.getSide();

if (side.getAxis().isHorizontal() && shouldCancel) {
Direction neighborDirection = this.getNeighborChestDirection(ctx, side.getOpposite());
if (neighborDirection != null && neighborDirection.getAxis() != side.getAxis()) {
direction = neighborDirection;
chestType = neighborDirection.rotateYCounterclockwise() == side.getOpposite() ? ChestType.RIGHT : ChestType.LEFT;
}
}

if (chestType == ChestType.SINGLE && !bl) {
if (direction == this.getNeighborChestDirection(ctx, direction.rotateYClockwise())) {
if (chestType == ChestType.SINGLE && !shouldCancel)
if (direction == this.getNeighborChestDirection(ctx, direction.rotateYClockwise()))
chestType = ChestType.LEFT;
} else if (direction == this.getNeighborChestDirection(ctx, direction.rotateYCounterclockwise())) {
else if (direction == this.getNeighborChestDirection(ctx, direction.rotateYCounterclockwise()))
chestType = ChestType.RIGHT;
}
}

return this.getDefaultState().with(FACING, direction).with(CHEST_TYPE, chestType).with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
return this.getDefaultState()
.with(FACING, direction)
.with(CHEST_TYPE, chestType)
.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
}

@Nullable
Expand All @@ -94,9 +96,7 @@ private Direction getNeighborChestDirection(ItemPlacementContext ctx, Direction
public BlockState getStateForNeighborUpdate(
BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos
) {
if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
if (state.get(WATERLOGGED)) world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));

if (neighborState.isOf(this) && direction.getAxis().isHorizontal()) {
ChestType chestType = neighborState.get(CHEST_TYPE);
Expand All @@ -106,9 +106,7 @@ public BlockState getStateForNeighborUpdate(
&& getFacing(neighborState) == direction.getOpposite()) {
return state.with(CHEST_TYPE, chestType.getOpposite());
}
} else if (getFacing(state) == direction) {
return state.with(CHEST_TYPE, ChestType.SINGLE);
}
} else if (getFacing(state) == direction) return state.with(CHEST_TYPE, ChestType.SINGLE);

return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
Expand Down
Loading

0 comments on commit cfbcf7f

Please sign in to comment.