still causes massive loadage if requested more than 2 chunks. Don't really know why. WIP I guess

This commit is contained in:
gnembon committed 2020-02-29 00:00:53 -04:00
1 parent e549c4df64
commit f43bd968bb
4 files changed
+158 -48

No files matched your search

@@ -1677,23 +1677,60 @@ public class CarpetExpression
this.expr.addLazyFunction("reset_chunk", -1, (c, t, lv) ->
{
CarpetContext cc = (CarpetContext)c;
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
List<ChunkPos> requestedChunks = new ArrayList<>();
if (lv.size() == 1)
{
//either one block or list of chunks
Value first = lv.get(0).evalValue(c);
if (first instanceof ListValue)
{
List<Value> listVal = ((ListValue) first).getItems();
int offset = 0;
BlockValue.LocatorResult locator = BlockValue.fromParamValues(cc, listVal, 0, false, false);
requestedChunks.add(new ChunkPos(locator.block.getPos()));
while (listVal.size() > locator.offset)
{
locator = BlockValue.fromParamValues(cc, listVal, locator.offset, false, false);
requestedChunks.add(new ChunkPos(locator.block.getPos()));
}
}
else
{
BlockValue.LocatorResult locator = BlockValue.fromParamValues(cc, Collections.singletonList(first), 0, false, false);
requestedChunks.add(new ChunkPos(locator.block.getPos()));
}
}
else
{
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
ChunkPos from = new ChunkPos(locator.block.getPos());
if (lv.size() > locator.offset)
{
locator = BlockValue.fromParams(cc, lv, locator.offset);
ChunkPos to = new ChunkPos(locator.block.getPos());
int xmax = Math.max(from.x, to.x);
int zmax = Math.max(from.z, to.z);
for (int x = Math.min(from.x, to.x); x <= xmax; x++) for (int z = Math.min(from.z, to.z); z <= zmax; z++)
{
requestedChunks.add(new ChunkPos(x,z));
}
CarpetSettings.LOG.error("Regenerating from "+Math.min(from.x, to.x)+", "+Math.min(from.z, to.z)+" to "+Math.max(from.x, to.x)+", "+Math.max(from.z, to.z));
}
else
{
requestedChunks.add(from);
}
}
ServerWorld world = cc.s.getWorld();
BlockPos pos = locator.block.getPos();
BlockPos temp = pos;
if (lv.size() > locator.offset )
{
BlockValue.LocatorResult locator2 = BlockValue.fromParams(cc, lv, locator.offset);
temp = locator2.block.getPos();
}
BlockPos toPos = temp;
((CarpetContext)c).s.getMinecraftServer().submitAndJoin( () ->
{
((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).regenerateChunkRegion(new ChunkPos(pos), new ChunkPos(toPos));
world.getChunk(pos);
this.forceChunkUpdate(pos, world);
((ThreadedAnvilChunkStorageInterface) world.getChunkManager().threadedAnvilChunkStorage).regenerateChunkRegion(requestedChunks);
for (ChunkPos chpos: requestedChunks)
if (world.getChunk(chpos.x, chpos.z, ChunkStatus.FULL, false) != null)
this.forceChunkUpdate(chpos.getCenterBlockPos(), world);
});
return LazyValue.NULL;
});
@@ -188,6 +188,56 @@ public class BlockValue extends Value
}
}
public static LocatorResult fromParamValues(CarpetContext c, List<Value> params, int offset, boolean acceptString, boolean optional)
{
try
{
Value v1 = params.get(0 + offset);
//add conditional from string name
if (optional && v1 instanceof NullValue)
{
return new LocatorResult(null, 1+offset);
}
if (acceptString && v1 instanceof StringValue)
{
return new LocatorResult(fromString(v1.getString()), 1+offset);
}
if (v1 instanceof BlockValue)
{
return new LocatorResult(((BlockValue) v1), 1+offset);
}
if (v1 instanceof ListValue)
{
List<Value> args = ((ListValue) v1).getItems();
int xpos = (int) NumericValue.asNumber(args.get(0)).getLong();
int ypos = (int) NumericValue.asNumber(args.get(1)).getLong();
int zpos = (int) NumericValue.asNumber(args.get(2)).getLong();
return new LocatorResult(
new BlockValue(
null,
c.s.getWorld(),
new BlockPos(c.origin.getX() + xpos, c.origin.getY() + ypos, c.origin.getZ() + zpos)
),
1+offset);
}
int xpos = (int) NumericValue.asNumber(v1).getLong();
int ypos = (int) NumericValue.asNumber( params.get(1 + offset)).getLong();
int zpos = (int) NumericValue.asNumber( params.get(2 + offset)).getLong();
return new LocatorResult(
new BlockValue(
null,
c.s.getWorld(),
new BlockPos(c.origin.getX() + xpos, c.origin.getY() + ypos, c.origin.getZ() + zpos)
),
3+offset
);
}
catch (IndexOutOfBoundsException e)
{
throw new InternalExpressionException("Block should be defined either by three coordinates, a block value, or a proper string");
}
}
public BlockState getBlockState()
{
if (blockState != null)