mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 19:29:31 +00:00
The Mana Network now works under a WeakHashSet with World pointers rather than Integer pointers. This fixes world leaking and possibly flowers sometimes losing their bindings.
This commit is contained in:
1 parent
61bae15118
commit
57fe64ca11
6 files changed
+40
-36
No files matched your search
@@ -16,6 +16,7 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class DummyManaNetwork implements IManaNetwork {
|
||||
|
||||
@@ -27,22 +28,22 @@ public class DummyManaNetwork implements IManaNetwork {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getClosestPool(ChunkCoordinates pos, int dimension, int limit) {
|
||||
public TileEntity getClosestPool(ChunkCoordinates pos, World world, int limit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getClosestCollector(ChunkCoordinates pos, int dimension, int limit) {
|
||||
public TileEntity getClosestCollector(ChunkCoordinates pos, World world, int limit) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TileEntity> getAllCollectorsInWorld(int dim) {
|
||||
public List<TileEntity> getAllCollectorsInWorld(World world) {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TileEntity> getAllPoolsInWorld(int dim) {
|
||||
public List<TileEntity> getAllPoolsInWorld(World world) {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* A basic interface for a world's Mana Network.
|
||||
@@ -37,7 +38,7 @@ public interface IManaNetwork {
|
||||
* @param limit The maximum distance the closest block can be, if the closest block
|
||||
* is farther away than that, null will be returned instead.
|
||||
*/
|
||||
public TileEntity getClosestCollector(ChunkCoordinates pos, int dim, int limit);
|
||||
public TileEntity getClosestCollector(ChunkCoordinates pos, World world, int limit);
|
||||
|
||||
/**
|
||||
* Gets the closest Mana Pool in the network to the Chunk Coordinates passed in,
|
||||
@@ -48,19 +49,19 @@ public interface IManaNetwork {
|
||||
* @param limit The maximum distance the closest block can be, if the closest block
|
||||
* is farther away than that, null will be returned instead.
|
||||
*/
|
||||
public TileEntity getClosestPool(ChunkCoordinates pos, int dim, int limit);
|
||||
public TileEntity getClosestPool(ChunkCoordinates pos, World world, int limit);
|
||||
|
||||
/**
|
||||
* Gets the list of all Mana Collectors (eg. Mana Spreader) in the dimension
|
||||
* passed in. Note that this is the actual list and not a copy, make sure to
|
||||
* clone the list if you intend to change it in any way.
|
||||
*/
|
||||
public List<TileEntity> getAllCollectorsInWorld(int dim);
|
||||
public List<TileEntity> getAllCollectorsInWorld(World world);
|
||||
|
||||
/**
|
||||
* Gets the list of all Mana Pools in the dimension passed in. Note that this
|
||||
* is the actual list and not a copy, make sure to clone the list if you intend
|
||||
* to change it in any way.
|
||||
*/
|
||||
public List<TileEntity> getAllPoolsInWorld(int dim);
|
||||
public List<TileEntity> getAllPoolsInWorld(World world);
|
||||
}
|
||||
@@ -99,10 +99,10 @@ public class SubTileFunctional extends SubTileEntity {
|
||||
|
||||
if(needsNew) {
|
||||
IManaNetwork network = BotaniaAPI.internalHandler.getManaNetworkInstance();
|
||||
int size = network.getAllPoolsInWorld(supertile.getWorldObj().provider.dimensionId).size();
|
||||
int size = network.getAllPoolsInWorld(supertile.getWorldObj()).size();
|
||||
if(size != sizeLastCheck) {
|
||||
ChunkCoordinates coords = new ChunkCoordinates(supertile.xCoord, supertile.yCoord, supertile.zCoord);
|
||||
linkedPool = network.getClosestPool(coords, supertile.getWorldObj().provider.dimensionId, range);
|
||||
linkedPool = network.getClosestPool(coords, supertile.getWorldObj(), range);
|
||||
sizeLastCheck = size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,10 +100,10 @@ public class SubTileGenerating extends SubTileEntity {
|
||||
|
||||
if(needsNew) {
|
||||
IManaNetwork network = BotaniaAPI.internalHandler.getManaNetworkInstance();
|
||||
int size = network.getAllCollectorsInWorld(supertile.getWorldObj().provider.dimensionId).size();
|
||||
int size = network.getAllCollectorsInWorld(supertile.getWorldObj()).size();
|
||||
if(size != sizeLastCheck) {
|
||||
ChunkCoordinates coords = new ChunkCoordinates(supertile.xCoord, supertile.yCoord, supertile.zCoord);
|
||||
linkedCollector = network.getClosestCollector(coords, supertile.getWorldObj().provider.dimensionId, range);
|
||||
linkedCollector = network.getClosestCollector(coords, supertile.getWorldObj(), range);
|
||||
sizeLastCheck = size;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ClientTickHandler {
|
||||
if(player != null) {
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
if(stack != null && stack.getItem() instanceof ItemTwigWand) {
|
||||
List<TileEntity> list = new ArrayList(ManaNetworkHandler.instance.getAllCollectorsInWorld(Minecraft.getMinecraft().theWorld.provider.dimensionId));
|
||||
List<TileEntity> list = new ArrayList(ManaNetworkHandler.instance.getAllCollectorsInWorld(Minecraft.getMinecraft().theWorld));
|
||||
for(TileEntity tile : list) {
|
||||
if(tile instanceof IManaCollector)
|
||||
((IManaCollector) tile).onClientDisplayTick();
|
||||
|
||||
@@ -12,12 +12,13 @@
|
||||
package vazkii.botania.common.core.handler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
import vazkii.botania.api.internal.IManaNetwork;
|
||||
import vazkii.botania.api.mana.ManaNetworkEvent;
|
||||
import vazkii.botania.api.mana.ManaNetworkEvent.Action;
|
||||
@@ -29,12 +30,12 @@ public final class ManaNetworkHandler implements IManaNetwork {
|
||||
|
||||
public static final ManaNetworkHandler instance = new ManaNetworkHandler();
|
||||
|
||||
public Map<Integer, List<TileEntity>> manaPools = new HashMap();
|
||||
public Map<Integer, List<TileEntity>> manaCollectors = new HashMap();
|
||||
public WeakHashMap<World, List<TileEntity>> manaPools = new WeakHashMap();
|
||||
public WeakHashMap<World, List<TileEntity>> manaCollectors = new WeakHashMap();
|
||||
|
||||
@SubscribeEvent
|
||||
public void onNetworkEvent(ManaNetworkEvent event) {
|
||||
Map<Integer, List<TileEntity>> map = event.type == ManaBlockType.COLLECTOR ? manaCollectors : manaPools;
|
||||
Map<World, List<TileEntity>> map = event.type == ManaBlockType.COLLECTOR ? manaCollectors : manaPools;
|
||||
if(event.action == Action.ADD)
|
||||
add(map, event.tile);
|
||||
else remove(map, event.tile);
|
||||
@@ -47,16 +48,16 @@ public final class ManaNetworkHandler implements IManaNetwork {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getClosestPool(ChunkCoordinates pos, int dimension, int limit) {
|
||||
if(manaPools.containsKey(dimension))
|
||||
return getClosest(manaPools.get(dimension), pos, limit);
|
||||
public TileEntity getClosestPool(ChunkCoordinates pos, World world, int limit) {
|
||||
if(manaPools.containsKey(world))
|
||||
return getClosest(manaPools.get(world), pos, limit);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getClosestCollector(ChunkCoordinates pos, int dimension, int limit) {
|
||||
if(manaCollectors.containsKey(dimension))
|
||||
return getClosest(manaCollectors.get(dimension), pos, limit);
|
||||
public TileEntity getClosestCollector(ChunkCoordinates pos, World world, int limit) {
|
||||
if(manaCollectors.containsKey(world))
|
||||
return getClosest(manaCollectors.get(world), pos, limit);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ public final class ManaNetworkHandler implements IManaNetwork {
|
||||
return closestTile;
|
||||
}
|
||||
|
||||
private synchronized void remove(Map<Integer, List<TileEntity>> map, TileEntity tile) {
|
||||
private synchronized void remove(Map<World, List<TileEntity>> map, TileEntity tile) {
|
||||
int dim = tile.getWorldObj().provider.dimensionId;
|
||||
|
||||
if(!map.containsKey(dim))
|
||||
@@ -88,32 +89,33 @@ public final class ManaNetworkHandler implements IManaNetwork {
|
||||
tiles.remove(tile);
|
||||
}
|
||||
|
||||
private synchronized void add(Map<Integer, List<TileEntity>> map, TileEntity tile) {
|
||||
int dim = tile.getWorldObj().provider.dimensionId;
|
||||
private synchronized void add(Map<World, List<TileEntity>> map, TileEntity tile) {
|
||||
World world = tile.getWorldObj();
|
||||
|
||||
List<TileEntity> tiles;
|
||||
if(!map.containsKey(dim))
|
||||
map.put(dim, new ArrayList());
|
||||
if(!map.containsKey(world))
|
||||
map.put(world, new ArrayList());
|
||||
|
||||
tiles = map.get(dim);
|
||||
tiles = map.get(world);
|
||||
|
||||
if(!tiles.contains(tile))
|
||||
tiles.add(tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TileEntity> getAllCollectorsInWorld(int dim) {
|
||||
return getAllInWorld(manaCollectors, dim);
|
||||
public List<TileEntity> getAllCollectorsInWorld(World world) {
|
||||
return getAllInWorld(manaCollectors, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TileEntity> getAllPoolsInWorld(int dim) {
|
||||
return getAllInWorld(manaPools, dim);
|
||||
public List<TileEntity> getAllPoolsInWorld(World world) {
|
||||
return getAllInWorld(manaPools, world);
|
||||
}
|
||||
|
||||
private List<TileEntity> getAllInWorld(Map<Integer, List<TileEntity>> map, int dim) {
|
||||
if(!map.containsKey(dim))
|
||||
private List<TileEntity> getAllInWorld(Map<World, List<TileEntity>> map, World world) {
|
||||
if(!map.containsKey(world))
|
||||
return new ArrayList();
|
||||
return map.get(dim);
|
||||
|
||||
return map.get(world);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user