diff --git a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileVinculotus.java b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileVinculotus.java index 5c75fc4f2..2dad23f51 100644 --- a/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileVinculotus.java +++ b/src/main/java/vazkii/botania/common/block/subtile/functional/SubTileVinculotus.java @@ -17,16 +17,15 @@ import net.minecraftforge.event.entity.living.EnderTeleportEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.registries.ObjectHolder; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; import vazkii.botania.api.subtile.RadiusDescriptor; import vazkii.botania.api.subtile.TileEntityFunctionalFlower; import vazkii.botania.common.core.helper.MathHelper; import vazkii.botania.common.lib.LibMisc; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import java.util.Map; +import java.util.Set; import java.util.WeakHashMap; @Mod.EventBusSubscriber(modid = LibMisc.MOD_ID) @@ -34,10 +33,7 @@ public class SubTileVinculotus extends TileEntityFunctionalFlower { @ObjectHolder(LibMisc.MOD_ID + ":vinculotus") public static TileEntityType TYPE; - // Must store position since red string spoofers are only active during tick - // But our main logic runs outside, in the event handler - // TODO not needed anymore with addition of getEffectivePos? - public static final Map existingFlowers = new WeakHashMap<>(); + public static final Set existingFlowers = Collections.newSetFromMap(new WeakHashMap<>()); private static final int RANGE = 64; public SubTileVinculotus() { @@ -49,9 +45,7 @@ public class SubTileVinculotus extends TileEntityFunctionalFlower { super.tickFlower(); if(!getWorld().isRemote) { - BlockPos pos = existingFlowers.get(this); - if (pos == null || !pos.equals(getEffectivePos())) - existingFlowers.put(this, getEffectivePos()); + existingFlowers.add(this); } } @@ -80,12 +74,13 @@ public class SubTileVinculotus extends TileEntityFunctionalFlower { int cost = 50; if(event.getEntityLiving() instanceof EndermanEntity) { - List> possibleFlowers = new ArrayList<>(); - for(Map.Entry e : existingFlowers.entrySet()) { - SubTileVinculotus flower = e.getKey(); - BlockPos activePos = e.getValue(); + List possibleFlowers = new ArrayList<>(); + for(SubTileVinculotus flower : existingFlowers) { + BlockPos activePos = flower.getEffectivePos(); - if(flower == null || flower.redstoneSignal > 0 || flower.getMana() <= cost || flower.getWorld() != event.getEntityLiving().world || flower.getWorld().getTileEntity(flower.getEffectivePos()) != flower) + if(flower.redstoneSignal > 0 || flower.getMana() <= cost + || flower.getWorld() != event.getEntityLiving().world + || flower.getWorld().getTileEntity(flower.getPos()) != flower) continue; double x = activePos.getX() + 0.5; @@ -93,13 +88,12 @@ public class SubTileVinculotus extends TileEntityFunctionalFlower { double z = activePos.getZ() + 0.5; if(MathHelper.pointDistanceSpace(x, y, z, event.getTargetX(), event.getTargetY(), event.getTargetZ()) < RANGE) - possibleFlowers.add(ImmutablePair.of(flower, activePos)); + possibleFlowers.add(flower); } if(!possibleFlowers.isEmpty()) { - Pair p = possibleFlowers.get(event.getEntityLiving().world.rand.nextInt(possibleFlowers.size())); - SubTileVinculotus flower = p.getLeft(); - BlockPos activePos = p.getRight(); + SubTileVinculotus flower = possibleFlowers.get(event.getEntityLiving().world.rand.nextInt(possibleFlowers.size())); + BlockPos activePos = flower.getEffectivePos(); double x = activePos.getX() + 0.5; double y = activePos.getY() + 1.5;