From fe5626ea2f012f3a370227d5ca77c2bd936f7911 Mon Sep 17 00:00:00 2001 From: blockparole <> Date: Thu, 14 Nov 2019 12:22:09 +0100 Subject: [PATCH 1/6] ignore non EntityLivingBase on valid place check --- .../impl/module/combat/ObsidianReplaceModule.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java index 13a5670..299217d 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java @@ -11,10 +11,15 @@ import me.rigamortis.seppuku.api.util.MathUtil; import me.rigamortis.seppuku.api.util.RenderUtil; import me.rigamortis.seppuku.api.value.OptionalValue; import me.rigamortis.seppuku.impl.module.player.FreeCamModule; -import net.minecraft.block.*; +import net.minecraft.block.Block; +import net.minecraft.block.BlockAir; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.BlockObsidian; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemBlock; @@ -344,8 +349,13 @@ public final class ObsidianReplaceModule extends Module { final Block east = mc.world.getBlockState(pos.add(1, 0, 0)).getBlock(); final Block west = mc.world.getBlockState(pos.add(-1, 0, 0)).getBlock(); + for (Entity entity : mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos))) { + if (entity instanceof EntityLivingBase) { + return false; + } + } + return (block instanceof BlockAir) - && mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos)).isEmpty() && ((up != null && up != Blocks.AIR && !(up instanceof BlockLiquid)) || (down != null && down != Blocks.AIR && !(down instanceof BlockLiquid)) || (north != null && north != Blocks.AIR && !(north instanceof BlockLiquid)) From 351afe7532fec237838446dd64b315c3dfece03d Mon Sep 17 00:00:00 2001 From: blockparole <> Date: Thu, 14 Nov 2019 12:26:31 +0100 Subject: [PATCH 2/6] remove duplicate instanceof checks --- .../module/combat/ObsidianReplaceModule.java | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java index 299217d..efbf172 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java @@ -79,12 +79,9 @@ public final class ObsidianReplaceModule extends Module { if (pos != null) { final double dist = mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ()); if (dist <= 5.0f) { - final Block block = mc.world.getBlockState(pos).getBlock(); - if (block instanceof BlockAir || block instanceof BlockLiquid) { - if (this.valid(pos)) { - this.place(pos); - valid = true; - } + if (this.valid(pos)) { + this.place(pos); + valid = true; } } } @@ -117,11 +114,8 @@ public final class ObsidianReplaceModule extends Module { if (pos != null) { final double dist = mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ()); if (dist <= 5.0f) { - final Block block = mc.world.getBlockState(pos).getBlock(); - if (block instanceof BlockAir || block instanceof BlockLiquid) { - if (this.valid(pos)) { - return true; - } + if (this.valid(pos)) { + return true; } } } @@ -342,12 +336,9 @@ public final class ObsidianReplaceModule extends Module { private boolean valid(BlockPos pos) { final Block block = mc.world.getBlockState(pos).getBlock(); - final Block up = mc.world.getBlockState(pos.add(0, 1, 0)).getBlock(); - final Block down = mc.world.getBlockState(pos.add(0, -1, 0)).getBlock(); - final Block north = mc.world.getBlockState(pos.add(0, 0, -1)).getBlock(); - final Block south = mc.world.getBlockState(pos.add(0, 0, 1)).getBlock(); - final Block east = mc.world.getBlockState(pos.add(1, 0, 0)).getBlock(); - final Block west = mc.world.getBlockState(pos.add(-1, 0, 0)).getBlock(); + if (!(block instanceof BlockAir) && !(block instanceof BlockLiquid)) { + return false; + } for (Entity entity : mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos))) { if (entity instanceof EntityLivingBase) { @@ -355,8 +346,14 @@ public final class ObsidianReplaceModule extends Module { } } - return (block instanceof BlockAir) - && ((up != null && up != Blocks.AIR && !(up instanceof BlockLiquid)) + final Block up = mc.world.getBlockState(pos.add(0, 1, 0)).getBlock(); + final Block down = mc.world.getBlockState(pos.add(0, -1, 0)).getBlock(); + final Block north = mc.world.getBlockState(pos.add(0, 0, -1)).getBlock(); + final Block south = mc.world.getBlockState(pos.add(0, 0, 1)).getBlock(); + final Block east = mc.world.getBlockState(pos.add(1, 0, 0)).getBlock(); + final Block west = mc.world.getBlockState(pos.add(-1, 0, 0)).getBlock(); + + return ((up != null && up != Blocks.AIR && !(up instanceof BlockLiquid)) || (down != null && down != Blocks.AIR && !(down instanceof BlockLiquid)) || (north != null && north != Blocks.AIR && !(north instanceof BlockLiquid)) || (south != null && south != Blocks.AIR && !(south instanceof BlockLiquid)) From 567bd469586eb92e90e6dd61c79a9c50a6af0917 Mon Sep 17 00:00:00 2001 From: blockparole <> Date: Thu, 14 Nov 2019 13:17:33 +0100 Subject: [PATCH 3/6] invert check to filter EntityItem only --- .../seppuku/impl/module/combat/ObsidianReplaceModule.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java index efbf172..5f7ed1d 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java @@ -19,7 +19,7 @@ import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemBlock; @@ -341,7 +341,7 @@ public final class ObsidianReplaceModule extends Module { } for (Entity entity : mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos))) { - if (entity instanceof EntityLivingBase) { + if (!(entity instanceof EntityItem)) { return false; } } From b415bf36843c93aac4e3d87b402e8d1366a4c4c6 Mon Sep 17 00:00:00 2001 From: blockparole <48992448+blockparole@users.noreply.github.com> Date: Thu, 14 Nov 2019 13:39:49 +0100 Subject: [PATCH 4/6] filter EntityXPOrb too --- .../seppuku/impl/module/combat/ObsidianReplaceModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java index 5f7ed1d..a60de5c 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java @@ -341,7 +341,7 @@ public final class ObsidianReplaceModule extends Module { } for (Entity entity : mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos))) { - if (!(entity instanceof EntityItem)) { + if (!(entity instanceof EntityItem) && !(entity instanceof EntityXPOrb)) { return false; } } From 967b41004c8135069d09da8b067b7800910aef38 Mon Sep 17 00:00:00 2001 From: blockparole <> Date: Thu, 14 Nov 2019 14:10:44 +0100 Subject: [PATCH 5/6] oops --- .../seppuku/impl/module/combat/ObsidianReplaceModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java index a60de5c..32d4e8f 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java @@ -20,6 +20,7 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemBlock; From 595d455f181f058f0391d3829f94dcc22287da1e Mon Sep 17 00:00:00 2001 From: Daniel E Date: Sun, 17 Nov 2019 15:27:52 -0700 Subject: [PATCH 6/6] Adjusted how entities are found in ObsidianReplace The world allows us to specify a predicate to filter out entities in the function, we should be using it! --- .../module/combat/ObsidianReplaceModule.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java index 32d4e8f..61175c7 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/ObsidianReplaceModule.java @@ -341,11 +341,11 @@ public final class ObsidianReplaceModule extends Module { return false; } - for (Entity entity : mc.world.getEntitiesWithinAABBExcludingEntity(null, new AxisAlignedBB(pos))) { - if (!(entity instanceof EntityItem) && !(entity instanceof EntityXPOrb)) { - return false; - } - } + final List invalidEntities = mc.world.getEntitiesInAABBexcluding(null, + new AxisAlignedBB(pos), entity -> !(entity instanceof EntityItem) && + !(entity instanceof EntityXPOrb)); + if (!invalidEntities.isEmpty()) + return false; final Block up = mc.world.getBlockState(pos.add(0, 1, 0)).getBlock(); final Block down = mc.world.getBlockState(pos.add(0, -1, 0)).getBlock(); @@ -354,12 +354,11 @@ public final class ObsidianReplaceModule extends Module { final Block east = mc.world.getBlockState(pos.add(1, 0, 0)).getBlock(); final Block west = mc.world.getBlockState(pos.add(-1, 0, 0)).getBlock(); - return ((up != null && up != Blocks.AIR && !(up instanceof BlockLiquid)) - || (down != null && down != Blocks.AIR && !(down instanceof BlockLiquid)) - || (north != null && north != Blocks.AIR && !(north instanceof BlockLiquid)) - || (south != null && south != Blocks.AIR && !(south instanceof BlockLiquid)) - || (east != null && east != Blocks.AIR && !(east instanceof BlockLiquid)) - || (west != null && west != Blocks.AIR && !(west instanceof BlockLiquid))); + return ((up != Blocks.AIR && !(up instanceof BlockLiquid)) + || (down != Blocks.AIR && !(down instanceof BlockLiquid)) + || (north != Blocks.AIR && !(north instanceof BlockLiquid)) + || (south != Blocks.AIR && !(south instanceof BlockLiquid)) + || (east != Blocks.AIR && !(east instanceof BlockLiquid)) + || (west != Blocks.AIR && !(west instanceof BlockLiquid))); } - }