Revert vinculotus map back into a set, hack no longer needed thanks to getEffectivePos

This commit is contained in:
Vincent Lee committed 2020-01-31 12:48:27 -06:00
1 parent 144f023041
commit 4ea449d723
1 file changed
+13 -19
@@ -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<SubTileVinculotus> 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<SubTileVinculotus, BlockPos> existingFlowers = new WeakHashMap<>();
public static final Set<SubTileVinculotus> 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<Pair<SubTileVinculotus, BlockPos>> possibleFlowers = new ArrayList<>();
for(Map.Entry<SubTileVinculotus, BlockPos> e : existingFlowers.entrySet()) {
SubTileVinculotus flower = e.getKey();
BlockPos activePos = e.getValue();
List<SubTileVinculotus> 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<SubTileVinculotus, BlockPos> 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;