Attempt to fix 1.16.3 branch's issues on the repository

Added the original 'wayoftime' folder back, so see if that fixed the multiple folder issue.
This commit is contained in:
WayofTime 2020-10-29 15:50:03 -04:00
parent 6b4145a67c
commit 9fa68e86ae
224 changed files with 24047 additions and 0 deletions

View file

@ -0,0 +1,76 @@
package wayoftime.bloodmagic.demonaura;
import org.apache.commons.lang3.builder.ToStringBuilder;
public class PosXY implements Comparable<PosXY>
{
public int x;
public int y;
public PosXY()
{
}
public PosXY(int x, int y)
{
this.x = x;
this.y = y;
}
@Override
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)
{
float f = this.x - x;
float f2 = this.y - z;
return f * f + f2 * f2;
}
public float getDistanceSquaredToChunkCoordinates(PosXY c)
{
return getDistanceSquared(c.x, c.y);
}
public void setX(int x)
{
this.x = x;
}
public void setY(int y)
{
this.y = y;
}
@Override
public String toString()
{
return new ToStringBuilder(this).append("x", x).append("y", y).toString();
}
@Override
public boolean equals(Object o)
{
if (this == o)
return true;
if (!(o instanceof PosXY))
return false;
PosXY posXY = (PosXY) o;
if (x != posXY.x)
return false;
return y == posXY.y;
}
@Override
public int hashCode()
{
int result = x;
result = 31 * result + y;
return result;
}
}

View file

@ -0,0 +1,72 @@
package wayoftime.bloodmagic.demonaura;
import java.lang.ref.WeakReference;
import net.minecraft.world.chunk.Chunk;
import wayoftime.bloodmagic.will.DemonWillHolder;
public class WillChunk
{
PosXY loc;
private short base;
private DemonWillHolder currentWill = new DemonWillHolder();
private WeakReference<Chunk> chunkRef;
public WillChunk(PosXY loc)
{
this.loc = loc;
}
public WillChunk(Chunk chunk, short base, DemonWillHolder currentWill)
{
this.loc = new PosXY(chunk.getPos().x, chunk.getPos().z);
this.chunkRef = new WeakReference(chunk);
this.base = base;
this.currentWill = currentWill;
}
public boolean isModified()
{
return (this.chunkRef != null) && (this.chunkRef.get() != null) && this.chunkRef.get().isModified();
}
public PosXY getLoc()
{
return loc;
}
public void setLoc(PosXY loc)
{
this.loc = loc;
}
public short getBase()
{
return base;
}
public void setBase(short base)
{
this.base = base;
}
public DemonWillHolder getCurrentWill()
{
return currentWill;
}
public void setCurrentWill(DemonWillHolder currentWill)
{
this.currentWill = currentWill;
}
public WeakReference<Chunk> getChunkRef()
{
return chunkRef;
}
public void setChunkRef(WeakReference<Chunk> chunkRef)
{
this.chunkRef = chunkRef;
}
}

View file

@ -0,0 +1,49 @@
package wayoftime.bloodmagic.demonaura;
import java.util.concurrent.ConcurrentHashMap;
import net.minecraft.util.ResourceLocation;
public class WillWorld
{
// TODO: It was noted I may need to use RegistryKey<World> instead.
ResourceLocation dim;
ConcurrentHashMap<PosXY, WillChunk> willChunks = new ConcurrentHashMap<>();
// private static ConcurrentHashMap<PosXY, AspectList> nodeTickets = new ConcurrentHashMap();
public WillWorld(ResourceLocation resourceLocation)
{
this.dim = resourceLocation;
}
public WillChunk getWillChunkAt(int x, int y)
{
return getWillChunkAt(new PosXY(x, y));
}
public WillChunk getWillChunkAt(PosXY loc)
{
return this.willChunks.get(loc);
}
public ConcurrentHashMap<PosXY, WillChunk> getWillChunks()
{
return willChunks;
}
public void setWillChunks(ConcurrentHashMap<PosXY, WillChunk> willChunks)
{
this.willChunks = willChunks;
}
// public static ConcurrentHashMap<PosXY, AspectList> getNodeTickets()
// {
// return nodeTickets;
// }
//
// public static void setNodeTickets(ConcurrentHashMap<PosXY, AspectList> nodeTickets)
// {
// nodeTickets = nodeTickets;
// }
}

View file

