Skip to content

Commit

Permalink
Diagonal mining
Browse files Browse the repository at this point in the history
Config option to enable/disable Diagonal mining
  • Loading branch information
kyrptonaught committed Oct 1, 2019
1 parent c0ca002 commit 17a28ad
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 63 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_mappings=1.14.4+build.13
loader_version=0.6.2+build.166

# Mod Properties
mod_version=1.0.4
mod_version=1.0.5
maven_group = net.fabricmc
archives_base_name=diggusmaximus

Expand Down
87 changes: 26 additions & 61 deletions src/main/java/net/kyrptonaught/diggusmaximus/Excavate.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package net.kyrptonaught.diggusmaximus;

import net.kyrptonaught.diggusmaximus.config.ConfigOptions;
import net.minecraft.block.Block;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.stat.Stats;
import net.minecraft.util.CuboidBlockIterator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraft.world.World;

import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Set;
import java.util.stream.Collectors;

class Excavate {
private BlockPos startPos;
Expand All @@ -22,6 +21,10 @@ class Excavate {
private int mined = 1;
private ItemStack tool;
private World world;
private static final Set<BlockPos> cube = BlockPos.stream(-1, -1, -1, 1, 1, 1).map(BlockPos::toImmutable).collect(Collectors.toSet());
private final int maxMined = Math.min(DiggusMaximusMod.getOptions().maxMinedBlocks, 256);
private final double maxDistance = Math.min(DiggusMaximusMod.getOptions().maxMineDistance + 1, 16);
private Deque<BlockPos> points = new ArrayDeque<>();

Excavate(BlockPos pos, Block block, PlayerEntity player) {
this.startPos = pos;
Expand All @@ -31,68 +34,35 @@ class Excavate {
this.world = player.getEntityWorld();
}

private Deque<BlockPos> points = new ArrayDeque<>();

void startExcavate() {
points.add(startPos);
while (!points.isEmpty()) {
spiral(points.remove());
spread(points.remove());
}
if (DiggusMaximusMod.getOptions().playerExhaustion)
player.addExhaustion(0.005F * mined);
}

private void spiral(BlockPos pos) {
point(pos.north());
point(pos.east());
point(pos.south());
point(pos.west());
point(pos.up());
point(pos.down());
/* BlockPos.stream(-1,-1,-1,1,1,1).forEach(testPos ->{
if(isValidPos(testPos))
point(testPos);
});
*/
point(pos.add(1,0,0));
point(pos.add(0,0,1));
point(pos.add(-1,0,0));
point(pos.add(0,0,-1));
point(pos.add(0,1,0));
point(pos.add(0,-1,0));

private void spread(BlockPos pos) {
if (DiggusMaximusMod.getOptions().mineDiag) {
point(pos.add(1, 0, 1));
point(pos.add(1, 0, -1));
point(pos.add(-1, 0, 1));
point(pos.add(-1, 0, -1));

point(pos.add(1,1,0));
point(pos.add(-1,1,0));
point(pos.add(1,-1,0));
point(pos.add(-1,-1,0));

point(pos.add(0,1,1));
point(pos.add(0,1,-1));
point(pos.add(0,-1,1));
point(pos.add(0,-1,-1));

point(pos.add(1, 1, 1));
point(pos.add(1, -1, 1));
point(pos.add(-1, 1, 1));
point(pos.add(-1, -1, 1));

point(pos.add(1, 1, -1));
point(pos.add(1, -1, -1));
point(pos.add(-1, 1, -1));
point(pos.add(-1, -1, -1));
for (BlockPos dirPos : cube) {
if (isValidPos(dirPos))
point(pos.add(dirPos));
}
} else {
point(pos.north());
point(pos.east());
point(pos.south());
point(pos.west());
point(pos.up());
point(pos.down());
}
}
private boolean isValidPos(BlockPos pos){
if(DiggusMaximusMod.getOptions().mineDiag)
return true;
return Math.abs(pos.getX()) + Math.abs(pos.getY()) + Math.abs(pos.getZ()) == 1;
}

private boolean isValidPos(BlockPos pos) {
return (Math.abs(pos.getX()) + Math.abs(pos.getY()) + Math.abs(pos.getZ())) != 0;
}

private void point(BlockPos pos) {
if (player.getEntityWorld().getBlockState(pos).getBlock().equals(startBlock) && canMine(pos)) {
points.add(pos);
Expand All @@ -102,12 +72,10 @@ private void point(BlockPos pos) {
}

private void mine(BlockPos pos) {
// world.getLevelProperties().getScheduledEvents().addEvent(pos.toString(), world.getTime()+ 40, (var1, var2, var3) -> System.out.println("yooo" + var3));
if (DiggusMaximusMod.getOptions().toolDuribility)
tool.postMine(world, world.getBlockState(pos), pos, player);
player.incrementStat(Stats.MINED.getOrCreateStat(startBlock));
dropStacks(world, pos);
//startBlock.onBreak(world, pos, world.getBlockState(pos), player);
world.clearBlockState(pos, false);
startBlock.onBroken(world, pos, world.getBlockState(pos));
}
Expand All @@ -124,16 +92,13 @@ private void dropStacks(World world, BlockPos pos) {
startBlock.onStacksDropped(world.getBlockState(pos), world, pos, tool);
}

private int maxMined = Math.min(DiggusMaximusMod.getOptions().maxMinedBlocks, 256);

private boolean canMine(BlockPos pos) {
return mined < maxMined && isWithinDistance(pos) && toolHasDurability() && (player.isCreative() || player.isUsingEffectiveTool(player.world.getBlockState(pos)));
}

private double distance = Math.min(DiggusMaximusMod.getOptions().maxMineDistance + 1, 16);

private boolean isWithinDistance(BlockPos pos) {
return pos.isWithinDistance(startPos, distance);
return pos.isWithinDistance(startPos, maxDistance);
}

private boolean toolHasDurability() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public String getModId() {
category.addEntry(entryBuilder.startBooleanToggle("key.diggusmaximus.config.enabled", options.enabled).setSaveConsumer(val -> options.enabled = val).setDefaultValue(true).build());

category.addEntry(new KeyBindEntry("key.diggusmaximus.config.hotkey", options.keybinding, key -> options.keybinding = key));
category.addEntry(entryBuilder.startBooleanToggle("key.diggusmaximus.config.minediag", options.mineDiag).setSaveConsumer(val -> options.mineDiag = val).setDefaultValue(true).build());
category.addEntry(entryBuilder.startIntField("key.diggusmaximus.config.maxmine", options.maxMinedBlocks).setSaveConsumer(val -> options.maxMinedBlocks = val).setDefaultValue(40).build());
category.addEntry(entryBuilder.startIntField("key.diggusmaximus.config.maxdistance", options.maxMineDistance).setSaveConsumer(val -> options.maxMineDistance = val).setDefaultValue(10).build());

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/diggusmaximus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"key.diggusmaximus.config.category": "Options",
"key.diggusmaximus.config.enabled": "Enabled",
"key.diggusmaximus.config.hotkey": "Keybind",
"key.diggusmaximus.config.minediag": "Mine blocks diagonally",
"key.diggusmaximus.config.maxmine": "Max mined blocks",
"key.diggusmaximus.config.maxdistance": "Max distance",
"key.diggusmaximus.config.autopickup": "Auto Pickup",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "diggusmaximus",
"version": "1.0.4",
"version": "1.0.5",
"name": "Diggus Maximus",
"description": "Mine ores more better!",
"authors": [
Expand Down

0 comments on commit 17a28ad

Please sign in to comment.