More API cleanup (notably, remove TileSignature)

This commit is contained in:
Vincent Lee committed 2020-02-26 19:10:50 -06:00
1 parent 8d54c9a8cb
commit 926b8d864a
7 files changed
+26 -83

No files matched your search

@@ -14,7 +14,6 @@ import com.google.common.collect.ImmutableSet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import vazkii.botania.api.mana.TileSignature;
import java.util.Set;
@@ -36,12 +35,12 @@ public class DummyManaNetwork implements IManaNetwork {
}
@Override
public Set<TileSignature> getAllCollectorsInWorld(World world) {
public Set<TileEntity> getAllCollectorsInWorld(World world) {
return ImmutableSet.of();
}
@Override
public Set<TileSignature> getAllPoolsInWorld(World world) {
public Set<TileEntity> getAllPoolsInWorld(World world) {
return ImmutableSet.of();
}
@@ -13,7 +13,6 @@ package vazkii.botania.api.internal;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import vazkii.botania.api.mana.TileSignature;
import java.util.Set;
@@ -56,12 +55,12 @@ public interface IManaNetwork {
* passed in. Note that this is the actual set and not a copy, make sure to
* clone the set if you intend to change it in any way.
*/
public Set<TileSignature> getAllCollectorsInWorld(World world);
public Set<TileEntity> getAllCollectorsInWorld(World world);
/**
* Gets the set of all Mana Pools in the dimension passed in. Note that this
* is the actual set and not a copy, make sure to clone the set if you intend
* to change it in any way.
*/
public Set<TileSignature> getAllPoolsInWorld(World world);
public Set<TileEntity> getAllPoolsInWorld(World world);
}
@@ -17,13 +17,15 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
/**
* A block that implements this can provide an IIcon (block icons only)
* A block that implements this can provide a sprite
* to be used as an overlay for the mana pool, similarly to the mana void
* and catalysts.
*/
public interface IPoolOverlayProvider {
/**
* @return A sprite to render. Must be stitched to the main block/item atlas.
*/
@OnlyIn(Dist.CLIENT)
public TextureAtlasSprite getIcon(World world, BlockPos pos);
TextureAtlasSprite getIcon(World world, BlockPos pos);
}
@@ -1,35 +0,0 @@
package vazkii.botania.api.mana;
import net.minecraft.tileentity.TileEntity;
public class TileSignature {
private final TileEntity tile;
private final boolean remoteWorld;
public TileSignature(TileEntity tile, boolean remoteWorld) {
this.tile = tile;
this.remoteWorld = remoteWorld;
}
public TileEntity getTile() {
return tile;
}
public boolean isRemote() {
return remoteWorld;
}
@Override
public int hashCode() {
return Boolean.hashCode(remoteWorld) ^ System.identityHashCode(tile);
}
@Override
public boolean equals(Object o) {
return o instanceof TileSignature
&& tile == ((TileSignature) o).tile
&& remoteWorld == ((TileSignature) o).remoteWorld;
}
}
@@ -35,19 +35,8 @@ public interface ISparkEntity {
*/
public void registerTransfer(ISparkEntity entity);
/**
* Gets which upgrade is in this Spark.<br>
* 0: None<br>
* 1: Dispersive<br>
* 2: Dominant<br>
* 3: Recessive<br>
* 4: Isolated
*/
public SparkUpgradeType getUpgrade();
/**
* Sets the upgrade on this Spark. See {@link ISparkEntity#getUpgrade}
*/
public void setUpgrade(SparkUpgradeType upgrade);
/**
@@ -21,17 +21,14 @@ import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import vazkii.botania.api.mana.IManaCollector;
import vazkii.botania.api.mana.TileSignature;
import vazkii.botania.client.render.tile.RenderTileRedString;
import vazkii.botania.common.block.subtile.functional.SubTileVinculotus;
import vazkii.botania.common.core.handler.ManaNetworkHandler;
import vazkii.botania.common.core.helper.PlayerHelper;
import vazkii.botania.common.item.ModItems;
import vazkii.botania.common.lib.LibMisc;
import vazkii.botania.common.lib.LibObfuscation;
import vazkii.patchouli.client.book.gui.GuiBook;
import java.lang.invoke.MethodHandle;
import java.lang.reflect.Field;
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = LibMisc.MOD_ID)
@@ -91,11 +88,7 @@ public final class ClientTickHandler {
PlayerEntity player = Minecraft.getInstance().player;
if(player != null) {
if(PlayerHelper.hasHeldItemClass(player, ModItems.twigWand)) {
for(TileSignature sig : ImmutableList.copyOf(ManaNetworkHandler.instance.getAllCollectorsInWorld(Minecraft.getInstance().world))) {
if(!sig.isRemote())
continue;
TileEntity tile = sig.getTile();
for(TileEntity tile : ImmutableList.copyOf(ManaNetworkHandler.instance.getAllCollectorsInWorld(Minecraft.getInstance().world))) {
if(tile instanceof IManaCollector)
((IManaCollector) tile).onClientDisplayTick();
}
@@ -18,7 +18,6 @@ import vazkii.botania.api.internal.IManaNetwork;
import vazkii.botania.api.mana.ManaNetworkEvent;
import vazkii.botania.api.mana.ManaNetworkEvent.Action;
import vazkii.botania.api.mana.ManaNetworkEvent.ManaBlockType;
import vazkii.botania.api.mana.TileSignature;
import java.util.Comparator;
import java.util.HashSet;
@@ -31,12 +30,12 @@ public final class ManaNetworkHandler implements IManaNetwork {
public static final ManaNetworkHandler instance = new ManaNetworkHandler();
private final WeakHashMap<World, Set<TileSignature>> manaPools = new WeakHashMap<>();
private final WeakHashMap<World, Set<TileSignature>> manaCollectors = new WeakHashMap<>();
private final WeakHashMap<World, Set<TileEntity>> manaPools = new WeakHashMap<>();
private final WeakHashMap<World, Set<TileEntity>> manaCollectors = new WeakHashMap<>();
@SubscribeEvent
public void onNetworkEvent(ManaNetworkEvent event) {
Map<World, Set<TileSignature>> map = event.type == ManaBlockType.COLLECTOR ? manaCollectors : manaPools;
Map<World, Set<TileEntity>> map = event.type == ManaBlockType.COLLECTOR ? manaCollectors : manaPools;
if(event.action == Action.ADD)
add(map, event.tile);
else remove(map, event.tile);
@@ -70,47 +69,44 @@ public final class ManaNetworkHandler implements IManaNetwork {
return isIn(tile, manaPools);
}
private boolean isIn(TileEntity tile, Map<World, Set<TileSignature>> map) {
Set<TileSignature> set = map.get(tile.getWorld());
return set != null && set.contains(new TileSignature(tile, tile.getWorld().isRemote));
private boolean isIn(TileEntity tile, Map<World, Set<TileEntity>> map) {
Set<TileEntity> set = map.get(tile.getWorld());
return set != null && set.contains(tile);
}
private TileEntity getClosest(Set<TileSignature> tiles, BlockPos pos, boolean remoteCheck, int limit) {
private TileEntity getClosest(Set<TileEntity> tiles, BlockPos pos, boolean remoteCheck, int limit) {
return tiles.stream()
.filter(ts -> ts.isRemote() == remoteCheck)
.map(TileSignature::getTile)
.filter(t -> !t.isRemoved())
.filter(t -> t.getPos().distanceSq(pos) <= limit * limit)
.filter(t -> t.getWorld().isRemote == remoteCheck && !t.isRemoved()
&& t.getPos().distanceSq(pos) <= limit * limit)
.reduce(BinaryOperator.minBy(Comparator.comparing(t -> t.getPos().distanceSq(pos), Double::compare)))
.orElse(null);
}
private void remove(Map<World, Set<TileSignature>> map, TileEntity tile) {
private void remove(Map<World, Set<TileEntity>> map, TileEntity tile) {
World world = tile.getWorld();
if(!map.containsKey(world))
return;
map.get(world).remove(new TileSignature(tile, tile.getWorld().isRemote));
map.get(world).remove(tile);
}
private void add(Map<World, Set<TileSignature>> map, TileEntity tile) {
private void add(Map<World, Set<TileEntity>> map, TileEntity tile) {
World world = tile.getWorld();
map.putIfAbsent(world, new HashSet<>());
map.get(world).add(new TileSignature(tile, tile.getWorld().isRemote));
map.computeIfAbsent(world, k -> new HashSet<>()).add(tile);
}
@Override
public Set<TileSignature> getAllCollectorsInWorld(World world) {
public Set<TileEntity> getAllCollectorsInWorld(World world) {
return getAllInWorld(manaCollectors, world);
}
@Override
public Set<TileSignature> getAllPoolsInWorld(World world) {
public Set<TileEntity> getAllPoolsInWorld(World world) {
return getAllInWorld(manaPools, world);
}
private Set<TileSignature> getAllInWorld(Map<World, Set<TileSignature>> map, World world) {
private Set<TileEntity> getAllInWorld(Map<World, Set<TileEntity>> map, World world) {
return map.getOrDefault(world, new HashSet<>());
}