@ -0,0 +1,218 @@
package wayoftime.bloodmagic.demonaura;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.annotation.Nullable;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import wayoftime.bloodmagic.util.BMLog;
import wayoftime.bloodmagic.will.DemonWillHolder;
import wayoftime.bloodmagic.will.EnumDemonWillType;
public class WorldDemonWillHandler
{
public static ConcurrentHashMap<ResourceLocation, CopyOnWriteArrayList<PosXY>> dirtyChunks = new ConcurrentHashMap<>();
static ConcurrentHashMap<ResourceLocation, WillWorld> containedWills = new ConcurrentHashMap<>();
@Nullable
public static DemonWillHolder getWillHolder(ResourceLocation resourceLocation, int x, int y)
{
WillChunk chunk = getWillChunk(resourceLocation, x, y);
if (chunk != null)
{
return chunk.getCurrentWill();
}
return null;
}
public static DemonWillHolder getWillHolder(World world, BlockPos pos)
{
return getWillHolder(getDimensionResourceLocation(world), pos.getX() >> 4, pos.getZ() >> 4);
}
public static WillWorld getWillWorld(int dim)
{
return containedWills.get(dim);
}
@Nullable
public static WillChunk getWillChunk(ResourceLocation resourceLocation, int x, int y)
{
if (!containedWills.containsKey(resourceLocation))
{
addWillWorld(resourceLocation);
}
return (containedWills.get(resourceLocation)).getWillChunkAt(x, y);
}
public static void addWillWorld(ResourceLocation resourceLocation)
{
if (!containedWills.containsKey(resourceLocation))
{
containedWills.put(resourceLocation, new WillWorld(resourceLocation));
BMLog.DEBUG.info("Creating demon will cache for world {}", resourceLocation);
}
}
public static void removeWillWorld(int dim)
{
containedWills.remove(dim);
BMLog.DEBUG.info("Removing demon will cache for world {}", dim);
}
public static void addWillChunk(ResourceLocation resourceLocation, Chunk chunk, short base, DemonWillHolder currentWill)
{
WillWorld aw = containedWills.get(resourceLocation);
if (aw == null)
{
aw = new WillWorld(resourceLocation);
}
aw.getWillChunks().put(new PosXY(chunk.getPos().x, chunk.getPos().z), new WillChunk(chunk, base, currentWill));
containedWills.put(resourceLocation, aw);
}
public static void removeWillChunk(ResourceLocation resourceLocation, int x, int y)
{
WillWorld aw = containedWills.get(resourceLocation);
if (aw != null)
{
WillChunk chunk = aw.getWillChunks().remove(new PosXY(x, y));
if (chunk != null)
{
markChunkAsDirty(chunk, resourceLocation);
}
}
}
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)
{
currentMax = currentWill.getWill(type);
currentHighest = type;
}
}
return currentHighest;
}
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)
{
return drain;
}
drain = currentWill.drainWill(type, drain);
markChunkAsDirty(willChunk, getDimensionResourceLocation(world));
return drain;
}
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)
{
return fill > 0 ? fill : 0;
}
fill = currentWill.addWill(type, amount, max);
markChunkAsDirty(willChunk, getDimensionResourceLocation(world));
return fill;
}
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)
{
return amount;
}
currentWill.addWill(type, amount);
markChunkAsDirty(willChunk, getDimensionResourceLocation(world));
return amount;
}
public static WillChunk getWillChunk(World world, BlockPos pos)
{
WillChunk willChunk = getWillChunk(getDimensionResourceLocation(world), pos.getX() >> 4, pos.getZ() >> 4);
if (willChunk == null)
{
Chunk chunk = world.getChunk(pos.getX() >> 4, pos.getZ() >> 4);
generateWill(chunk);
willChunk = getWillChunk(getDimensionResourceLocation(world), pos.getX() >> 4, pos.getZ() >> 4);
}
return willChunk;
}
public static double getCurrentWill(World world, BlockPos pos, EnumDemonWillType type)
{
WillChunk willChunk = getWillChunk(world, pos);
if (willChunk == null)
{
return 0;
}
DemonWillHolder currentWill = willChunk.getCurrentWill();
return currentWill.getWill(type);
}
private static void markChunkAsDirty(WillChunk chunk, ResourceLocation resourceLocation)
{
if (chunk.isModified())
{
return;
}
PosXY pos = new PosXY(chunk.loc.x, chunk.loc.y);
if (!dirtyChunks.containsKey(resourceLocation))
{
dirtyChunks.put(resourceLocation, new CopyOnWriteArrayList<>());
}
CopyOnWriteArrayList<PosXY> dc = dirtyChunks.get(resourceLocation);
if (!dc.contains(pos))
{
dc.add(pos);
}
}
public static void generateWill(Chunk chunk)
{
addWillChunk(chunk.getWorld().getDimensionKey().getLocation(), chunk, (short) 1, new DemonWillHolder());
}
private static ResourceLocation getDimensionResourceLocation(World world)
{
return world.getDimensionKey().getLocation();
}
}