Skip to content

Commit

Permalink
slightly improved ore mining rig active setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Feb 5, 2025
1 parent 4385512 commit 335807f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public abstract class BlockEntityDrillingRigBase<T extends BlockEntityDrillingRi
protected BlockPos miningPos;
protected int euPerTick;
protected int cycle = 160;
protected int inactiveTicks = 0;
public BlockEntityDrillingRigBase(Machine<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
miningPos = new int3(pos, this.getFacing(state)).back(1).immutable().below();
Expand All @@ -60,6 +61,11 @@ public void onFirstTick() {
@Override
public void serverTick(Level level, BlockPos pos, BlockState state) {
super.serverTick(level, pos, state);
if (inactiveTicks > 2){
if (getMachineState() == MachineState.ACTIVE){
setMachineState(MachineState.IDLE);
}
}
boolean wasStopped = false;
if (stopped && level.getGameTime() % 200 == 0){
wasStopped = true;
Expand Down Expand Up @@ -90,21 +96,17 @@ public void serverTick(Level level, BlockPos pos, BlockState state) {
if (miningPos.getY() + 1 < this.getBlockPos().getY()){
level.setBlock(miningPos.above(), MINING_PIPE.defaultBlockState(), 3);
}
if (getMachineState() == MachineState.IDLE) setMachineState(MachineState.ACTIVE);
setActive();
energyHandler.ifPresent(e -> e.extractEu(euPerTick, false));
} else if (getMachineState() == MachineState.ACTIVE){
setMachineState(MachineState.IDLE);
}
} else if (getMachineState() == MachineState.ACTIVE){
setMachineState(MachineState.IDLE);
}
} else inactiveTicks++;
} else inactiveTicks++;
} else if (!foundBottom){
if (level.getGameTime() % 20 != 0) return;
MineResult breakResult = mineBelowBlock(level, miningPos, true, getMiningPickaxe());
if (breakResult == BlockEntityDrillingRigBase.MineResult.PIPE_BROKEN){
return;
}
if (getMachineState() == MachineState.IDLE) setMachineState(MachineState.ACTIVE);
setActive();
energyHandler.ifPresent(e -> e.extractEu(euPerTick, false));
if (breakResult == BlockEntityDrillingRigBase.MineResult.FOUND_BOTTOM || breakResult == MineResult.FOUND_BOTTOM_MINING_PIPE){
foundBottom = true;
Expand All @@ -130,6 +132,13 @@ public void serverTick(Level level, BlockPos pos, BlockState state) {
}
}

protected void setActive(){
inactiveTicks = 0;
if (getMachineState() == MachineState.IDLE) {
setMachineState(MachineState.ACTIVE);
}
}

protected abstract MineResult mineBelowBlock(Level level, BlockPos pos, boolean dropBlock, ItemStack item);

protected abstract void run(Level level, BlockPos pos, BlockState state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ public void run(Level level, BlockPos pos, BlockState state) {
return;
}
}
if (getMachineState() != MachineState.ACTIVE){
setMachineState(MachineState.ACTIVE);
}
setActive();
energyHandler.ifPresent(e -> e.extractEu(euPerTick, false));
if (++progress == cycle){
progress = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected void run(Level level, BlockPos pos, BlockState state) {
if (getMachineState() == MachineState.ACTIVE) setMachineState(MachineState.IDLE);
return;
}
if (getMachineState() == MachineState.IDLE) setMachineState(MachineState.ACTIVE);
setActive();
runningState = RunningState.MINING;
energyHandler.ifPresent(e -> e.extractEu(euPerTick, false));
if (progress < cycle) {
Expand All @@ -153,10 +153,11 @@ protected void run(Level level, BlockPos pos, BlockState state) {
progress = 0;
currentDrops = null;
} else {
if (getMachineState() == MachineState.ACTIVE) setMachineState(MachineState.IDLE);
inactiveTicks++;
BlockState blockState = level.getBlockState(miningPos);
if (blockState.getBlock() == Blocks.BEDROCK || blockState.getBlock() == Blocks.VOID_AIR){
runningState = RunningState.FINISHED;
if (getMachineState() == MachineState.ACTIVE) setMachineState(MachineState.IDLE);
return;
}
foundBottom = false;
Expand Down

0 comments on commit 335807f

Please sign in to comment.