From 931c21814d2c2533fe2fb8d5a37e02ee35343930 Mon Sep 17 00:00:00 2001 From: koiNoCirculation <57739338+koiNoCirculation@users.noreply.github.com> Date: Thu, 21 Mar 2024 12:17:10 -0700 Subject: [PATCH] Fix memory leak by tesla, but problem still exists when using tesla cover. (#275) * Fixed memory leak. But leak still exists in tesla cover, because when chunk unloads, the TeslaCoverConnection object is not removed from the set. * Fixed memory leak. But leak still exists in tesla cover, because when chunk unloads, the TeslaCoverConnection object is not removed from the set. --- .../tectech/thing/cover/GT_Cover_TM_TeslaCoil.java | 11 +++++++++++ .../multi/GT_MetaTileEntity_TM_teslaCoil.java | 7 +++++++ .../single/GT_MetaTileEntity_TeslaCoil.java | 7 +++++++ 3 files changed, 25 insertions(+) diff --git a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java index 7fab22c9b..da8fed78a 100644 --- a/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/cover/GT_Cover_TM_TeslaCoil.java @@ -1,6 +1,7 @@ package com.github.technus.tectech.thing.cover; import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.teslaSimpleNodeSetAdd; +import static com.github.technus.tectech.mechanics.tesla.ITeslaConnectable.TeslaUtil.teslaSimpleNodeSetRemove; import static ic2.api.info.Info.DMG_ELECTRIC; import net.minecraft.entity.player.EntityPlayer; @@ -30,6 +31,16 @@ public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, return super.doCoverThings(side, aInputRedstone, aCoverID, aCoverVariable, aTileEntity, aTimer); } + @Override + public boolean onCoverRemoval(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, + boolean aForced) { + teslaSimpleNodeSetRemove( + new TeslaCoverConnection( + aTileEntity.getIGregTechTileEntityOffset(0, 0, 0), + getTeslaReceptionCapability())); + return super.onCoverRemoval(side, aCoverID, aCoverVariable, aTileEntity, aForced); + } + @Override public String getDescription(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { return "Do not attempt to use screwdriver!"; // TODO Translation support diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java index 3260546ec..1054825db 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/multi/GT_MetaTileEntity_TM_teslaCoil.java @@ -708,6 +708,13 @@ public void onRemoval() { } } + @Override + public void onUnload() { + if (!getBaseMetaTileEntity().isClientSide()) { + teslaSimpleNodeSetRemove(this); + } + } + @Override protected void parametersInstantiation_EM() { Parameters.Group hatch_0 = parametrization.getGroup(0, true); diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index 940c27683..87bc5c3d7 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -237,6 +237,13 @@ public void onRemoval() { } } + @Override + public void onUnload() { + if (!this.getBaseMetaTileEntity().isClientSide()) { + teslaSimpleNodeSetRemove(this); + } + } + @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT);