drill optimization

This commit is contained in:
Jörg Henke 2022-02-13 21:22:27 +01:00
parent 507fdc1ba5
commit 1b282bd49c
11 changed files with 80 additions and 13 deletions

View File

@ -9,7 +9,7 @@
loader_version=0.12.12
# Mod Properties
mod_version = 1.18.1.4
mod_version = 1.18.1.5
maven_group = de.jottyfan.minecraft
archives_base_name = quickiefabric

View File

@ -1,5 +1,8 @@
package de.jottyfan.minecraft.quickiefabric.blockentity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
@ -21,7 +24,39 @@ public class DrillBlockDownEntity extends DrillBlockEntity {
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockDownEntity) {
DrillBlockDownEntity dbe = (DrillBlockDownEntity) be;
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, pos.down());
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, generateBlockPos(pos));
}
}
public static final List<BlockPos> generateBlockPos(BlockPos pos) {
List<BlockPos> list = new ArrayList<>();
Integer tracesMod = pos.getY() % 8;
tracesMod = tracesMod < 0 ? tracesMod * -1 : tracesMod; // lower that 0 makes it negative
if (tracesMod != 0) {
list.add(pos.north());
}
if (tracesMod != 1) {
list.add(pos.north().west());
}
if (tracesMod != 2) {
list.add(pos.west());
}
if (tracesMod != 3) {
list.add(pos.south().west());
}
if (tracesMod != 4) {
list.add(pos.south());
}
if (tracesMod != 5) {
list.add(pos.south().east());
}
if (tracesMod != 6) {
list.add(pos.east());
}
if (tracesMod != 7) {
list.add(pos.north().east());
}
list.add(pos.down()); // must be last position
return list;
}
}

View File

@ -1,5 +1,8 @@
package de.jottyfan.minecraft.quickiefabric.blockentity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
@ -21,7 +24,10 @@ public class DrillBlockEastEntity extends DrillBlockEntity {
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockEastEntity) {
DrillBlockEastEntity dbe = (DrillBlockEastEntity) be;
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, pos.east().down());
List<BlockPos> list = new ArrayList<>();
list.add(pos.east());
list.add(pos.east().down()); // must be last position
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
}

View File

@ -1,5 +1,7 @@
package de.jottyfan.minecraft.quickiefabric.blockentity;
import java.util.List;
import de.jottyfan.minecraft.quickiefabric.blocks.QuickieBlocks;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
@ -29,19 +31,25 @@ public abstract class DrillBlockEntity extends BlockEntity {
}
}
protected static final void drill(BlockPos pos, BlockPos to, World world) {
protected static final Boolean drill(BlockPos pos, List<BlockPos> toList, World world) {
Boolean lastSuccess = false;
for (BlockPos to : toList) {
if (!world.getBlockState(to).isOf(Blocks.BEDROCK) && !world.getBlockState(to).isOf(QuickieBlocks.DRILLSTOP)) {
world.breakBlock(to, true);
if (pos.down() != to) { // no need for the falling one
moveBlockWithEntity(pos, to, world);
lastSuccess = pos.down() != to; // no need for the falling one
} else {
lastSuccess = false; // in case that the last one is a bedrock or a drillstop
}
}
return lastSuccess;
}
public static void tick(World world, BlockPos pos, BlockState state, DrillBlockEntity be, Integer maxDrillStep, BlockPos drillPosition) {
public static void tick(World world, BlockPos pos, BlockState state, DrillBlockEntity be, Integer maxDrillStep, List<BlockPos> drillPosition) {
if (be.getDrillstep() < 1) {
be.setDrillstep(maxDrillStep);
drill(pos, drillPosition, world);
if (drill(pos, drillPosition, world)) {
moveBlockWithEntity(pos, drillPosition.get(drillPosition.size() - 1), world);
}
} else {
be.doDrillstep();
}

View File

@ -1,5 +1,8 @@
package de.jottyfan.minecraft.quickiefabric.blockentity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
@ -21,7 +24,10 @@ public class DrillBlockNorthEntity extends DrillBlockEntity {
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockNorthEntity) {
DrillBlockNorthEntity dbe = (DrillBlockNorthEntity) be;
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, pos.north().down());
List<BlockPos> list = new ArrayList<>();
list.add(pos.north());
list.add(pos.north().down()); // must be last position
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
}

View File

@ -1,5 +1,8 @@
package de.jottyfan.minecraft.quickiefabric.blockentity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
@ -20,7 +23,10 @@ public class DrillBlockSouthEntity extends DrillBlockEntity {
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockSouthEntity) {
DrillBlockSouthEntity dbe = (DrillBlockSouthEntity) be;
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, pos.south().down());
List<BlockPos> list = new ArrayList<>();
list.add(pos.south());
list.add(pos.south().down()); // must be last position
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
}

View File

@ -1,5 +1,8 @@
package de.jottyfan.minecraft.quickiefabric.blockentity;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.util.math.BlockPos;
@ -21,7 +24,10 @@ public class DrillBlockWestEntity extends DrillBlockEntity {
public static void tick(World world, BlockPos pos, BlockState state, BlockEntity be) {
if (be instanceof DrillBlockWestEntity) {
DrillBlockWestEntity dbe = (DrillBlockWestEntity) be;
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, pos.west().down());
List<BlockPos> list = new ArrayList<>();
list.add(pos.west());
list.add(pos.west().down()); // must be last position
DrillBlockEntity.tick(world, pos, state, dbe, MAXDRILLSTEP, list);
}
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB