Fix World leak in WirelessChargerController

This commit is contained in:
Alexdoru committed 2025-11-23 14:31:20 +01:00
1 parent fe95c2795c
commit 918b219413
4 files changed
+20 -26

No files matched your search

@@ -1,7 +1,5 @@
package crazypants.enderio;
import java.text.DecimalFormat;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
@@ -21,15 +19,15 @@ import crazypants.enderio.conduit.IConduit;
import crazypants.enderio.conduit.render.ConduitRenderer;
import crazypants.enderio.machine.hypercube.HyperCubeRegister;
import crazypants.enderio.machine.transceiver.ServerChannelRegister;
import crazypants.enderio.machine.wireless.WirelessChargerController;
public class CommonProxy {
private static final DecimalFormat FORMAT = new DecimalFormat("########0.000");
protected long serverTickCount = 0;
protected long clientTickCount = 0;
protected final TickTimer tickTimer = new TickTimer();
public ConduitNetworkTickHandler conduitNetworkTickHandler = null;
public WirelessChargerController wirelessChargerController = null;
public CommonProxy() {}
@@ -86,6 +84,8 @@ public class CommonProxy {
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
conduitNetworkTickHandler = new ConduitNetworkTickHandler();
FMLCommonHandler.instance().bus().register(conduitNetworkTickHandler);
wirelessChargerController = new WirelessChargerController();
FMLCommonHandler.instance().bus().register(wirelessChargerController);
}
public void onServerStarted(FMLServerStartedEvent event) {
@@ -97,6 +97,8 @@ public class CommonProxy {
HyperCubeRegister.unload();
FMLCommonHandler.instance().bus().unregister(conduitNetworkTickHandler);
conduitNetworkTickHandler = null;
FMLCommonHandler.instance().bus().unregister(wirelessChargerController);
wirelessChargerController = null;
}
public final class TickTimer {
@@ -6,6 +6,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cofh.api.energy.IEnergyContainerItem;
import crazypants.enderio.EnderIO;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.power.IInternalPowerReceiver;
@@ -28,7 +29,7 @@ public class TileWirelessCharger extends TileEntityEio implements IInternalPower
@Override
public void invalidate() {
super.invalidate();
WirelessChargerController.instance.deregisterCharger(this);
EnderIO.proxy.wirelessChargerController.deregisterCharger(this);
registered = false;
}
@@ -40,7 +41,7 @@ public class TileWirelessCharger extends TileEntityEio implements IInternalPower
}
if (!registered) {
WirelessChargerController.instance.registerCharger(this);
EnderIO.proxy.wirelessChargerController.registerCharger(this);
registered = true;
}
@@ -8,6 +8,8 @@ import net.minecraft.tileentity.TileEntity;
import com.enderio.core.common.util.BlockCoord;
import crazypants.enderio.EnderIO;
public class WirelessChargedLocation {
private final TileEntity te;
@@ -22,11 +24,11 @@ public class WirelessChargedLocation {
* use (unless ~4B changes happen in between). Do this instead directly updating so that WirelessChargedLocation
* can be used while the TileEntity is still in construction (or loading).
*/
this.lastChangeCount = WirelessChargerController.instance.getChangeCount() - 1;
this.lastChangeCount = EnderIO.proxy.wirelessChargerController.getChangeCount() - 1;
}
private void updateChargers() {
WirelessChargerController wcc = WirelessChargerController.instance;
WirelessChargerController wcc = EnderIO.proxy.wirelessChargerController;
chargers.clear();
lastChangeCount = wcc.getChangeCount();
final BlockCoord bc = new BlockCoord(te);
@@ -39,7 +41,7 @@ public class WirelessChargedLocation {
}
private void checkChangeCount() {
if (lastChangeCount != WirelessChargerController.instance.getChangeCount()) {
if (lastChangeCount != EnderIO.proxy.wirelessChargerController.getChangeCount()) {
updateChargers();
}
}
@@ -8,11 +8,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import com.enderio.core.common.util.BlockCoord;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
@@ -21,19 +19,17 @@ import crazypants.util.BaublesUtil;
public class WirelessChargerController {
public static WirelessChargerController instance = new WirelessChargerController();
private static final int RANGE = Config.wirelessChargerRange;
private static final int RANGE_SQ = RANGE * RANGE;
static {
FMLCommonHandler.instance().bus().register(WirelessChargerController.instance);
MinecraftForge.EVENT_BUS.register(WirelessChargerController.instance);
}
private final Map<Integer, Map<BlockCoord, IWirelessCharger>> perWorldChargers = new HashMap<Integer, Map<BlockCoord, IWirelessCharger>>();
private int changeCount;
private WirelessChargerController() {}
@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.side != Side.CLIENT && event.phase == TickEvent.Phase.END) {
chargePlayersItems(event.player);
}
}
public void registerCharger(IWirelessCharger charger) {
if (charger == null) {
@@ -53,13 +49,6 @@ public class WirelessChargerController {
changeCount++;
}
@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event) {
if (event.side != Side.CLIENT && event.phase == TickEvent.Phase.END) {
chargePlayersItems(event.player);
}
}
private void chargePlayersItems(EntityPlayer player) {
Map<BlockCoord, IWirelessCharger> chargers = getChargersForWorld(player.worldObj);
if (chargers.isEmpty()) {