From 9667d2df51999847be257b96ef70248b68c4a6d1 Mon Sep 17 00:00:00 2001 From: RecursivePineapple Date: Mon, 20 Jan 2025 01:54:23 -0500 Subject: [PATCH] Minor moving fixes (#25) --- .../common/building/PendingMove.java | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/recursive_pineapple/matter_manipulator/common/building/PendingMove.java b/src/main/java/com/recursive_pineapple/matter_manipulator/common/building/PendingMove.java index 1972666..efb5912 100644 --- a/src/main/java/com/recursive_pineapple/matter_manipulator/common/building/PendingMove.java +++ b/src/main/java/com/recursive_pineapple/matter_manipulator/common/building/PendingMove.java @@ -59,6 +59,8 @@ public void tryPlaceBlocks(ItemStack stack, EntityPlayer player) { int ops = 0; var iter = moves.listIterator(moves.size()); + ArrayList> shuffled = new ArrayList<>(); + // try to move `placeSpeed` blocks from here to there while (ops < tier.placeSpeed && iter.hasPrevious()) { Pair move = iter.previous(); @@ -68,6 +70,11 @@ public void tryPlaceBlocks(ItemStack stack, EntityPlayer player) { // if either block is protected, ignore them completely and print a warning if (!isEditable(world, s.x, s.y, s.z) || !isEditable(world, d.x, d.y, d.z)) { + MMUtils.sendErrorToPlayer( + player, + String.format("Could not move protected block X=%d, Y=%d, Z=%d: %s", s.x, s.y, s.z, source.getDisplayName()) + ); + iter.remove(); continue; } @@ -81,8 +88,9 @@ public void tryPlaceBlocks(ItemStack stack, EntityPlayer player) { if (source.getBlock().getBlockHardness(world, s.x, s.y, s.z) < 0) { MMUtils.sendErrorToPlayer( player, - String.format("Could not move invulnerable source block X=%d, Y=%d, Z=%d", s.x, s.y, s.z) + String.format("Could not move invulnerable source block X=%d, Y=%d, Z=%d: %s", s.x, s.y, s.z, source.getDisplayName()) ); + iter.remove(); continue; } @@ -100,8 +108,9 @@ public void tryPlaceBlocks(ItemStack stack, EntityPlayer player) { if (!canPlace) { MMUtils.sendErrorToPlayer( player, - String.format("Destination was blocked for source block X=%d, Y=%d, Z=%d", d.x, d.y, d.z) + String.format("Destination was blocked for source block X=%d, Y=%d, Z=%d: %s", d.x, d.y, d.z, source.getDisplayName()) ); + iter.remove(); continue; } @@ -117,6 +126,8 @@ public void tryPlaceBlocks(ItemStack stack, EntityPlayer player) { // if we can't move the source block then skip it for now if (!source.getBlock().canPlaceBlockAt(world, d.x, d.y, d.z)) { + shuffled.add(move); + iter.remove(); continue; } @@ -140,6 +151,8 @@ public void tryPlaceBlocks(ItemStack stack, EntityPlayer player) { ops++; } + moves.addAll(shuffled); + playSounds(); actuallyGivePlayerStuff(); @@ -226,13 +239,13 @@ public static boolean swapBlocks(World world, Location s, BlockSpec spec1, Locat Block blockS = worldS.getBlock(sx, sy, sz); Block blockD = worldD.getBlock(dx, dy, dz); - if (blockS.equals(Blocks.air) && blockD.equals(Blocks.air)) { return false; } + if (blockS.equals(Blocks.air) && blockD.equals(Blocks.air)) return false; int metaS = worldS.getBlockMetadata(sx, sy, sz); int metaD = worldD.getBlockMetadata(dx, dy, dz); if (Mods.BloodMagic.isModLoaded()) { - if (!allowTelepose(worldS, worldD, s, spec1, d, spec2)) { return false; } + if (!allowTelepose(worldS, worldD, s, spec1, d, spec2)) return false; } // CLEAR TILES @@ -280,19 +293,24 @@ public static boolean swapBlocks(World world, Location s, BlockSpec spec1, Locat newTileEntityF.zCoord = sz; if (Mods.GregTech.isModLoaded()) { - if (newTileEntityF instanceof IGregTechTileEntity igte && igte.getMetaTileEntity() instanceof BaseMetaTileEntity bmte) { - bmte.setCableUpdateDelay(100); - } - - if (newTileEntityF instanceof IIC2Enet enet) { - enet.doEnetUpdate(); - } + updateGTIfNeeded(newTileEntityF); } } return true; } + @Optional(Names.GREG_TECH) + private static void updateGTIfNeeded(TileEntity te) { + if (te instanceof IGregTechTileEntity igte && igte.getMetaTileEntity() instanceof BaseMetaTileEntity bmte) { + bmte.setCableUpdateDelay(100); + } + + if (te instanceof IIC2Enet enet) { + enet.doEnetUpdate(); + } + } + @Optional(Names.BLOOD_MAGIC) private static boolean allowTelepose(World worldI, World worldF, Location s, BlockSpec spec1, Location d, BlockSpec spec2) { TeleposeEvent evt = new TeleposeEvent(