From 363619148f14f20a390ac6c16d1a45c7c2386ad9 Mon Sep 17 00:00:00 2001 From: astoria Date: Mon, 3 Apr 2023 11:54:10 -0500 Subject: [PATCH] Prep for delete --- .../afloydwiremod/api/AbstractWireTile.java | 6 ++++++ .../api/AbstractWireTileEntity.java | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java index 476aa66..c5b8f44 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTile.java @@ -54,4 +54,10 @@ public abstract class AbstractWireTile extends BlockContainer { //Singleplayer ((IEntityPlayer)player).displayGuiSettings(chip); } + @Override + public void onBlockRemoval(World world, int x, int y, int z) { + AbstractWireTileEntity tile = (AbstractWireTileEntity) world.getBlockTileEntity(x, y, z); + tile.prepForDelete(); + super.onBlockRemoval(world, x, y, z); + } } diff --git a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java index 47fdf32..93b0620 100644 --- a/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java +++ b/src/main/java/net/brokenmoon/afloydwiremod/api/AbstractWireTileEntity.java @@ -102,4 +102,21 @@ public abstract class AbstractWireTileEntity extends TileEntity { } } } + + public void prepForDelete() { + if(outputs != null) { + for (int i = 0; i < outputs.length; ++i) { + if (outputs[i].wire != null && outputs[i].wire.thisslot > -1) { + WireConnection wire = outputs[i].wire; + AbstractWireTileEntity otherChip = (AbstractWireTileEntity)this.worldObj.getBlockTileEntity(wire.x, wire.y, wire.z); + if(otherChip != null && otherChip.inputs != null) { + outputs[i].floatvalue = 0; + outputs[i].stringvalue = ""; + this.updateIO(); + otherChip.update(); + } + } + } + } + } }