From a5b794c8d721511744cf3232332ad113f41d9a26 Mon Sep 17 00:00:00 2001 From: Maxx <53229958+MBatt1@users.noreply.github.com> Date: Tue, 29 Aug 2023 21:49:40 -0500 Subject: [PATCH] Torches last ~30 minutes and rely on scheduled ticks instead of random --- .../block/functional/TimedTorchBlock.java | 24 +++++++++++-------- .../net/cr24/primeval/item/FlintItem.java | 2 -- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/cr24/primeval/block/functional/TimedTorchBlock.java b/src/main/java/net/cr24/primeval/block/functional/TimedTorchBlock.java index f6c94b4..d0dacff 100644 --- a/src/main/java/net/cr24/primeval/block/functional/TimedTorchBlock.java +++ b/src/main/java/net/cr24/primeval/block/functional/TimedTorchBlock.java @@ -18,6 +18,8 @@ import net.minecraft.world.WorldAccess; public class TimedTorchBlock extends Block { + static final int TICKS = 6000; + public static final IntProperty BURNOUT_STAGE; public static final DirectionProperty DIRECTION; protected static final VoxelShape[] SHAPES; @@ -30,7 +32,7 @@ public TimedTorchBlock(Settings settings) { protected void appendProperties(StateManager.Builder builder) { super.appendProperties(builder); - builder.add(new Property[]{BURNOUT_STAGE, DIRECTION}); + builder.add(BURNOUT_STAGE, DIRECTION); } public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { @@ -45,17 +47,19 @@ public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos po return null; } - public boolean hasRandomTicks(BlockState state) { - int burnout = state.get(BURNOUT_STAGE); - return (burnout != 0 && burnout != 5); + public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) { + int stage = state.get(BURNOUT_STAGE); + if (stage == 1) { + world.createAndScheduleBlockTick(pos, this, TICKS*stage); + } } - public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { - super.randomTick(state, world, pos, random); - double burnout = (double)state.get(BURNOUT_STAGE) * 0.1; - int randomChance = (int) ((1.0+burnout) * 7); - if (random.nextInt(randomChance) == 0) { - world.setBlockState(pos, state.with(BURNOUT_STAGE, state.get(BURNOUT_STAGE)+1)); + @Override + public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { + int stage = state.get(BURNOUT_STAGE); + world.setBlockState(pos, state.with(BURNOUT_STAGE, Math.min(stage+1, 5))); + if (stage < 4) { + world.createAndScheduleBlockTick(pos, PrimevalBlocks.CRUDE_TORCH, TICKS*stage); } } diff --git a/src/main/java/net/cr24/primeval/item/FlintItem.java b/src/main/java/net/cr24/primeval/item/FlintItem.java index 5658d2a..4d493fa 100644 --- a/src/main/java/net/cr24/primeval/item/FlintItem.java +++ b/src/main/java/net/cr24/primeval/item/FlintItem.java @@ -21,8 +21,6 @@ public ActionResult useOnBlock(ItemUsageContext context) { World world = context.getWorld(); Block targetBlock = world.getBlockState(pos).getBlock(); if (hoeables.containsKey(targetBlock) && world.getBlockState(pos.up()).isAir()) { - String side = world.isClient() ? "Client " : "Server "; - System.out.println(side + context.getStack().getCount()); world.setBlockState(pos, hoeables.get(targetBlock).getDefaultState()); world.playSound(context.getPlayer(), pos, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0f, 1.0f); if (!world.isClient() && context.getWorld().getRandom().nextFloat() < 0.2) {