mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-11-22 19:58:34 +01:00
some more caching for some more performance improvements!
This commit is contained in:
parent
5bee48bdfc
commit
8770ac6cd7
2 changed files with 38 additions and 8 deletions
|
@ -152,10 +152,11 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
||||||
public BlockPos getLowestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) {
|
public BlockPos getLowestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) {
|
||||||
var lowestAmount = new MutableInt(Integer.MAX_VALUE);
|
var lowestAmount = new MutableInt(Integer.MAX_VALUE);
|
||||||
var lowestSpot = new MutableObject<BlockPos>();
|
var lowestSpot = new MutableObject<BlockPos>();
|
||||||
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> {
|
Helper.getAuraChunksWithSpotsInArea(level, pos, radius, c -> {
|
||||||
if (drainSpot < lowestAmount.intValue()) {
|
var spot = c.getLowestAndHighestSpots(pos, radius)[0];
|
||||||
lowestAmount.setValue(drainSpot);
|
if (spot.getRight() < lowestAmount.intValue()) {
|
||||||
lowestSpot.setValue(blockPos);
|
lowestAmount.setValue(spot.getRight());
|
||||||
|
lowestSpot.setValue(spot.getLeft());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var lowest = lowestSpot.getValue();
|
var lowest = lowestSpot.getValue();
|
||||||
|
@ -168,10 +169,11 @@ public class InternalHooks implements NaturesAuraAPI.IInternalHooks {
|
||||||
public BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) {
|
public BlockPos getHighestAuraDrainSpot(Level level, BlockPos pos, int radius, BlockPos defaultSpot) {
|
||||||
var highestAmount = new MutableInt(Integer.MIN_VALUE);
|
var highestAmount = new MutableInt(Integer.MIN_VALUE);
|
||||||
var highestSpot = new MutableObject<BlockPos>();
|
var highestSpot = new MutableObject<BlockPos>();
|
||||||
this.getAuraSpotsInArea(level, pos, radius, (blockPos, drainSpot) -> {
|
Helper.getAuraChunksWithSpotsInArea(level, pos, radius, c -> {
|
||||||
if (drainSpot > highestAmount.intValue()) {
|
var spot = c.getLowestAndHighestSpots(pos, radius)[1];
|
||||||
highestAmount.setValue(drainSpot);
|
if (spot.getRight() > highestAmount.intValue()) {
|
||||||
highestSpot.setValue(blockPos);
|
highestAmount.setValue(spot.getRight());
|
||||||
|
highestSpot.setValue(spot.getLeft());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var highest = highestSpot.getValue();
|
var highest = highestSpot.getValue();
|
||||||
|
|
|
@ -20,6 +20,7 @@ import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraft.world.level.chunk.LevelChunk;
|
import net.minecraft.world.level.chunk.LevelChunk;
|
||||||
import org.apache.commons.lang3.mutable.MutableInt;
|
import org.apache.commons.lang3.mutable.MutableInt;
|
||||||
|
import org.apache.commons.lang3.mutable.MutableObject;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -34,6 +35,7 @@ public class AuraChunk implements IAuraChunk {
|
||||||
private final IAuraType type;
|
private final IAuraType type;
|
||||||
private final Map<BlockPos, MutableInt> drainSpots = new ConcurrentHashMap<>();
|
private final Map<BlockPos, MutableInt> drainSpots = new ConcurrentHashMap<>();
|
||||||
private final Table<BlockPos, Integer, Pair<Integer, Integer>> auraAndSpotAmountCache = HashBasedTable.create();
|
private final Table<BlockPos, Integer, Pair<Integer, Integer>> auraAndSpotAmountCache = HashBasedTable.create();
|
||||||
|
private final Table<BlockPos, Integer, Pair<BlockPos, Integer>[]> limitSpotCache = HashBasedTable.create();
|
||||||
private final List<IDrainSpotEffect> effects = new ArrayList<>();
|
private final List<IDrainSpotEffect> effects = new ArrayList<>();
|
||||||
private boolean needsSync;
|
private boolean needsSync;
|
||||||
|
|
||||||
|
@ -143,6 +145,7 @@ public class AuraChunk implements IAuraChunk {
|
||||||
this.chunk.setUnsaved(true);
|
this.chunk.setUnsaved(true);
|
||||||
this.needsSync = true;
|
this.needsSync = true;
|
||||||
this.auraAndSpotAmountCache.clear();
|
this.auraAndSpotAmountCache.clear();
|
||||||
|
this.limitSpotCache.clear();
|
||||||
this.addOrRemoveAsActive();
|
this.addOrRemoveAsActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +197,31 @@ public class AuraChunk implements IAuraChunk {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pair<BlockPos, Integer>[] getLowestAndHighestSpots(BlockPos pos, int radius) {
|
||||||
|
var ret = this.limitSpotCache.get(pos, radius);
|
||||||
|
if (ret == null) {
|
||||||
|
var lowestSpot = new MutableObject<BlockPos>();
|
||||||
|
var highestSpot = new MutableObject<BlockPos>();
|
||||||
|
var lowestAmount = new MutableInt(Integer.MAX_VALUE);
|
||||||
|
var highestAmount = new MutableInt(Integer.MIN_VALUE);
|
||||||
|
this.getSpots(pos, radius, (p, i) -> {
|
||||||
|
if (i > highestAmount.intValue()) {
|
||||||
|
highestAmount.setValue(i);
|
||||||
|
highestSpot.setValue(p);
|
||||||
|
}
|
||||||
|
if (i < lowestAmount.intValue()) {
|
||||||
|
lowestAmount.setValue(i);
|
||||||
|
lowestSpot.setValue(p);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ret = new Pair[]{
|
||||||
|
Pair.of(lowestSpot.getValue(), lowestAmount.intValue()),
|
||||||
|
Pair.of(highestSpot.getValue(), highestAmount.intValue())};
|
||||||
|
this.limitSpotCache.put(pos, radius, ret);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public void getActiveEffectIcons(Player player, Map<ResourceLocation, Tuple<ItemStack, Boolean>> icons) {
|
public void getActiveEffectIcons(Player player, Map<ResourceLocation, Tuple<ItemStack, Boolean>> icons) {
|
||||||
for (var effect : this.effects) {
|
for (var effect : this.effects) {
|
||||||
var alreadyThere = icons.get(effect.getName());
|
var alreadyThere = icons.get(effect.getName());
|
||||||
|
|
Loading…
Reference in a new issue