Skip to content

Commit

Permalink
Torches last ~30 minutes and rely on scheduled ticks instead of random
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed Aug 30, 2023
1 parent f34af88 commit a5b794c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +32,7 @@ public TimedTorchBlock(Settings settings) {

protected void appendProperties(StateManager.Builder<Block, BlockState> 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) {
Expand All @@ -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);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/cr24/primeval/item/FlintItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a5b794c

Please sign in to comment.