proper block updating
This commit is contained in:
1 parent
a62d4d73af
commit
6871ac027c
2 files changed
+12
-18
No files matched your search
@@ -949,16 +949,26 @@ public class CarpetExpression
|
|||||||
this.expr.addLazyFunction("set_biome", -1, (c, t, lv) -> {
|
this.expr.addLazyFunction("set_biome", -1, (c, t, lv) -> {
|
||||||
CarpetContext cc = (CarpetContext)c;
|
CarpetContext cc = (CarpetContext)c;
|
||||||
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
|
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
|
||||||
|
if (lv.size() == locator.offset)
|
||||||
|
throw new InternalExpressionException("set_biome needs a biome name as an argument");
|
||||||
String biomeName = lv.get(locator.offset+0).evalValue(c).getString();
|
String biomeName = lv.get(locator.offset+0).evalValue(c).getString();
|
||||||
Biome biome = Registry.BIOME.get(new Identifier(biomeName));
|
Biome biome = Registry.BIOME.get(new Identifier(biomeName));
|
||||||
|
if (biome == null)
|
||||||
|
throw new InternalExpressionException("Unknown biome: "+biomeName);
|
||||||
byte biomeId = (byte) (Registry.BIOME.getRawId(biome) & 255);
|
byte biomeId = (byte) (Registry.BIOME.getRawId(biome) & 255);
|
||||||
ServerWorld world = cc.s.getWorld();
|
ServerWorld world = cc.s.getWorld();
|
||||||
BlockPos pos = locator.block.getPos();
|
BlockPos pos = locator.block.getPos();
|
||||||
Chunk chunk = world.getChunk(pos);
|
Chunk chunk = world.getChunk(pos);
|
||||||
chunk.getBiomeArray()[(pos.getX() & 15) | (pos.getZ() & 15) << 4] = biome;
|
chunk.getBiomeArray()[(pos.getX() & 15) | (pos.getZ() & 15) << 4] = biome;
|
||||||
chunk.setShouldSave(true);
|
chunk.setShouldSave(true);
|
||||||
//world.method_14178().markForUpdate(pos);
|
for (int i = 0; i<16; i++)
|
||||||
CarpetServer.scriptServer.markChunkForUpdate(world, pos);
|
{
|
||||||
|
BlockPos section = new BlockPos((pos.getX()>>4 <<4)+8, 16*i, (pos.getZ()>>4 <<4)+8);
|
||||||
|
world.method_14178().markForUpdate(section);
|
||||||
|
world.method_14178().markForUpdate(section.east());
|
||||||
|
world.method_14178().markForUpdate(section.west());
|
||||||
|
world.method_14178().markForUpdate(section.north());
|
||||||
|
}
|
||||||
return LazyValue.NULL;
|
return LazyValue.NULL;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ public class CarpetScriptServer
|
|||||||
public boolean stopAll;
|
public boolean stopAll;
|
||||||
Set<String> holyMoly;
|
Set<String> holyMoly;
|
||||||
public CarpetEventServer events;
|
public CarpetEventServer events;
|
||||||
private Set<Pair<ServerWorld,ChunkPos>> modifiedChunks = new HashSet<>();
|
|
||||||
|
|
||||||
public static List<ModuleInterface> bundledModuleData = new ArrayList<ModuleInterface>(){{
|
public static List<ModuleInterface> bundledModuleData = new ArrayList<ModuleInterface>(){{
|
||||||
add(new CameraPathModule());
|
add(new CameraPathModule());
|
||||||
@@ -332,23 +331,8 @@ public class CarpetScriptServer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void markChunkForUpdate(ServerWorld world, BlockPos pos)
|
|
||||||
{
|
|
||||||
modifiedChunks.add(Pair.of(world, new ChunkPos(pos)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void tick()
|
public void tick()
|
||||||
{
|
{
|
||||||
for (Pair<ServerWorld,ChunkPos> tuple : modifiedChunks)
|
|
||||||
{
|
|
||||||
//ChunkDataS2CPacket
|
|
||||||
ServerWorld world = tuple.getLeft();
|
|
||||||
ChunkPos chpos = tuple.getRight();
|
|
||||||
Chunk chunk = world.getChunk(chpos.x, chpos.z);
|
|
||||||
//.....
|
|
||||||
|
|
||||||
}
|
|
||||||
modifiedChunks.clear();
|
|
||||||
events.tick();
|
events.tick();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user