diff --git a/src/client/java/dev/spiritstudios/hollow/particle/FireflyJarParticle.java b/src/client/java/dev/spiritstudios/hollow/particle/FireflyJarParticle.java index db3371f..f63b65e 100644 --- a/src/client/java/dev/spiritstudios/hollow/particle/FireflyJarParticle.java +++ b/src/client/java/dev/spiritstudios/hollow/particle/FireflyJarParticle.java @@ -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); diff --git a/src/client/java/dev/spiritstudios/hollow/render/entity/FireflyEntityRenderer.java b/src/client/java/dev/spiritstudios/hollow/render/entity/FireflyEntityRenderer.java index 33060eb..940a9e0 100644 --- a/src/client/java/dev/spiritstudios/hollow/render/entity/FireflyEntityRenderer.java +++ b/src/client/java/dev/spiritstudios/hollow/render/entity/FireflyEntityRenderer.java @@ -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) diff --git a/src/main/java/dev/spiritstudios/hollow/Hollow.java b/src/main/java/dev/spiritstudios/hollow/Hollow.java index 240551f..206502e 100644 --- a/src/main/java/dev/spiritstudios/hollow/Hollow.java +++ b/src/main/java/dev/spiritstudios/hollow/Hollow.java @@ -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( @@ -50,7 +50,6 @@ public void onInitialize() { } }); - FabricDefaultAttributeRegistry.register(HollowEntityTypeRegistrar.FIREFLY, FireflyEntity.createFireflyAttributes()); HollowBiomeModifications.init(); diff --git a/src/main/java/dev/spiritstudios/hollow/block/JarBlock.java b/src/main/java/dev/spiritstudios/hollow/block/JarBlock.java index 539b70d..896323c 100644 --- a/src/main/java/dev/spiritstudios/hollow/block/JarBlock.java +++ b/src/main/java/dev/spiritstudios/hollow/block/JarBlock.java @@ -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 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), @@ -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 @@ -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 getCodec() { return CODEC; } + protected MapCodec getCodec() { + return CODEC; + } } diff --git a/src/main/java/dev/spiritstudios/hollow/block/RootVinesBlock.java b/src/main/java/dev/spiritstudios/hollow/block/RootVinesBlock.java index b779be7..79ad8c1 100644 --- a/src/main/java/dev/spiritstudios/hollow/block/RootVinesBlock.java +++ b/src/main/java/dev/spiritstudios/hollow/block/RootVinesBlock.java @@ -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 @@ -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); } } diff --git a/src/main/java/dev/spiritstudios/hollow/block/StoneChestBlock.java b/src/main/java/dev/spiritstudios/hollow/block/StoneChestBlock.java index 0ca8c9a..28ab126 100644 --- a/src/main/java/dev/spiritstudios/hollow/block/StoneChestBlock.java +++ b/src/main/java/dev/spiritstudios/hollow/block/StoneChestBlock.java @@ -35,12 +35,12 @@ public class StoneChestBlock extends BlockWithEntity implements Waterloggable { public static final BooleanProperty WATERLOGGED = Properties.WATERLOGGED; public static final MapCodec 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) @@ -48,7 +48,7 @@ public class StoneChestBlock extends BlockWithEntity implements Waterloggable { 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) @@ -56,7 +56,7 @@ public class StoneChestBlock extends BlockWithEntity implements Waterloggable { 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() @@ -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 @@ -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 @@ -114,10 +122,14 @@ protected void appendProperties(StateManager.Builder 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( @@ -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) { @@ -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()); } @@ -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 getCodec() { return CODEC; } + protected MapCodec getCodec() { + return CODEC; + } } diff --git a/src/main/java/dev/spiritstudios/hollow/block/StoneChestLidBlock.java b/src/main/java/dev/spiritstudios/hollow/block/StoneChestLidBlock.java index b94b6cb..b7c36a4 100644 --- a/src/main/java/dev/spiritstudios/hollow/block/StoneChestLidBlock.java +++ b/src/main/java/dev/spiritstudios/hollow/block/StoneChestLidBlock.java @@ -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 @@ -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); @@ -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); } diff --git a/src/main/java/dev/spiritstudios/hollow/block/entity/EchoingPotBlockEntity.java b/src/main/java/dev/spiritstudios/hollow/block/entity/EchoingPotBlockEntity.java index 002b8ad..90a5206 100644 --- a/src/main/java/dev/spiritstudios/hollow/block/entity/EchoingPotBlockEntity.java +++ b/src/main/java/dev/spiritstudios/hollow/block/entity/EchoingPotBlockEntity.java @@ -28,16 +28,6 @@ import java.util.Optional; public class EchoingPotBlockEntity extends BlockEntity { -// private static final ParticleSystem PARTICLE_SYSTEM = new ParticleSystem( -// new Vec3d(0.007F, 0.07F, 0.007F), -// new Vec3d(0.5, 1, 0.5), -// new Vec3d(0.1, 0, 0.1), -// 2, -// 1, -// true, -// ParticleTypes.SCULK_SOUL -// ); - public int activeTime = 0; public EchoingPotBlockEntity(BlockPos pos, BlockState state) { @@ -45,46 +35,46 @@ public EchoingPotBlockEntity(BlockPos pos, BlockState state) { } public static void tick(World world, BlockPos pos, BlockState state, EchoingPotBlockEntity blockEntity) { - if (blockEntity.activeTime > 0) { - if (!world.isClient) { - blockEntity.activeTime--; - blockEntity.markDirty(); - world.updateListeners(pos, state, state, Block.NOTIFY_LISTENERS); - - List wardens = world.getEntitiesByClass( - WardenEntity.class, - Box.from(pos.toCenterPos()).expand(16), - warden -> true + if (blockEntity.activeTime <= 0) return; + + if (!world.isClient) { + blockEntity.activeTime--; + blockEntity.markDirty(); + world.updateListeners(pos, state, state, Block.NOTIFY_LISTENERS); + + List wardens = world.getEntitiesByClass( + WardenEntity.class, + Box.from(pos.toCenterPos()).expand(16), + warden -> true + ); + + wardens.forEach(warden -> { + WardenAngerManager angerManager = warden.getAngerManager(); + + Optional target = angerManager.getPrimeSuspect(); + if (target.isEmpty()) return; + + angerManager.removeSuspect(target.get()); + }); + } else { + Random random = world.getRandom(); + for (int i = 0; i < 2; ++i) { + float x = 2.0F * random.nextFloat() - 1.0F; + float y = 2.0F * random.nextFloat() - 1.0F; + float z = 2.0F * random.nextFloat() - 1.0F; + world.addParticle( + ParticleTypes.SCULK_SOUL, + (double) pos.getX() + 0.5 + (x * 0.25), + (double) pos.getY() + 1, + (double) pos.getZ() + 0.5 + (z * 0.25), + (x * 0.0075F), + (y * 0.075F), + (z * 0.0075F) ); - - wardens.forEach(warden -> { - WardenAngerManager angerManager = warden.getAngerManager(); - - Optional target = angerManager.getPrimeSuspect(); - if (target.isEmpty()) return; - - angerManager.removeSuspect(target.get()); - }); - } else { - Random random = world.getRandom(); - for (int i = 0; i < 2; ++i) { - float x = 2.0F * random.nextFloat() - 1.0F; - float y = 2.0F * random.nextFloat() - 1.0F; - float z = 2.0F * random.nextFloat() - 1.0F; - world.addParticle( - ParticleTypes.SCULK_SOUL, - (double) pos.getX() + 0.5 + (x * 0.25), - (double) pos.getY() + 1, - (double) pos.getZ() + 0.5 + (z * 0.25), - (x * 0.0075F), - (y * 0.075F), - (z * 0.0075F) - ); - } - - if (world.random.nextInt(5) == 0) - world.playSoundAtBlockCenter(pos, SoundEvents.PARTICLE_SOUL_ESCAPE.value(), SoundCategory.BLOCKS, 0.5F, 1.0F, false); } + + if (world.random.nextInt(5) == 0) + world.playSoundAtBlockCenter(pos, SoundEvents.PARTICLE_SOUL_ESCAPE.value(), SoundCategory.BLOCKS, 0.5F, 1.0F, false); } } diff --git a/src/main/java/dev/spiritstudios/hollow/block/entity/JarBlockEntity.java b/src/main/java/dev/spiritstudios/hollow/block/entity/JarBlockEntity.java index 4fee04a..d69e15a 100644 --- a/src/main/java/dev/spiritstudios/hollow/block/entity/JarBlockEntity.java +++ b/src/main/java/dev/spiritstudios/hollow/block/entity/JarBlockEntity.java @@ -14,31 +14,25 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import java.util.stream.IntStream; + public class JarBlockEntity extends InventoryBlockEntity { public JarBlockEntity(BlockPos pos, BlockState state) { super(HollowBlockEntityRegistrar.JAR_BLOCK_ENTITY, pos, state, 17); } - + public void use(World world, BlockPos pos, PlayerEntity player, Hand hand) { - if (!inventory.isEmpty() && !world.isClient) { - world.playSound( - null, - pos, - SoundEvents.ENTITY_ITEM_PICKUP, - SoundCategory.PLAYERS, - 0.2f, - ((player.getRandom().nextFloat() - player.getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F - ); - } + if (!inventory.isEmpty() && !world.isClient) world.playSound( + null, + pos, + SoundEvents.ENTITY_ITEM_PICKUP, + SoundCategory.PLAYERS, + 0.2f, + ((player.getRandom().nextFloat() - player.getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F + ); if (player.getStackInHand(hand).isEmpty()) { - int slot = -1; - for (int i = inventory.size() - 1; i >= 0; i--) { - if (!inventory.get(i).isEmpty()) { - slot = i; - break; - } - } + int slot = IntStream.iterate(inventory.size() - 1, i -> i >= 0, i -> i - 1).filter(i -> !inventory.get(i).isEmpty()).findFirst().orElse(-1); if (slot == -1) return; ItemStack stack = inventory.get(slot); @@ -48,7 +42,7 @@ public void use(World world, BlockPos pos, PlayerEntity player, Hand hand) { this.markDirty(); return; } - + int slot = -1; for (int i = 0; i < inventory.size(); i++) { if (inventory.get(i).isEmpty()) { @@ -56,7 +50,6 @@ public void use(World world, BlockPos pos, PlayerEntity player, Hand hand) { break; } } - if (slot == -1) return; setStack(slot, player.getStackInHand(hand)); diff --git a/src/main/java/dev/spiritstudios/hollow/block/entity/StoneChestBlockEntity.java b/src/main/java/dev/spiritstudios/hollow/block/entity/StoneChestBlockEntity.java index 564d02e..ec73960 100644 --- a/src/main/java/dev/spiritstudios/hollow/block/entity/StoneChestBlockEntity.java +++ b/src/main/java/dev/spiritstudios/hollow/block/entity/StoneChestBlockEntity.java @@ -15,6 +15,7 @@ import net.minecraft.loot.context.LootContextTypes; import net.minecraft.nbt.NbtCompound; import net.minecraft.registry.RegistryWrapper; +import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.Hand; @@ -24,63 +25,51 @@ import net.minecraft.util.math.Vec3d; import org.jetbrains.annotations.Nullable; -public class StoneChestBlockEntity extends LootableInventoryBlockEntity { -// private static final ParticleSystem PARTICLE_SYSTEM = new ParticleSystem( -// new Vec3d(0.025F, 0.05F, 0.025F), -// new Vec3d(0.5, 1, 0.5), -// new Vec3d(0, 0, 0), -// 15, -// 1, -// true, -// ParticleTypes.LARGE_SMOKE -// ); +import java.util.stream.IntStream; +public class StoneChestBlockEntity extends LootableInventoryBlockEntity { public StoneChestBlockEntity(BlockPos pos, BlockState state) { super(HollowBlockEntityRegistrar.STONE_CHEST_BLOCK_ENTITY, pos, state, 27); } - public void checkLootInteraction(@Nullable PlayerEntity player, boolean randomSeed) { if (world == null) return; - if (this.lootTable != null && this.world.getServer() != null) { - LootTable lootTable = this.world.getServer().getReloadableRegistries().getLootTable(this.lootTable); - if (player instanceof ServerPlayerEntity) { - Criteria.PLAYER_GENERATES_CONTAINER_LOOT.trigger((ServerPlayerEntity)player, this.lootTable); - } - this.lootTable = null; - LootContextParameterSet.Builder builder = new LootContextParameterSet.Builder((ServerWorld)this.world) - .add(LootContextParameters.ORIGIN, Vec3d.ofCenter(this.pos)); - if (player != null) { - builder.luck(player.getLuck()).add(LootContextParameters.THIS_ENTITY, player); - } + MinecraftServer server = world.getServer(); + if (this.lootTable == null || server == null) return; - lootTable.supplyInventory( - this, - builder.build(LootContextTypes.CHEST), - randomSeed ? world.getRandom().nextLong() : this.lootTableSeed - ); - } + LootTable lootTable = server.getReloadableRegistries().getLootTable(this.lootTable); + if (player instanceof ServerPlayerEntity serverPlayer) + Criteria.PLAYER_GENERATES_CONTAINER_LOOT.trigger(serverPlayer, this.lootTable); + this.lootTable = null; + + LootContextParameterSet.Builder builder = new LootContextParameterSet.Builder((ServerWorld)this.world) + .add(LootContextParameters.ORIGIN, Vec3d.ofCenter(this.pos)); + + if (player != null) builder.luck(player.getLuck()).add(LootContextParameters.THIS_ENTITY, player); + + lootTable.supplyInventory( + this, + builder.build(LootContextTypes.CHEST), + randomSeed ? world.getRandom().nextLong() : this.lootTableSeed + ); } public void aboveBroken() { if (world == null) return; checkLootInteraction(null, true); Vec3d centerPos = pos.toCenterPos(); - for (ItemStack stack : inventory) { - if (!stack.isEmpty()) { - ItemEntity itemEntity = new ItemEntity(world, centerPos.getX(), centerPos.getY() + 0.5, centerPos.getZ(), stack); - world.spawnEntity(itemEntity); - } - } + inventory.stream() + .filter(stack -> !stack.isEmpty()) + .map(stack -> new ItemEntity(world, centerPos.getX(), centerPos.getY() + 0.5, centerPos.getZ(), stack)) + .forEach(itemEntity -> world.spawnEntity(itemEntity)); inventory.clear(); -// PARTICLE_SYSTEM.tick(world, pos); } public ItemActionResult use(PlayerEntity player, Hand hand, Direction side) { - if (player.getStackInHand(hand).isEmpty()) return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION; - if (player.getStackInHand(hand).isOf(HollowBlockRegistrar.STONE_CHEST_LID.asItem()) && side.equals(Direction.UP)) return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION; + if (player.getStackInHand(hand).isEmpty() || player.getStackInHand(hand).isOf(HollowBlockRegistrar.STONE_CHEST_LID.asItem()) && side.equals(Direction.UP)) + return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION; int slot = -1; diff --git a/src/main/java/dev/spiritstudios/hollow/entity/FireflyEntity.java b/src/main/java/dev/spiritstudios/hollow/entity/FireflyEntity.java index 84fcc62..80be258 100644 --- a/src/main/java/dev/spiritstudios/hollow/entity/FireflyEntity.java +++ b/src/main/java/dev/spiritstudios/hollow/entity/FireflyEntity.java @@ -34,10 +34,10 @@ public class FireflyEntity extends PathAwareEntity implements Flutterer { private static final TrackedData LIGHT_TICKS = DataTracker.registerData(FireflyEntity.class, TrackedDataHandlerRegistry.INTEGER); - + public FireflyEntity(EntityType entityType, World world) { super(entityType, world); - + this.moveControl = new FlightMoveControl(this, 360, true); this.setPathfindingPenalty(PathNodeType.DANGER_FIRE, -1.0F); this.setPathfindingPenalty(PathNodeType.WATER, -1.0F); @@ -48,9 +48,9 @@ public FireflyEntity(EntityType entityType, World wor public boolean canBeLeashed() { return false; } private void setLightTicks(int ticks) { - this.dataTracker.set(LIGHT_TICKS, ticks); + this.dataTracker.set(LIGHT_TICKS, MathHelper.clamp(ticks, 0, 15)); } - + public int getLightTicks() { return this.dataTracker.get(LIGHT_TICKS); } @@ -74,7 +74,7 @@ public boolean isValidPosition(BlockPos pos) { return !this.world.getBlockState(pos.down()).isAir(); } }; - + birdNavigation.setCanPathThroughDoors(false); birdNavigation.setCanSwim(false); birdNavigation.setCanEnterOpenDoors(true); @@ -91,22 +91,11 @@ public static DefaultAttributeContainer.Builder createFireflyAttributes() { @Override public void tick() { super.tick(); - - if (getEntityWorld().isNight() || getEntityWorld().getLightLevel(this.getBlockPos()) < 5) { - if (this.age % 5 == 0 && this.random.nextInt(5) == 0) { - this.setLightTicks(this.getLightTicks() - this.random.nextBetween(10, 15)); - } else { - this.setLightTicks(this.getLightTicks() + 1); - } - } else { - if (this.age % 5 == 0 && this.random.nextInt(5) == 0) { - this.setLightTicks(this.getLightTicks() + this.random.nextBetween(5, 10)); - } else { - this.setLightTicks(this.getLightTicks() - 1); - } - } - this.setLightTicks(MathHelper.clamp(getLightTicks(), 0, 15)); + if (getEntityWorld().isNight() || getEntityWorld().getLightLevel(this.getBlockPos()) < 5) + this.setLightTicks(this.age % 5 == 0 && this.random.nextInt(5) == 0 ? this.getLightTicks() - this.random.nextBetween(10, 15) : this.getLightTicks() + 1); + else + this.setLightTicks(this.age % 5 == 0 && this.random.nextInt(5) == 0 ? this.getLightTicks() + this.random.nextBetween(5, 10) : this.getLightTicks() - 1); } @Override @@ -143,7 +132,7 @@ protected float getSoundVolume() { @Override protected void pushAway(Entity entity) { - + } public static boolean canSpawn(EntityType entityType, ServerWorldAccess worldAccess, SpawnReason spawnReason, BlockPos pos, Random random) { @@ -167,7 +156,7 @@ protected void tickCramming() { } static class FlyRandomlyGoal extends Goal { private final FireflyEntity firefly; - + public FlyRandomlyGoal(FireflyEntity firefly) { this.firefly = firefly; this.setControls(EnumSet.of(Goal.Control.MOVE)); @@ -178,10 +167,10 @@ protected Vec3d getWanderTarget() { Vec3d rotation = firefly.getRotationVec(0.0F); Vec3d target = AboveGroundTargeting.find(firefly, 8, 7, rotation.x, rotation.z, MathHelper.HALF_PI, 3, 1); if (target != null) return target; - + return NoPenaltySolidTargeting.find(firefly, 8, 4, -2, rotation.x, rotation.z, MathHelper.HALF_PI); } - + @Override public boolean canStart() { return firefly.navigation.isIdle() && firefly.random.nextInt(10) == 0; diff --git a/src/main/java/dev/spiritstudios/hollow/worldgen/FallenTreeFeature.java b/src/main/java/dev/spiritstudios/hollow/worldgen/FallenTreeFeature.java index b1e3c3e..6d45ae6 100644 --- a/src/main/java/dev/spiritstudios/hollow/worldgen/FallenTreeFeature.java +++ b/src/main/java/dev/spiritstudios/hollow/worldgen/FallenTreeFeature.java @@ -35,14 +35,6 @@ public boolean generate(FeatureContext context) { origin = world.getTopPosition(Heightmap.Type.MOTION_BLOCKING, origin); -// boolean canPlace = true; -// for (int i = 0; i < size; i++) { -// BlockPos pos = origin.offset(axis, i); -// canPlace = canPlace && (world.isAir(pos) || world.getBlockState(pos).isOf(Blocks.SHORT_GRASS)) && world.getBlockState(pos.down()).isSolidBlock(world, pos.down()); -// } -// -// if (!canPlace) return false; - for (int i = 0; i < size; i++) { BlockPos pos = origin.offset(axis, i); if ((!world.isAir(pos) && !world.getBlockState(pos).isReplaceable()) || !world.getBlockState(pos.down()).isSolidBlock(world, pos.down()))