Skip to content

Commit

Permalink
Minor moving fixes (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
RecursivePineapple authored Jan 20, 2025
1 parent 8c805ca commit 9667d2d
Showing 1 changed file with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public void tryPlaceBlocks(ItemStack stack, EntityPlayer player) {
int ops = 0;
var iter = moves.listIterator(moves.size());

ArrayList<Pair<Location, Location>> shuffled = new ArrayList<>();

// try to move `placeSpeed` blocks from here to there
while (ops < tier.placeSpeed && iter.hasPrevious()) {
Pair<Location, Location> move = iter.previous();
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -140,6 +151,8 @@ public void tryPlaceBlocks(ItemStack stack, EntityPlayer player) {
ops++;
}

moves.addAll(shuffled);

playSounds();
actuallyGivePlayerStuff();

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9667d2d

Please sign in to comment.