mirror of
https://github.com/GTNewHorizons/Gadomancy.git
synced 2026-11-19 03:39:13 +00:00
[Memory-opti:fix leak] Fix world leak in Event class (#44)
Co-authored-by: Nikolay S. <[email protected]>
This commit is contained in:
1 parent
f635705888
commit
178013a9cd
9 files changed
+78
-65
No files matched your search
@@ -22,6 +22,7 @@ import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import makeo.gadomancy.client.effect.EffectHandler;
|
||||
import makeo.gadomancy.client.events.ClientHandler;
|
||||
import makeo.gadomancy.client.events.RenderEventHandler;
|
||||
@@ -310,4 +311,9 @@ public class ClientProxy extends CommonProxy {
|
||||
public void runDelayedClientSide(Runnable run) {
|
||||
this.clientActions.add(run);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Side getSide() {
|
||||
return Side.CLIENT;
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,11 @@ import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||
import cpw.mods.fml.common.network.IGuiHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import makeo.gadomancy.client.ClientProxy;
|
||||
import makeo.gadomancy.common.aura.AuraEffects;
|
||||
import makeo.gadomancy.common.containers.ContainerArcanePackager;
|
||||
import makeo.gadomancy.common.containers.ContainerInfusionClaw;
|
||||
@@ -46,22 +47,18 @@ import thaumcraft.common.entities.golems.EntityGolemBase;
|
||||
/**
|
||||
* This class is part of the Gadomancy Mod Gadomancy is Open Source and distributed under the GNU LESSER GENERAL PUBLIC
|
||||
* LICENSE for more read the LICENSE file
|
||||
*
|
||||
* <p>
|
||||
* Created by makeo @ 29.11.2014 14:18
|
||||
*/
|
||||
public class CommonProxy implements IGuiHandler {
|
||||
|
||||
public static boolean serverOnlineState;
|
||||
|
||||
public static final EventHandlerGolem EVENT_HANDLER_GOLEM = new EventHandlerGolem();
|
||||
|
||||
public void onConstruct() {}
|
||||
|
||||
public void preInitalize() {
|
||||
PacketHandler.init();
|
||||
|
||||
RegisteredItems.preInit();
|
||||
|
||||
RegisteredBlocks.init();
|
||||
RegisteredItems.init();
|
||||
RegisteredGolemStuff.init();
|
||||
@@ -69,21 +66,10 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
public void initalize() {
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(Gadomancy.instance, this);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(CommonProxy.EVENT_HANDLER_GOLEM);
|
||||
FMLCommonHandler.instance().bus().register(new EventHandlerNetwork());
|
||||
EventHandlerWorld worldEventHandler = new EventHandlerWorld();
|
||||
MinecraftForge.EVENT_BUS.register(worldEventHandler);
|
||||
FMLCommonHandler.instance().bus().register(worldEventHandler);
|
||||
MinecraftForge.EVENT_BUS.register(new EventHandlerEntity());
|
||||
|
||||
RegisteredEnchantments.init();
|
||||
RegisteredRecipes.init();
|
||||
|
||||
SyncDataHolder.initialize();
|
||||
|
||||
RegisteredEntities.init();
|
||||
|
||||
DimensionManager.registerProviderType(ModConfig.dimOuterId, WorldProviderTCEldrich.class, true);
|
||||
DimensionManager.registerDimension(ModConfig.dimOuterId, ModConfig.dimOuterId);
|
||||
}
|
||||
@@ -91,14 +77,10 @@ public class CommonProxy implements IGuiHandler {
|
||||
public void postInitalize() {
|
||||
RegisteredPotions.init();
|
||||
AuraEffects.AER.getTickInterval(); // initalize AuraEffects
|
||||
|
||||
RegisteredResearches.init();
|
||||
RegisteredIntegrations.init();
|
||||
|
||||
RegisteredResearches.postInit();
|
||||
|
||||
RegisteredItems.postInit();
|
||||
|
||||
ModSubstitutions.postInit();
|
||||
}
|
||||
|
||||
@@ -125,15 +107,12 @@ public class CommonProxy implements IGuiHandler {
|
||||
|
||||
@Override
|
||||
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
||||
switch (ID) {
|
||||
case 0:
|
||||
return new ContainerGolem(player.inventory, ((EntityGolemBase) world.getEntityByID(x)).inventory);
|
||||
case 1:
|
||||
return new ContainerInfusionClaw(player.inventory, (IInventory) world.getTileEntity(x, y, z));
|
||||
case 2:
|
||||
return new ContainerArcanePackager(player.inventory, (IInventory) world.getTileEntity(x, y, z));
|
||||
}
|
||||
return null;
|
||||
return switch (ID) {
|
||||
case 0 -> new ContainerGolem(player.inventory, ((EntityGolemBase) world.getEntityByID(x)).inventory);
|
||||
case 1 -> new ContainerInfusionClaw(player.inventory, (IInventory) world.getTileEntity(x, y, z));
|
||||
case 2 -> new ContainerArcanePackager(player.inventory, (IInventory) world.getTileEntity(x, y, z));
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,6 +123,35 @@ public class CommonProxy implements IGuiHandler {
|
||||
public void runDelayedClientSide(Runnable run) {}
|
||||
|
||||
public Side getSide() {
|
||||
return this instanceof ClientProxy ? Side.CLIENT : Side.SERVER;
|
||||
return Side.SERVER;
|
||||
}
|
||||
|
||||
public EventHandlerGolem EVENT_HANDLER_GOLEM;
|
||||
public EventHandlerNetwork EVENT_HANDLER_NETWORK;
|
||||
public EventHandlerWorld EVENT_HANDLER_WORLD;
|
||||
public EventHandlerEntity EVENT_HANDLER_ENTITY;
|
||||
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
|
||||
EVENT_HANDLER_GOLEM = new EventHandlerGolem();
|
||||
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_GOLEM);
|
||||
EVENT_HANDLER_NETWORK = new EventHandlerNetwork();
|
||||
FMLCommonHandler.instance().bus().register(EVENT_HANDLER_NETWORK);
|
||||
EVENT_HANDLER_WORLD = new EventHandlerWorld();
|
||||
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_WORLD);
|
||||
FMLCommonHandler.instance().bus().register(EVENT_HANDLER_WORLD);
|
||||
EVENT_HANDLER_ENTITY = new EventHandlerEntity();
|
||||
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_ENTITY);
|
||||
}
|
||||
|
||||
public void onServerStopped(FMLServerStoppedEvent event) {
|
||||
MinecraftForge.EVENT_BUS.unregister(EVENT_HANDLER_GOLEM);
|
||||
EVENT_HANDLER_GOLEM = null;
|
||||
FMLCommonHandler.instance().bus().unregister(EVENT_HANDLER_NETWORK);
|
||||
EVENT_HANDLER_NETWORK = null;
|
||||
MinecraftForge.EVENT_BUS.unregister(EVENT_HANDLER_WORLD);
|
||||
FMLCommonHandler.instance().bus().unregister(EVENT_HANDLER_WORLD);
|
||||
EVENT_HANDLER_WORLD = null;
|
||||
MinecraftForge.EVENT_BUS.unregister(EVENT_HANDLER_ENTITY);
|
||||
EVENT_HANDLER_ENTITY = null;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLInterModComms;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerAboutToStartEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStoppedEvent;
|
||||
import makeo.gadomancy.api.GadomancyApi;
|
||||
import makeo.gadomancy.common.api.DefaultApiHandler;
|
||||
import makeo.gadomancy.common.data.config.ModConfig;
|
||||
@@ -83,7 +85,6 @@ public class Gadomancy {
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
Gadomancy.proxy.initalize();
|
||||
|
||||
FMLInterModComms.sendMessage(Thaumcraft.MODID, "dimensionBlacklist", ModConfig.dimOuterId + ":0");
|
||||
}
|
||||
|
||||
@@ -91,4 +92,14 @@ public class Gadomancy {
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
Gadomancy.proxy.postInitalize();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerAboutToStart(FMLServerAboutToStartEvent event) {
|
||||
Gadomancy.proxy.onServerAboutToStart(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void onServerStopped(FMLServerStoppedEvent event) {
|
||||
Gadomancy.proxy.onServerStopped(event);
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ import net.minecraft.world.EnumDifficulty;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import makeo.gadomancy.api.AuraEffect;
|
||||
import makeo.gadomancy.common.events.EventHandlerEntity;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.integration.IntegrationThaumicTinkerer;
|
||||
import makeo.gadomancy.common.registration.RegisteredIntegrations;
|
||||
import makeo.gadomancy.common.registration.RegisteredPotions;
|
||||
@@ -201,8 +201,9 @@ public class AuraEffects {
|
||||
|
||||
@Override
|
||||
public void doEntityEffect(ChunkCoordinates originTile, Entity e) {
|
||||
if (!EventHandlerEntity.registeredLuxPylons.contains(originTile))
|
||||
EventHandlerEntity.registeredLuxPylons.add(originTile);
|
||||
if (!Gadomancy.proxy.EVENT_HANDLER_ENTITY.registeredLuxPylons.contains(originTile)) {
|
||||
Gadomancy.proxy.EVENT_HANDLER_ENTITY.registeredLuxPylons.add(originTile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,7 @@ import thaumcraft.common.items.armor.Hover;
|
||||
*/
|
||||
public class EventHandlerEntity {
|
||||
|
||||
public static List<ChunkCoordinates> registeredLuxPylons = new ArrayList<ChunkCoordinates>();
|
||||
public final List<ChunkCoordinates> registeredLuxPylons = new ArrayList<>();
|
||||
|
||||
/*
|
||||
* @SubscribeEvent(priority = EventPriority.LOWEST) public void on(EntityEvent.EntityConstructing e) { if (e.entity
|
||||
@@ -51,7 +51,7 @@ public class EventHandlerEntity {
|
||||
if (event.entityLiving.isCreatureType(EnumCreatureType.monster, false)) {
|
||||
double rangeSq = AuraEffects.LUX.getRange() * AuraEffects.LUX.getRange();
|
||||
Vector3 entityPos = MiscUtils.getPositionVector(event.entity);
|
||||
for (ChunkCoordinates luxPylons : EventHandlerEntity.registeredLuxPylons) {
|
||||
for (ChunkCoordinates luxPylons : registeredLuxPylons) {
|
||||
Vector3 pylon = Vector3.fromCC(luxPylons);
|
||||
if (entityPos.distanceSquared(pylon) <= rangeSq) {
|
||||
event.setResult(Event.Result.DENY);
|
||||
|
||||
@@ -50,6 +50,8 @@ import thaumcraft.common.items.wands.ItemWandCasting;
|
||||
*/
|
||||
public class EventHandlerGolem {
|
||||
|
||||
private final Map<EntityGolemBase, EntityPlayer> markedGolems = new HashMap<>();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void on(EntityEvent.EntityConstructing e) {
|
||||
if (e.entity instanceof EntityGolemBase) {
|
||||
@@ -147,8 +149,6 @@ public class EventHandlerGolem {
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<EntityGolemBase, EntityPlayer> markedGolems = new HashMap<EntityGolemBase, EntityPlayer>();
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
|
||||
public void on(PlaySoundAtEntityEvent event) {
|
||||
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -18,7 +17,6 @@ import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.Explosion;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingEvent;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
@@ -56,7 +54,9 @@ import thaumcraft.common.tiles.TileJarFillable;
|
||||
*/
|
||||
public class EventHandlerWorld {
|
||||
|
||||
public Map<EntityItem, Long> trackedItems = new HashMap<EntityItem, Long>();
|
||||
private final Map<EntityItem, Long> trackedItems = new HashMap<>();
|
||||
private Map<EntityPlayer, Integer> interacts;
|
||||
private int serverTick;
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
public void on(EntityJoinWorldEvent event) {
|
||||
@@ -146,16 +146,6 @@ public class EventHandlerWorld {
|
||||
return NBTHelper.hasPersistentData(stack) && NBTHelper.getPersistentData(stack).hasKey("disguise");
|
||||
}
|
||||
|
||||
private int serverTick;
|
||||
private Entity lastUpdated;
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void on(LivingEvent.LivingUpdateEvent e) {
|
||||
if (!e.entityLiving.worldObj.isRemote) {
|
||||
this.lastUpdated = e.entityLiving;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public void on(WorldEvent.Load e) {
|
||||
if (!e.world.isRemote && e.world.provider.dimensionId == 0) {
|
||||
@@ -200,12 +190,10 @@ public class EventHandlerWorld {
|
||||
SyncDataHolder.doNecessaryUpdates();
|
||||
this.serverTick++;
|
||||
if ((this.serverTick & 15) == 0) {
|
||||
EventHandlerEntity.registeredLuxPylons.clear();
|
||||
Gadomancy.proxy.EVENT_HANDLER_ENTITY.registeredLuxPylons.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private Map<EntityPlayer, Integer> interacts;
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
|
||||
public void on(BlockEvent.PlaceEvent e) {
|
||||
if (e.isCanceled()) {
|
||||
@@ -237,7 +225,7 @@ public class EventHandlerWorld {
|
||||
if (!event.world.isRemote) {
|
||||
if (event.block == RegisteredBlocks.blockNodeManipulator) {
|
||||
TileEntity te = event.world.getTileEntity(event.x, event.y, event.z);
|
||||
if (te != null && te instanceof TileNodeManipulator) {
|
||||
if (te instanceof TileNodeManipulator) {
|
||||
if (((TileNodeManipulator) te).isInMultiblock()) ((TileNodeManipulator) te).breakMultiblock();
|
||||
}
|
||||
}
|
||||
@@ -280,20 +268,19 @@ public class EventHandlerWorld {
|
||||
}
|
||||
|
||||
private boolean isStickyJar(ItemStack stack) {
|
||||
return stack != null && RegisteredItems.isStickyableJar(stack)
|
||||
&& stack.hasTagCompound()
|
||||
return RegisteredItems.isStickyableJar(stack) && stack.hasTagCompound()
|
||||
&& stack.stackTagCompound.getBoolean("isStickyJar");
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.NORMAL)
|
||||
public void on(ItemTooltipEvent e) {
|
||||
if (e.toolTip.size() > 0 && e.itemStack.hasTagCompound()) {
|
||||
if (!e.toolTip.isEmpty() && e.itemStack.hasTagCompound()) {
|
||||
if (e.itemStack.stackTagCompound.getBoolean("isStickyJar")) {
|
||||
e.toolTip.add(1, "\u00a7a" + StatCollector.translateToLocal("gadomancy.lore.stickyjar"));
|
||||
e.toolTip.add(1, EnumChatFormatting.GREEN + StatCollector.translateToLocal("gadomancy.lore.stickyjar"));
|
||||
}
|
||||
}
|
||||
|
||||
if (e.toolTip.size() > 0 && NBTHelper.hasPersistentData(e.itemStack)) {
|
||||
if (!e.toolTip.isEmpty() && NBTHelper.hasPersistentData(e.itemStack)) {
|
||||
NBTTagCompound compound = NBTHelper.getPersistentData(e.itemStack);
|
||||
if (compound.hasKey("disguise")) {
|
||||
NBTBase base = compound.getTag("disguise");
|
||||
@@ -306,7 +293,7 @@ public class EventHandlerWorld {
|
||||
} else {
|
||||
lore = StatCollector.translateToLocal("gadomancy.lore.disguise.none");
|
||||
}
|
||||
e.toolTip.add("\u00a7a" + lore);
|
||||
e.toolTip.add(EnumChatFormatting.GREEN + lore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,7 +19,6 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import makeo.gadomancy.api.ClickBehavior;
|
||||
import makeo.gadomancy.client.ClientProxy;
|
||||
import makeo.gadomancy.common.CommonProxy;
|
||||
import makeo.gadomancy.common.Gadomancy;
|
||||
import makeo.gadomancy.common.integration.IntegrationMod;
|
||||
import makeo.gadomancy.common.registration.RegisteredBlocks;
|
||||
@@ -87,7 +86,8 @@ public class IntegrationThaumicHorizions extends IntegrationMod {
|
||||
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if (stack != null && stack.getItem().onLeftClickEntity(stack, player, e.target) && e.target.isDead) {
|
||||
CommonProxy.EVENT_HANDLER_GOLEM.on(new PlaySoundAtEntityEvent(e.target, "thaumcraft:zap", 0.5f, 1.0f));
|
||||
Gadomancy.proxy.EVENT_HANDLER_GOLEM
|
||||
.on(new PlaySoundAtEntityEvent(e.target, "thaumcraft:zap", 0.5f, 1.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class NBTHelper {
|
||||
|
||||
public static boolean hasPersistentData(NBTTagCompound base) {
|
||||
NBTBase modData = base.getTag(Gadomancy.MODID);
|
||||
return modData != null && modData instanceof NBTTagCompound;
|
||||
return modData instanceof NBTTagCompound;
|
||||
}
|
||||
|
||||
public static void removePersistentData(Entity entity) {
|
||||
|
||||
Reference in new issue
Block a user