mark chunks for resend
This commit is contained in:
1 parent
da063aacb4
commit
4c031ba2ef
3 files changed
+64
-25
No files matched your search
@@ -64,7 +64,7 @@ public class CarpetServer // static for now - easier to handle all around the co
|
|||||||
{
|
{
|
||||||
TickSpeed.tick(server);
|
TickSpeed.tick(server);
|
||||||
HUDController.update_hud(server);
|
HUDController.update_hud(server);
|
||||||
scriptServer.events.tick();
|
scriptServer.tick();
|
||||||
|
|
||||||
//in case something happens
|
//in case something happens
|
||||||
CarpetSettings.impendingFillSkipUpdates = false;
|
CarpetSettings.impendingFillSkipUpdates = false;
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ import net.minecraft.util.registry.Registry;
|
|||||||
import net.minecraft.world.Heightmap;
|
import net.minecraft.world.Heightmap;
|
||||||
import net.minecraft.world.LightType;
|
import net.minecraft.world.LightType;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.world.biome.Biome;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
import net.minecraft.world.loot.context.LootContext;
|
import net.minecraft.world.loot.context.LootContext;
|
||||||
import net.minecraft.world.loot.context.LootContextParameters;
|
import net.minecraft.world.loot.context.LootContextParameters;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
@@ -926,6 +928,40 @@ public class CarpetExpression
|
|||||||
return (_c, _t) -> retval;
|
return (_c, _t) -> retval;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.expr.addLazyFunction("trace_block", -1, (c, t, lv) -> {
|
||||||
|
Value entityValue = lv.get(0).evalValue(c);
|
||||||
|
if (!(entityValue instanceof EntityValue))
|
||||||
|
throw new InternalExpressionException("First argument of trace_block should be an entity");
|
||||||
|
Entity e = ((EntityValue) entityValue).getEntity();
|
||||||
|
HitResult hitres = Tracer.traceEntityLook(e, 20);
|
||||||
|
switch (hitres.getType())
|
||||||
|
{
|
||||||
|
case MISS:
|
||||||
|
return (_c, _t) -> Value.NULL;
|
||||||
|
case BLOCK:
|
||||||
|
return (_c, _t) -> new BlockValue(null, e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() );
|
||||||
|
case ENTITY:
|
||||||
|
return (_c, _t) -> new EntityValue(((EntityHitResult)hitres).getEntity());
|
||||||
|
}
|
||||||
|
return LazyValue.NULL;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.expr.addLazyFunction("set_biome", -1, (c, t, lv) -> {
|
||||||
|
CarpetContext cc = (CarpetContext)c;
|
||||||
|
BlockValue.LocatorResult locator = BlockValue.fromParams(cc, lv, 0);
|
||||||
|
String biomeName = lv.get(locator.offset+0).evalValue(c).getString();
|
||||||
|
Biome biome = Registry.BIOME.get(new Identifier(biomeName));
|
||||||
|
byte biomeId = (byte) (Registry.BIOME.getRawId(biome) & 255);
|
||||||
|
ServerWorld world = cc.s.getWorld();
|
||||||
|
BlockPos pos = locator.block.getPos();
|
||||||
|
Chunk chunk = world.getChunk(pos);
|
||||||
|
chunk.getBiomeArray()[(pos.getX() & 15) | (pos.getZ() & 15) << 4] = biome;
|
||||||
|
chunk.setShouldSave(true);
|
||||||
|
//world.method_14178().markForUpdate(pos);
|
||||||
|
CarpetServer.scriptServer.markChunkForUpdate(world, pos);
|
||||||
|
return LazyValue.NULL;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1245,24 +1281,6 @@ public class CarpetExpression
|
|||||||
Value res = new NumericValue(item.getStack().getCount());
|
Value res = new NumericValue(item.getStack().getCount());
|
||||||
return (_c, _t) -> res;
|
return (_c, _t) -> res;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.expr.addLazyFunction("trace_block", -1, (c, t, lv) -> {
|
|
||||||
Value entityValue = lv.get(0).evalValue(c);
|
|
||||||
if (!(entityValue instanceof EntityValue))
|
|
||||||
throw new InternalExpressionException("First argument of trace_block should be an entity");
|
|
||||||
Entity e = ((EntityValue) entityValue).getEntity();
|
|
||||||
HitResult hitres = Tracer.traceEntityLook(e, 20);
|
|
||||||
switch (hitres.getType())
|
|
||||||
{
|
|
||||||
case MISS:
|
|
||||||
return (_c, _t) -> Value.NULL;
|
|
||||||
case BLOCK:
|
|
||||||
return (_c, _t) -> new BlockValue(null, e.getEntityWorld(), ((BlockHitResult)hitres).getBlockPos() );
|
|
||||||
case ENTITY:
|
|
||||||
return (_c, _t) -> new EntityValue(((EntityHitResult)hitres).getEntity());
|
|
||||||
}
|
|
||||||
return LazyValue.NULL;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -14,16 +14,16 @@ import com.mojang.brigadier.arguments.StringArgumentType;
|
|||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.tree.CommandNode;
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
|
import net.minecraft.client.network.packet.ChunkDataS2CPacket;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.server.world.ServerWorld;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.ChunkPos;
|
||||||
|
import net.minecraft.world.chunk.Chunk;
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.minecraft.server.command.CommandManager.argument;
|
import static net.minecraft.server.command.CommandManager.argument;
|
||||||
@@ -38,6 +38,7 @@ 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());
|
||||||
@@ -330,4 +331,24 @@ public class CarpetScriptServer
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void markChunkForUpdate(ServerWorld world, BlockPos pos)
|
||||||
|
{
|
||||||
|
modifiedChunks.add(Pair.of(world, new ChunkPos(pos)));
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user