Run formatter
This commit is contained in:
parent
61c44a831b
commit
08258fd6ef
606 changed files with 13464 additions and 22975 deletions
|
@ -2,8 +2,7 @@ package WayofTime.bloodmagic.demonAura;
|
|||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
|
||||
public class PosXY implements Comparable<PosXY>
|
||||
{
|
||||
public class PosXY implements Comparable<PosXY> {
|
||||
public int x;
|
||||
public int y;
|
||||
|
||||
|
@ -16,20 +15,17 @@ public class PosXY implements Comparable<PosXY>
|
|||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(PosXY c)
|
||||
{
|
||||
public int compareTo(PosXY c) {
|
||||
return this.y == c.y ? this.x - c.x : this.y - c.y;
|
||||
}
|
||||
|
||||
public float getDistanceSquared(int x, int z)
|
||||
{
|
||||
public float getDistanceSquared(int x, int z) {
|
||||
float f = this.x - x;
|
||||
float f2 = this.y - z;
|
||||
return f * f + f2 * f2;
|
||||
}
|
||||
|
||||
public float getDistanceSquaredToChunkCoordinates(PosXY c)
|
||||
{
|
||||
public float getDistanceSquaredToChunkCoordinates(PosXY c) {
|
||||
return getDistanceSquared(c.x, c.y);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,20 +5,17 @@ import net.minecraft.world.chunk.Chunk;
|
|||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
public class WillChunk
|
||||
{
|
||||
public class WillChunk {
|
||||
PosXY loc;
|
||||
private short base;
|
||||
private DemonWillHolder currentWill = new DemonWillHolder();
|
||||
private WeakReference<Chunk> chunkRef;
|
||||
|
||||
public WillChunk(PosXY loc)
|
||||
{
|
||||
public WillChunk(PosXY loc) {
|
||||
this.loc = loc;
|
||||
}
|
||||
|
||||
public WillChunk(Chunk chunk, short base, DemonWillHolder currentWill)
|
||||
{
|
||||
public WillChunk(Chunk chunk, short base, DemonWillHolder currentWill) {
|
||||
this.loc = new PosXY(chunk.x, chunk.z);
|
||||
this.chunkRef = new WeakReference(chunk);
|
||||
this.base = base;
|
||||
|
|
|
@ -2,25 +2,21 @@ package WayofTime.bloodmagic.demonAura;
|
|||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class WillWorld
|
||||
{
|
||||
public class WillWorld {
|
||||
int dim;
|
||||
ConcurrentHashMap<PosXY, WillChunk> willChunks = new ConcurrentHashMap<PosXY, WillChunk>();
|
||||
|
||||
// private static ConcurrentHashMap<PosXY, AspectList> nodeTickets = new ConcurrentHashMap();
|
||||
|
||||
public WillWorld(int dim)
|
||||
{
|
||||
public WillWorld(int dim) {
|
||||
this.dim = dim;
|
||||
}
|
||||
|
||||
public WillChunk getWillChunkAt(int x, int y)
|
||||
{
|
||||
public WillChunk getWillChunkAt(int x, int y) {
|
||||
return getWillChunkAt(new PosXY(x, y));
|
||||
}
|
||||
|
||||
public WillChunk getWillChunkAt(PosXY loc)
|
||||
{
|
||||
public WillChunk getWillChunkAt(PosXY loc) {
|
||||
return this.willChunks.get(loc);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,64 +11,52 @@ import javax.annotation.Nullable;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class WorldDemonWillHandler
|
||||
{
|
||||
static ConcurrentHashMap<Integer, WillWorld> containedWills = new ConcurrentHashMap<Integer, WillWorld>();
|
||||
public class WorldDemonWillHandler {
|
||||
public static ConcurrentHashMap<Integer, CopyOnWriteArrayList<PosXY>> dirtyChunks = new ConcurrentHashMap<Integer, CopyOnWriteArrayList<PosXY>>();
|
||||
static ConcurrentHashMap<Integer, WillWorld> containedWills = new ConcurrentHashMap<Integer, WillWorld>();
|
||||
|
||||
@Nullable
|
||||
public static DemonWillHolder getWillHolder(int dim, int x, int y)
|
||||
{
|
||||
public static DemonWillHolder getWillHolder(int dim, int x, int y) {
|
||||
WillChunk chunk = getWillChunk(dim, x, y);
|
||||
if (chunk != null)
|
||||
{
|
||||
if (chunk != null) {
|
||||
return chunk.getCurrentWill();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static DemonWillHolder getWillHolder(World world, BlockPos pos)
|
||||
{
|
||||
public static DemonWillHolder getWillHolder(World world, BlockPos pos) {
|
||||
return getWillHolder(world.provider.getDimension(), pos.getX() >> 4, pos.getZ() >> 4);
|
||||
}
|
||||
|
||||
public static WillWorld getWillWorld(int dim)
|
||||
{
|
||||
public static WillWorld getWillWorld(int dim) {
|
||||
return containedWills.get(dim);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static WillChunk getWillChunk(int dim, int x, int y)
|
||||
{
|
||||
if (!containedWills.containsKey(dim))
|
||||
{
|
||||
public static WillChunk getWillChunk(int dim, int x, int y) {
|
||||
if (!containedWills.containsKey(dim)) {
|
||||
addWillWorld(dim);
|
||||
}
|
||||
|
||||
return (containedWills.get(dim)).getWillChunkAt(x, y);
|
||||
}
|
||||
|
||||
public static void addWillWorld(int dim)
|
||||
{
|
||||
if (!containedWills.containsKey(dim))
|
||||
{
|
||||
public static void addWillWorld(int dim) {
|
||||
if (!containedWills.containsKey(dim)) {
|
||||
containedWills.put(dim, new WillWorld(dim));
|
||||
BloodMagicAPI.logger.info("Creating demon will cache for world " + dim);
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeWillWorld(int dim)
|
||||
{
|
||||
public static void removeWillWorld(int dim) {
|
||||
containedWills.remove(dim);
|
||||
BloodMagicAPI.logger.info("Removing demon will cache for world " + dim);
|
||||
}
|
||||
|
||||
public static void addWillChunk(int dim, Chunk chunk, short base, DemonWillHolder currentWill)
|
||||
{
|
||||
public static void addWillChunk(int dim, Chunk chunk, short base, DemonWillHolder currentWill) {
|
||||
WillWorld aw = containedWills.get(dim);
|
||||
if (aw == null)
|
||||
{
|
||||
if (aw == null) {
|
||||
aw = new WillWorld(dim);
|
||||
}
|
||||
aw.getWillChunks().put(new PosXY(chunk.x, chunk.z), new WillChunk(chunk, base, currentWill));
|
||||
|
@ -76,31 +64,25 @@ public class WorldDemonWillHandler
|
|||
containedWills.put(dim, aw);
|
||||
}
|
||||
|
||||
public static void removeWillChunk(int dim, int x, int y)
|
||||
{
|
||||
public static void removeWillChunk(int dim, int x, int y) {
|
||||
WillWorld aw = containedWills.get(dim);
|
||||
if (aw != null)
|
||||
{
|
||||
if (aw != null) {
|
||||
WillChunk chunk = aw.getWillChunks().remove(new PosXY(x, y));
|
||||
if (chunk != null)
|
||||
{
|
||||
if (chunk != null) {
|
||||
markChunkAsDirty(chunk, dim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static EnumDemonWillType getHighestDemonWillType(World world, BlockPos pos)
|
||||
{
|
||||
public static EnumDemonWillType getHighestDemonWillType(World world, BlockPos pos) {
|
||||
double currentMax = 0;
|
||||
EnumDemonWillType currentHighest = EnumDemonWillType.DEFAULT;
|
||||
|
||||
WillChunk willChunk = getWillChunk(world, pos);
|
||||
|
||||
DemonWillHolder currentWill = willChunk.getCurrentWill();
|
||||
for (EnumDemonWillType type : EnumDemonWillType.values())
|
||||
{
|
||||
if (currentWill.getWill(type) > currentMax)
|
||||
{
|
||||
for (EnumDemonWillType type : EnumDemonWillType.values()) {
|
||||
if (currentWill.getWill(type) > currentMax) {
|
||||
currentMax = currentWill.getWill(type);
|
||||
currentHighest = type;
|
||||
}
|
||||
|
@ -109,14 +91,12 @@ public class WorldDemonWillHandler
|
|||
return currentHighest;
|
||||
}
|
||||
|
||||
public static double drainWill(World world, BlockPos pos, EnumDemonWillType type, double amount, boolean doDrain)
|
||||
{
|
||||
public static double drainWill(World world, BlockPos pos, EnumDemonWillType type, double amount, boolean doDrain) {
|
||||
WillChunk willChunk = getWillChunk(world, pos);
|
||||
|
||||
DemonWillHolder currentWill = willChunk.getCurrentWill();
|
||||
double drain = Math.min(currentWill.getWill(type), amount);
|
||||
if (!doDrain)
|
||||
{
|
||||
if (!doDrain) {
|
||||
return drain;
|
||||
}
|
||||
|
||||
|
@ -126,14 +106,12 @@ public class WorldDemonWillHandler
|
|||
return drain;
|
||||
}
|
||||
|
||||
public static double fillWillToMaximum(World world, BlockPos pos, EnumDemonWillType type, double amount, double max, boolean doFill)
|
||||
{
|
||||
public static double fillWillToMaximum(World world, BlockPos pos, EnumDemonWillType type, double amount, double max, boolean doFill) {
|
||||
WillChunk willChunk = getWillChunk(world, pos);
|
||||
|
||||
DemonWillHolder currentWill = willChunk.getCurrentWill();
|
||||
double fill = Math.min(amount, max - currentWill.getWill(type));
|
||||
if (!doFill || fill <= 0)
|
||||
{
|
||||
if (!doFill || fill <= 0) {
|
||||
return fill > 0 ? fill : 0;
|
||||
}
|
||||
|
||||
|
@ -143,13 +121,11 @@ public class WorldDemonWillHandler
|
|||
return fill;
|
||||
}
|
||||
|
||||
public static double fillWill(World world, BlockPos pos, EnumDemonWillType type, double amount, boolean doFill)
|
||||
{
|
||||
public static double fillWill(World world, BlockPos pos, EnumDemonWillType type, double amount, boolean doFill) {
|
||||
WillChunk willChunk = getWillChunk(world, pos);
|
||||
|
||||
DemonWillHolder currentWill = willChunk.getCurrentWill();
|
||||
if (!doFill)
|
||||
{
|
||||
if (!doFill) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
|
@ -159,11 +135,9 @@ public class WorldDemonWillHandler
|
|||
return amount;
|
||||
}
|
||||
|
||||
public static WillChunk getWillChunk(World world, BlockPos pos)
|
||||
{
|
||||
public static WillChunk getWillChunk(World world, BlockPos pos) {
|
||||
WillChunk willChunk = getWillChunk(world.provider.getDimension(), pos.getX() >> 4, pos.getZ() >> 4);
|
||||
if (willChunk == null)
|
||||
{
|
||||
if (willChunk == null) {
|
||||
Chunk chunk = world.getChunkFromBlockCoords(pos);
|
||||
generateWill(chunk);
|
||||
|
||||
|
@ -173,12 +147,10 @@ public class WorldDemonWillHandler
|
|||
return willChunk;
|
||||
}
|
||||
|
||||
public static double getCurrentWill(World world, BlockPos pos, EnumDemonWillType type)
|
||||
{
|
||||
public static double getCurrentWill(World world, BlockPos pos, EnumDemonWillType type) {
|
||||
WillChunk willChunk = getWillChunk(world, pos);
|
||||
|
||||
if (willChunk == null)
|
||||
{
|
||||
if (willChunk == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -186,26 +158,21 @@ public class WorldDemonWillHandler
|
|||
return currentWill.getWill(type);
|
||||
}
|
||||
|
||||
private static void markChunkAsDirty(WillChunk chunk, int dim)
|
||||
{
|
||||
if (chunk.isModified())
|
||||
{
|
||||
private static void markChunkAsDirty(WillChunk chunk, int dim) {
|
||||
if (chunk.isModified()) {
|
||||
return;
|
||||
}
|
||||
PosXY pos = new PosXY(chunk.loc.x, chunk.loc.y);
|
||||
if (!dirtyChunks.containsKey(dim))
|
||||
{
|
||||
if (!dirtyChunks.containsKey(dim)) {
|
||||
dirtyChunks.put(dim, new CopyOnWriteArrayList<PosXY>());
|
||||
}
|
||||
CopyOnWriteArrayList<PosXY> dc = dirtyChunks.get(dim);
|
||||
if (!dc.contains(pos))
|
||||
{
|
||||
if (!dc.contains(pos)) {
|
||||
dc.add(pos);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateWill(Chunk chunk)
|
||||
{
|
||||
public static void generateWill(Chunk chunk) {
|
||||
addWillChunk(chunk.getWorld().provider.getDimension(), chunk, (short) 1, new DemonWillHolder());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue