mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 19:29:31 +00:00
Fix lurking race condition in TileCorporeaIndex
This commit is contained in:
1 parent
a299257431
commit
1d754b010a
2 files changed
+20
-13
No files matched your search
@@ -65,7 +65,6 @@ public final class ClientTickHandler {
|
||||
|
||||
if(Minecraft.getMinecraft().world == null) {
|
||||
ManaNetworkHandler.instance.clear();
|
||||
TileCorporeaIndex.indexes.clear();
|
||||
SubTileVinculotus.existingFlowers.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ package vazkii.botania.common.block.tile.corporea;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
@@ -34,7 +33,6 @@ import vazkii.botania.common.core.helper.MathHelper;
|
||||
import vazkii.botania.common.core.helper.PlayerHelper;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -43,13 +41,15 @@ import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TileCorporeaIndex extends TileCorporeaBase implements ICorporeaRequestor {
|
||||
|
||||
public static final double RADIUS = 2.5;
|
||||
|
||||
private static InputHandler input;
|
||||
public static final Set<TileCorporeaIndex> indexes = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
private static final Set<TileCorporeaIndex> serverIndexes = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
private static final Set<TileCorporeaIndex> clientIndexes = Collections.newSetFromMap(new WeakHashMap<>());
|
||||
|
||||
private static final Map<Pattern, IRegexStacker> patterns = new LinkedHashMap<>();
|
||||
|
||||
@@ -173,20 +173,20 @@ public class TileCorporeaIndex extends TileCorporeaBase implements ICorporeaRequ
|
||||
} else if(closeby > 0F)
|
||||
closeby -= step;
|
||||
|
||||
if(!isInvalid() && !indexes.contains(this))
|
||||
indexes.add(this);
|
||||
if(!isInvalid())
|
||||
addIndex(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate() {
|
||||
super.invalidate();
|
||||
indexes.remove(this);
|
||||
removeIndex(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
super.onChunkUnload();
|
||||
indexes.remove(this);
|
||||
removeIndex(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -231,6 +231,16 @@ public class TileCorporeaIndex extends TileCorporeaBase implements ICorporeaRequ
|
||||
return input;
|
||||
}
|
||||
|
||||
private static void addIndex(TileCorporeaIndex index) {
|
||||
Set<TileCorporeaIndex> set = index.world.isRemote ? clientIndexes : serverIndexes;
|
||||
set.add(index);
|
||||
}
|
||||
|
||||
private static void removeIndex(TileCorporeaIndex index) {
|
||||
Set<TileCorporeaIndex> set = index.world.isRemote ? clientIndexes : serverIndexes;
|
||||
set.remove(index);
|
||||
}
|
||||
|
||||
public static final class InputHandler implements ICorporeaAutoCompleteController {
|
||||
|
||||
public InputHandler() {
|
||||
@@ -280,11 +290,9 @@ public class TileCorporeaIndex extends TileCorporeaBase implements ICorporeaRequ
|
||||
}
|
||||
|
||||
public static List<TileCorporeaIndex> getNearbyIndexes(EntityPlayer player) {
|
||||
List<TileCorporeaIndex> indexList = new ArrayList<>();
|
||||
for(TileCorporeaIndex index : indexes)
|
||||
if(isInRangeOfIndex(player, index) && index.world.isRemote == player.world.isRemote)
|
||||
indexList.add(index);
|
||||
return indexList;
|
||||
return (player.world.isRemote ? clientIndexes : serverIndexes)
|
||||
.stream().filter(i -> isInRangeOfIndex(player, i))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user