chunk_tickets_api
This commit is contained in:
1 parent
6413c17657
commit
8b73d57a6b
4 files changed
+81
No files matched your search
@@ -0,0 +1,15 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSortedSet;
|
||||
import net.minecraft.server.world.ChunkTicket;
|
||||
import net.minecraft.server.world.ChunkTicketManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(ChunkTicketManager.class)
|
||||
public interface ChunkTicketManager_scarpetMixin
|
||||
{
|
||||
@Accessor
|
||||
Long2ObjectOpenHashMap<ObjectSortedSet<ChunkTicket<?>>> getTicketsByPosition();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import net.minecraft.server.world.ChunkTicketManager;
|
||||
import net.minecraft.server.world.ServerChunkManager;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(ServerChunkManager.class)
|
||||
public interface ServerChunkManager_scarpetMixin
|
||||
{
|
||||
@Accessor
|
||||
ChunkTicketManager getTicketManager();
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package carpet.script;
|
||||
import carpet.CarpetServer;
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.FeatureGenerator;
|
||||
import carpet.mixins.ChunkTicketManager_scarpetMixin;
|
||||
import carpet.mixins.ServerChunkManager_scarpetMixin;
|
||||
import carpet.script.Fluff.TriFunction;
|
||||
import carpet.script.exception.CarpetExpressionException;
|
||||
import carpet.script.exception.ExitStatement;
|
||||
@@ -24,6 +26,8 @@ import carpet.utils.Messenger;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectSortedSet;
|
||||
import net.minecraft.block.BarrierBlock;
|
||||
import net.minecraft.block.BedrockBlock;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -59,6 +63,7 @@ import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ChunkTicket;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
@@ -89,6 +94,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -855,6 +861,51 @@ public class CarpetExpression
|
||||
return (c_, t_) -> retval;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("chunk_tickets", -1, (c, t, lv) ->
|
||||
{
|
||||
ServerWorld world = ((CarpetContext) c).s.getWorld();
|
||||
Long2ObjectOpenHashMap<ObjectSortedSet<ChunkTicket<?>>> levelTickets = (
|
||||
(ChunkTicketManager_scarpetMixin) ((ServerChunkManager_scarpetMixin) world.method_14178())
|
||||
.getTicketManager()
|
||||
).getTicketsByPosition();
|
||||
List<Value> res = new ArrayList<>();
|
||||
if (lv.size() == 0)
|
||||
{
|
||||
for (long key : levelTickets.keySet())
|
||||
{
|
||||
ChunkPos chpos = new ChunkPos(key);
|
||||
for (ChunkTicket ticket : levelTickets.get(key))
|
||||
{
|
||||
res.add(ListValue.of(
|
||||
new StringValue(ticket.getType().toString()),
|
||||
new NumericValue(33 - ticket.getLevel()),
|
||||
new NumericValue(chpos.x),
|
||||
new NumericValue(chpos.z)
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
BlockValue.LocatorResult locatorResult = BlockValue.fromParams((CarpetContext) c, lv, 0);
|
||||
BlockPos pos = locatorResult.block.getPos();
|
||||
ObjectSortedSet<ChunkTicket<?>> tickets = levelTickets.get(new ChunkPos(pos).toLong());
|
||||
if (tickets != null)
|
||||
{
|
||||
for (ChunkTicket ticket : tickets)
|
||||
{
|
||||
res.add(ListValue.of(
|
||||
new StringValue(ticket.getType().toString()),
|
||||
new NumericValue(33 - ticket.getLevel())
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
res.sort(Comparator.comparing(e -> ((ListValue) e).getItems().get(1)).reversed());
|
||||
Value returnValue = ListValue.wrap(res);
|
||||
return (_c, _t) -> returnValue;
|
||||
});
|
||||
|
||||
this.expr.addLazyFunction("suffocates", -1, (c, t, lv) ->
|
||||
genericStateTest(c, "suffocates", lv, (s, p, w) -> new NumericValue(s.canSuffocate(w, p))));
|
||||
|
||||
|
||||
@@ -129,6 +129,8 @@
|
||||
"DamageTracker_scarpetEventMixin",
|
||||
"ServerPlayerEntity_scarpetEventMixin",
|
||||
"FallingBlockEntity_scarpetEventsMixin",
|
||||
"ChunkTicketManager_scarpetMixin",
|
||||
"ServerChunkManager_scarpetMixin",
|
||||
|
||||
|
||||
"PistonBlock_movableTEMixin",
|
||||
|
||||
Reference in new issue
Block a user