diff --git a/src/main/java/carpet/CarpetServer.java b/src/main/java/carpet/CarpetServer.java
index 2b9aa05e..27fa84e1 100644
--- a/src/main/java/carpet/CarpetServer.java
+++ b/src/main/java/carpet/CarpetServer.java
@@ -26,6 +26,7 @@ import carpet.script.CarpetScriptServer;
import carpet.api.settings.SettingsManager;
import carpet.logging.HUDController;
import carpet.script.external.Carpet;
+import carpet.script.external.Vanilla;
import carpet.script.utils.ParticleParser;
import carpet.utils.MobAI;
import carpet.utils.SpawnReporter;
@@ -35,6 +36,7 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandBuildContext;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
+import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.commands.PerfCommand;
import net.minecraft.server.level.ServerPlayer;
@@ -164,16 +166,25 @@ public class CarpetServer // static for now - easier to handle all around the co
{
ServerNetworkHandler.onPlayerJoin(player);
LoggerRegistry.playerConnected(player);
- scriptServer.onPlayerJoin(player);
extensions.forEach(e -> e.onPlayerLoggedIn(player));
-
+ scriptServer.onPlayerJoin(player);
}
+ @Deprecated(forRemoval = true)
public static void onPlayerLoggedOut(ServerPlayer player)
+ {
+ onPlayerLoggedOut(player, Component.translatable("multiplayer.player.left"));
+ }
+ public static void onPlayerLoggedOut(ServerPlayer player, Component reason)
{
ServerNetworkHandler.onPlayerLoggedOut(player);
LoggerRegistry.playerDisconnected(player);
extensions.forEach(e -> e.onPlayerLoggedOut(player));
+ // first case client, second case server
+ CarpetScriptServer runningScriptServer = (player.getServer() == null) ? scriptServer : Vanilla.MinecraftServer_getScriptServer(player.getServer());
+ if (runningScriptServer != null && !runningScriptServer.stopAll) {
+ runningScriptServer.onPlayerLoggedOut(player, reason);
+ }
}
public static void clientPreClosing()
@@ -189,6 +200,11 @@ public class CarpetServer // static for now - easier to handle all around the co
if (minecraft_server != null)
{
if (scriptServer != null) scriptServer.onClose();
+ // this is a mess, will cleanip onlly when global reference is gone
+ if (!Vanilla.MinecraftServer_getScriptServer(server).stopAll) {
+ Vanilla.MinecraftServer_getScriptServer(server).onClose();
+ }
+
scriptServer = null;
ServerNetworkHandler.close();
diff --git a/src/main/java/carpet/fakes/ServerChunkManagerInterface.java b/src/main/java/carpet/fakes/ServerChunkManagerInterface.java
deleted file mode 100644
index a65de7bf..00000000
--- a/src/main/java/carpet/fakes/ServerChunkManagerInterface.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package carpet.fakes;
-
-import net.minecraft.server.level.DistanceManager;
-
-public interface ServerChunkManagerInterface
-{
- DistanceManager getCMTicketManager();
-}
diff --git a/src/main/java/carpet/mixins/BlockItem_scarpetEventMixin.java b/src/main/java/carpet/mixins/BlockItem_scarpetEventMixin.java
index 2b34ecac..2a2d43bd 100644
--- a/src/main/java/carpet/mixins/BlockItem_scarpetEventMixin.java
+++ b/src/main/java/carpet/mixins/BlockItem_scarpetEventMixin.java
@@ -29,9 +29,9 @@ public class BlockItem_scarpetEventMixin
}
@Inject(method = "placeBlock", at = @At("HEAD"), cancellable = true)
- private void beforePlacement(BlockPlaceContext blockPlaceContext, BlockState blockState, CallbackInfoReturnable cir) {
- if (blockPlaceContext.getPlayer() instanceof ServerPlayer && PLAYER_PLACING_BLOCK.isNeeded()) {
- if (PLAYER_PLACING_BLOCK.onBlockPlaced((ServerPlayer) blockPlaceContext.getPlayer(), blockPlaceContext.getClickedPos(), blockPlaceContext.getHand(), blockPlaceContext.getItemInHand())) {
+ private void beforePlacement(BlockPlaceContext context, BlockState placementState, CallbackInfoReturnable cir) {
+ if (context.getPlayer() instanceof ServerPlayer && PLAYER_PLACING_BLOCK.isNeeded()) {
+ if (PLAYER_PLACING_BLOCK.onBlockPlaced((ServerPlayer) context.getPlayer(), context.getClickedPos(), context.getHand(), context.getItemInHand())) {
cir.setReturnValue(false);
cir.cancel();
}
diff --git a/src/main/java/carpet/mixins/PlayerList_coreMixin.java b/src/main/java/carpet/mixins/PlayerList_coreMixin.java
index 27f095ae..e547f6b6 100644
--- a/src/main/java/carpet/mixins/PlayerList_coreMixin.java
+++ b/src/main/java/carpet/mixins/PlayerList_coreMixin.java
@@ -9,8 +9,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import static carpet.script.CarpetEventServer.Event.PLAYER_CONNECTS;
-
@Mixin(PlayerList.class)
public class PlayerList_coreMixin
{
@@ -19,6 +17,5 @@ public class PlayerList_coreMixin
private void onPlayerConnected(Connection connection, ServerPlayer player, CallbackInfo ci)
{
CarpetServer.onPlayerLoggedIn(player);
- PLAYER_CONNECTS.onPlayerEvent(player);
}
}
diff --git a/src/main/java/carpet/mixins/PlayerList_scarpetEventsMixin.java b/src/main/java/carpet/mixins/PlayerList_scarpetEventsMixin.java
index 5ca7afb4..99915f05 100644
--- a/src/main/java/carpet/mixins/PlayerList_scarpetEventsMixin.java
+++ b/src/main/java/carpet/mixins/PlayerList_scarpetEventsMixin.java
@@ -1,10 +1,13 @@
package carpet.mixins;
-import carpet.CarpetServer;
import carpet.fakes.ServerPlayerInterface;
+import carpet.script.external.Vanilla;
+import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
+import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -15,6 +18,8 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_RESPAWNS;
@Mixin(PlayerList.class)
public class PlayerList_scarpetEventsMixin
{
+ @Shadow @Final private MinecraftServer server;
+
@Inject(method = "respawn", at = @At("HEAD"))
private void onRespawn(ServerPlayer player, boolean olive, CallbackInfoReturnable cir)
{
@@ -33,6 +38,6 @@ public class PlayerList_scarpetEventsMixin
@Inject(method = "reloadResources", at = @At("HEAD"))
private void reloadCommands(CallbackInfo ci)
{
- CarpetServer.scriptServer.reAddCommands();
+ Vanilla.MinecraftServer_getScriptServer(server).reAddCommands();
}
}
diff --git a/src/main/java/carpet/mixins/ServerChunkCacheMixin.java b/src/main/java/carpet/mixins/ServerChunkCacheMixin.java
index 9bedf714..2724b650 100644
--- a/src/main/java/carpet/mixins/ServerChunkCacheMixin.java
+++ b/src/main/java/carpet/mixins/ServerChunkCacheMixin.java
@@ -1,6 +1,5 @@
package carpet.mixins;
-import carpet.fakes.ServerChunkManagerInterface;
import carpet.utils.SpawnReporter;
import org.apache.commons.lang3.tuple.Pair;
import org.spongepowered.asm.mixin.Final;
@@ -22,18 +21,12 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.storage.LevelData;
@Mixin(ServerChunkCache.class)
-public abstract class ServerChunkCacheMixin implements ServerChunkManagerInterface
+public abstract class ServerChunkCacheMixin
{
@Shadow @Final private ServerLevel level;
@Shadow @Final private DistanceManager distanceManager;
- @Override // shared between scarpet and spawnChunks setting
- public DistanceManager getCMTicketManager()
- {
- return distanceManager;
- }
-
@Redirect(method = "tickChunks", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/DistanceManager;getNaturalSpawnChunkCount()I"
diff --git a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java
index b7278c60..d9a8efcf 100644
--- a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java
+++ b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_coreMixin.java
@@ -13,8 +13,6 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import static carpet.script.CarpetEventServer.Event.PLAYER_DISCONNECTS;
-
@Mixin(ServerGamePacketListenerImpl.class)
public class ServerGamePacketListenerImpl_coreMixin implements ServerGamePacketListenerImplInterface {
@Shadow
@@ -24,8 +22,7 @@ public class ServerGamePacketListenerImpl_coreMixin implements ServerGamePacketL
@Inject(method = "onDisconnect", at = @At("HEAD"))
private void onPlayerDisconnect(Component reason, CallbackInfo ci) {
- CarpetServer.onPlayerLoggedOut(this.player);
- if (PLAYER_DISCONNECTS.isNeeded()) PLAYER_DISCONNECTS.onPlayerMessage(player, reason.getContents().toString());
+ CarpetServer.onPlayerLoggedOut(this.player, reason);
}
@Override
diff --git a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java
index b70a1f8c..26749b59 100644
--- a/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java
+++ b/src/main/java/carpet/mixins/ServerGamePacketListenerImpl_scarpetEventsMixin.java
@@ -237,25 +237,6 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
PLAYER_DEPLOYS_ELYTRA.onPlayerEvent(player);
}
- /*@Inject(method = "onPlayerInteractEntity", at = @At(
- value = "INVOKE",
- target = "Lnet/minecraft/server/network/ServerPlayerEntity;interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"
- ))
- private void onEntityInteract(PlayerInteractEntityC2SPacket playerInteractEntityC2SPacket_1, CallbackInfo ci)
- {
- PLAYER_INTERACTS_WITH_ENTITY.onEntityHandAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getWorld()), playerInteractEntityC2SPacket_1.getHand());
- }*/
-
- /*@Inject(method = "onPlayerInteractEntity", at = @At(
- value = "INVOKE",
- target = "Lnet/minecraft/server/network/ServerPlayerEntity;attack(Lnet/minecraft/entity/Entity;)V"
- ))
- private void onEntityAttack(PlayerInteractEntityC2SPacket playerInteractEntityC2SPacket_1, CallbackInfo ci)
- {
- //todo add hit and hand in the future
- PLAYER_ATTACKS_ENTITY.onEntityHandAction(player, playerInteractEntityC2SPacket_1.getEntity(player.getWorld()), null);
- }*/
-
@Inject(method = "handleContainerButtonClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;resetLastActionTime()V"))
private void onItemBeingPickedFromInventory(ServerboundContainerButtonClickPacket packet, CallbackInfo ci)
{
diff --git a/src/main/java/carpet/script/CarpetScriptHost.java b/src/main/java/carpet/script/CarpetScriptHost.java
index 1353971a..eba43377 100644
--- a/src/main/java/carpet/script/CarpetScriptHost.java
+++ b/src/main/java/carpet/script/CarpetScriptHost.java
@@ -30,12 +30,6 @@ import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
-import net.fabricmc.loader.api.FabricLoader;
-import net.fabricmc.loader.api.ModContainer;
-import net.fabricmc.loader.api.SemanticVersion;
-import net.fabricmc.loader.api.Version;
-import net.fabricmc.loader.api.VersionParsingException;
-import net.fabricmc.loader.api.metadata.version.VersionPredicate;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.Tag;
@@ -474,31 +468,13 @@ public class CarpetScriptHost extends ScriptHost
{
throw new InternalExpressionException("`requires` field must be a map of mod dependencies or a function to be executed");
}
+
Map requirements = map.getMap();
for (Entry requirement : requirements.entrySet())
{
String requiredModId = requirement.getKey().getString();
String stringPredicate = requirement.getValue().getString();
- VersionPredicate predicate;
- try
- {
- predicate = VersionPredicate.parse(stringPredicate);
- }
- catch (VersionParsingException e)
- {
- throw new InternalExpressionException("Failed to parse version conditions for '" + requiredModId + "' in 'requires': " + e.getMessage());
- }
-
- ModContainer mod = FabricLoader.getInstance().getModContainer(requiredModId).orElse(null);
- if (mod != null)
- {
- Version presentVersion = mod.getMetadata().getVersion();
- if (predicate.test(presentVersion) || (FabricLoader.getInstance().isDevelopmentEnvironment() && !(presentVersion instanceof SemanticVersion)))
- { // in a dev env, mod version is usually replaced with ${version}, and that isn't semantic
- continue;
- }
- }
- throw new LoadException(String.format("%s requires a version of mod '%s' matching '%s', which is missing!", getName(), requiredModId, stringPredicate));
+ Carpet.assertRequirementMet(this, requiredModId, stringPredicate);
}
}
diff --git a/src/main/java/carpet/script/CarpetScriptServer.java b/src/main/java/carpet/script/CarpetScriptServer.java
index aa4f7a74..5345ceae 100644
--- a/src/main/java/carpet/script/CarpetScriptServer.java
+++ b/src/main/java/carpet/script/CarpetScriptServer.java
@@ -23,9 +23,8 @@ import carpet.script.value.FunctionValue;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.tree.CommandNode;
-import net.fabricmc.api.EnvType;
-import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandSourceStack;
+import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.storage.LevelResource;
@@ -51,6 +50,9 @@ import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import static carpet.script.CarpetEventServer.Event.PLAYER_CONNECTS;
+import static carpet.script.CarpetEventServer.Event.PLAYER_DISCONNECTS;
+
public class CarpetScriptServer extends ScriptServer
{
//make static for now, but will change that later:
@@ -156,24 +158,10 @@ public class CarpetScriptServer extends ScriptServer
}
}
- if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
+ Module globalModule = Carpet.fetchGlobalModule(name, allowLibraries);
+ if (globalModule != null)
{
- Path globalFolder = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts");
- if (!Files.exists(globalFolder))
- {
- Files.createDirectories(globalFolder);
- }
- try (Stream folderWalker = Files.walk(globalFolder))
- {
- Optional scriptPath = folderWalker
- .filter(script -> script.getFileName().toString().equalsIgnoreCase(name + ".sc") ||
- (allowLibraries && script.getFileName().toString().equalsIgnoreCase(name + ".scl")))
- .findFirst();
- if (scriptPath.isPresent())
- {
- return Module.fromPath(scriptPath.get());
- }
- }
+ return globalModule;
}
}
catch (IOException e)
@@ -229,20 +217,8 @@ public class CarpetScriptServer extends ScriptServer
.forEach(f -> moduleNames.add(f.getFileName().toString().replaceFirst("\\.sc$", "").toLowerCase(Locale.ROOT)));
}
- if (includeBuiltIns && (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT))
- {
- Path globalScripts = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts");
- if (!Files.exists(globalScripts))
- {
- Files.createDirectories(globalScripts);
- }
- try (Stream folderWalker = Files.walk(globalScripts, FileVisitOption.FOLLOW_LINKS))
- {
- folderWalker
- .filter(f -> f.toString().endsWith(".sc"))
- .forEach(f -> moduleNames.add(f.getFileName().toString().replaceFirst("\\.sc$", "").toLowerCase(Locale.ROOT)));
- }
- }
+ Carpet.addGlobalModules(moduleNames, includeBuiltIns);
+
}
catch (IOException e)
{
@@ -451,6 +427,7 @@ public class CarpetScriptServer extends ScriptServer
public void onPlayerJoin(ServerPlayer player)
{
+ PLAYER_CONNECTS.onPlayerEvent(player);
modules.values().forEach(h ->
{
if (h.isPerUser())
@@ -472,6 +449,14 @@ public class CarpetScriptServer extends ScriptServer
return server.getWorldPath(LevelResource.ROOT).resolve("scripts/" + suffix);
}
+ public void onPlayerLoggedOut(ServerPlayer player, Component reason)
+ {
+ if (PLAYER_DISCONNECTS.isNeeded())
+ {
+ PLAYER_DISCONNECTS.onPlayerMessage(player, reason.getContents().toString());
+ }
+ }
+
private record TransferData(boolean perUser, Predicate commandValidator,
boolean isRuleApp)
{
@@ -497,8 +482,11 @@ public class CarpetScriptServer extends ScriptServer
}));
}
+ private static boolean bootstrapDone = false;
public static void parseFunctionClasses()
{
+ if (bootstrapDone) return;
+ bootstrapDone = true;
ExpressionException.prepareForDoom(); // see fc-#1172
// Language
AnnotationParser.parseFunctionClass(Arithmetic.class);
diff --git a/src/main/java/carpet/script/annotation/AnnotationParser.java b/src/main/java/carpet/script/annotation/AnnotationParser.java
index 1e98ed67..2d64a0c0 100644
--- a/src/main/java/carpet/script/annotation/AnnotationParser.java
+++ b/src/main/java/carpet/script/annotation/AnnotationParser.java
@@ -28,7 +28,6 @@ import carpet.script.Fluff.UsageProvider;
import carpet.script.exception.InternalExpressionException;
import carpet.script.LazyValue;
import carpet.script.value.Value;
-import net.fabricmc.api.ModInitializer;
/**
* This class parses methods annotated with the {@link ScarpetFunction} annotation in a given {@link Class}, generating
@@ -85,7 +84,7 @@ public final class AnnotationParser
* to be used in the Scarpet language.
*
* Only call this method once per class per lifetime of the JVM! (for example, at {@link carpet.CarpetExtension#onGameStarted()} or
- * {@link ModInitializer#onInitialize()}).
+ * {@link net.fabricmc.api.ModInitializer#onInitialize()}).
*
* There is a set of requirements for the class and its methods:
*
diff --git a/src/main/java/carpet/script/annotation/Param.java b/src/main/java/carpet/script/annotation/Param.java
index 28185963..665d6029 100644
--- a/src/main/java/carpet/script/annotation/Param.java
+++ b/src/main/java/carpet/script/annotation/Param.java
@@ -12,7 +12,6 @@ import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;
-import carpet.CarpetServer;
import carpet.script.Context;
import carpet.script.value.BooleanValue;
import carpet.script.value.EntityValue;
@@ -213,7 +212,7 @@ public interface Param
registerStrictConverter(Component.class, false, new SimpleTypeConverter<>(FormattedTextValue.class, FormattedTextValue::getText, "text"));
registerStrictConverter(Component.class, true, new SimpleTypeConverter<>(StringValue.class, FormattedTextValue::getTextByValue, "text"));
registerStrictConverter(ServerPlayer.class, false, new SimpleTypeConverter<>(EntityValue.class,
- v -> EntityValue.getPlayerByValue(CarpetServer.minecraft_server, v), "online player entity"));
+ v -> EntityValue.getPlayerByValue(v.getEntity().getServer(), v), "online player entity"));
registerStrictConverter(Boolean.class, false, new SimpleTypeConverter<>(BooleanValue.class, BooleanValue::getBoolean, "boolean"));
registerStrictConverter(Boolean.class, true, new SimpleTypeConverter<>(NumericValue.class, NumericValue::getBoolean, "boolean"));
}
diff --git a/src/main/java/carpet/script/api/WorldAccess.java b/src/main/java/carpet/script/api/WorldAccess.java
index cc9f43ca..6139c2ae 100644
--- a/src/main/java/carpet/script/api/WorldAccess.java
+++ b/src/main/java/carpet/script/api/WorldAccess.java
@@ -7,8 +7,8 @@ import carpet.script.Expression;
import carpet.script.Fluff;
import carpet.script.external.Carpet;
import carpet.script.external.Vanilla;
+import carpet.script.utils.Colors;
import carpet.script.utils.FeatureGenerator;
-import carpet.mixins.PoiRecord_scarpetMixin;
import carpet.script.argument.BlockArgument;
import carpet.script.argument.Vector3Argument;
import carpet.script.exception.InternalExpressionException;
@@ -311,7 +311,7 @@ public class WorldAccess
).filter(p -> p.getPos().equals(pos)).findFirst().orElse(null);
return poi == null ? Value.NULL : ListValue.of(
ValueConversions.of(poiReg.getKey(poi.getPoiType().value())),
- new NumericValue(poiType.maxTickets() - ((PoiRecord_scarpetMixin) poi).getFreeTickets())
+ new NumericValue(poiType.maxTickets() - Vanilla.PoiRecord_getFreeTickets(poi))
);
}
int radius = NumericValue.asNumber(lv.get(locator.offset)).getInt();
@@ -360,7 +360,7 @@ public class WorldAccess
return ListValue.wrap(pois.sorted(Comparator.comparingDouble(p -> p.getPos().distSqr(pos))).map(p ->
ListValue.of(
ValueConversions.of(poiReg.getKey(p.getPoiType().value())),
- new NumericValue(p.getPoiType().value().maxTickets() - ((PoiRecord_scarpetMixin) p).getFreeTickets()),
+ new NumericValue(p.getPoiType().value().maxTickets() - Vanilla.PoiRecord_getFreeTickets(p)),
ValueConversions.of(p.getPos())
)
));
@@ -421,7 +421,7 @@ public class WorldAccess
).filter(p -> p.getPos().equals(pos)).findFirst().ifPresent(p -> {
for (int i = 0; i < finalO; i++)
{
- ((PoiRecord_scarpetMixin) p).callAcquireTicket();
+ Vanilla.PoiRecord_callAcquireTicket(p);
}
});
}
@@ -638,7 +638,7 @@ public class WorldAccess
expression.addContextFunction("chunk_tickets", -1, (c, t, lv) ->
{
ServerLevel world = ((CarpetContext) c).level();
- DistanceManager foo = Vanilla.ServerChunkCache_getCMTicketManager(world.getChunkSource());
+ DistanceManager foo = world.getChunkSource().chunkMap.getDistanceManager();
Long2ObjectOpenHashMap>> levelTickets = Vanilla.ChunkTicketManager_getTicketsByPosition(foo);
List res = new ArrayList<>();
@@ -1158,15 +1158,15 @@ public class WorldAccess
expression.addContextFunction("block_sound", -1, (c, t, lv) ->
stateStringQuery(c, "block_sound", lv, (s, p) ->
- Carpet.getSoundTypeNames().get(s.getSoundType())));
+ Colors.soundName.get(s.getSoundType())));
expression.addContextFunction("material", -1, (c, t, lv) ->
stateStringQuery(c, "material", lv, (s, p) ->
- Carpet.getMaterialNames().get(s.getMaterial())));
+ Colors.materialName.get(s.getMaterial())));
expression.addContextFunction("map_colour", -1, (c, t, lv) ->
stateStringQuery(c, "map_colour", lv, (s, p) ->
- Carpet.getMapColorNames().get(s.getMapColor(((CarpetContext) c).level(), p))));
+ Colors.materialName.get(s.getMapColor(((CarpetContext) c).level(), p))));
// Deprecated for block_state()
diff --git a/src/main/java/carpet/script/external/Carpet.java b/src/main/java/carpet/script/external/Carpet.java
index eafd1cd0..cc692d19 100644
--- a/src/main/java/carpet/script/external/Carpet.java
+++ b/src/main/java/carpet/script/external/Carpet.java
@@ -12,27 +12,41 @@ import carpet.logging.HUDController;
import carpet.network.ServerNetworkHandler;
import carpet.patches.EntityPlayerMPFake;
import carpet.script.CarpetExpression;
+import carpet.script.CarpetScriptHost;
import carpet.script.CarpetScriptServer;
+import carpet.script.Module;
+import carpet.script.exception.InternalExpressionException;
+import carpet.script.exception.LoadException;
import carpet.script.utils.AppStoreManager;
import carpet.script.value.MapValue;
import carpet.script.value.StringValue;
-import carpet.utils.BlockInfo;
import carpet.utils.CarpetProfiler;
import carpet.utils.Messenger;
+import net.fabricmc.api.EnvType;
+import net.fabricmc.loader.api.FabricLoader;
+import net.fabricmc.loader.api.ModContainer;
+import net.fabricmc.loader.api.SemanticVersion;
+import net.fabricmc.loader.api.Version;
+import net.fabricmc.loader.api.VersionParsingException;
+import net.fabricmc.loader.api.metadata.version.VersionPredicate;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.network.chat.Component;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
-import net.minecraft.world.level.block.SoundType;
-import net.minecraft.world.level.material.Material;
-import net.minecraft.world.level.material.MaterialColor;
import javax.annotation.Nullable;
+import java.io.IOException;
+import java.nio.file.FileVisitOption;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Locale;
import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Stream;
public class Carpet
{
@@ -66,21 +80,6 @@ public class Carpet
return CarpetSettings.impendingFillSkipUpdates;
}
- public static Map getSoundTypeNames()
- {
- return BlockInfo.soundName;
- }
-
- public static Map getMapColorNames()
- {
- return BlockInfo.mapColourName;
- }
-
- public static Map getMaterialNames()
- {
- return BlockInfo.materialName;
- }
-
public static Runnable startProfilerSection(String name)
{
CarpetProfiler.ProfilerToken token = CarpetProfiler.start_section(null, name, CarpetProfiler.TYPE.GENERAL);
@@ -148,6 +147,73 @@ public class Carpet
return CarpetSettings.fillUpdates;
}
+ @Nullable
+ public static Module fetchGlobalModule(String name, boolean allowLibraries) throws IOException
+ {
+ if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT)
+ {
+ Path globalFolder = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts");
+ if (!Files.exists(globalFolder))
+ {
+ Files.createDirectories(globalFolder);
+ }
+ try (Stream folderWalker = Files.walk(globalFolder))
+ {
+ Optional scriptPath = folderWalker
+ .filter(script -> script.getFileName().toString().equalsIgnoreCase(name + ".sc") ||
+ (allowLibraries && script.getFileName().toString().equalsIgnoreCase(name + ".scl")))
+ .findFirst();
+ if (scriptPath.isPresent())
+ {
+ return Module.fromPath(scriptPath.get());
+ }
+ }
+ }
+ return null;
+ }
+
+ public static void addGlobalModules(final List moduleNames, boolean includeBuiltIns) throws IOException
+ {
+ if (includeBuiltIns && (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT))
+ {
+ Path globalScripts = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts");
+ if (!Files.exists(globalScripts))
+ {
+ Files.createDirectories(globalScripts);
+ }
+ try (Stream folderWalker = Files.walk(globalScripts, FileVisitOption.FOLLOW_LINKS))
+ {
+ folderWalker
+ .filter(f -> f.toString().endsWith(".sc"))
+ .forEach(f -> moduleNames.add(f.getFileName().toString().replaceFirst("\\.sc$", "").toLowerCase(Locale.ROOT)));
+ }
+ }
+ }
+
+ public static void assertRequirementMet(CarpetScriptHost host, String requiredModId, String stringPredicate)
+ {
+ VersionPredicate predicate;
+ try
+ {
+ predicate = VersionPredicate.parse(stringPredicate);
+ }
+ catch (VersionParsingException e)
+ {
+ throw new InternalExpressionException("Failed to parse version conditions for '" + requiredModId + "' in 'requires': " + e.getMessage());
+ }
+
+ ModContainer mod = FabricLoader.getInstance().getModContainer(requiredModId).orElse(null);
+ if (mod != null)
+ {
+ Version presentVersion = mod.getMetadata().getVersion();
+ if (predicate.test(presentVersion) || (FabricLoader.getInstance().isDevelopmentEnvironment() && !(presentVersion instanceof SemanticVersion)))
+ { // in a dev env, mod version is usually replaced with ${version}, and that isn't semantic
+ return;
+ }
+ }
+ throw new LoadException(String.format("%s requires a version of mod '%s' matching '%s', which is missing!", host.getName(), requiredModId, stringPredicate));
+ }
+
public static class ScarpetAppStoreValidator extends Validator
{
@Override
diff --git a/src/main/java/carpet/script/external/Vanilla.java b/src/main/java/carpet/script/external/Vanilla.java
index 79f2e009..67470b4d 100644
--- a/src/main/java/carpet/script/external/Vanilla.java
+++ b/src/main/java/carpet/script/external/Vanilla.java
@@ -16,13 +16,13 @@ import carpet.fakes.MobEntityInterface;
import carpet.fakes.RandomStateVisitorAccessor;
import carpet.fakes.RecipeManagerInterface;
import carpet.fakes.AbstractContainerMenuInterface;
-import carpet.fakes.ServerChunkManagerInterface;
import carpet.fakes.ServerPlayerInterface;
import carpet.fakes.ServerPlayerInteractionManagerInterface;
import carpet.fakes.ServerWorldInterface;
import carpet.fakes.SpawnHelperInnerInterface;
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
import carpet.mixins.Objective_scarpetMixin;
+import carpet.mixins.PoiRecord_scarpetMixin;
import carpet.mixins.Scoreboard_scarpetMixin;
import carpet.network.ServerNetworkHandler;
import carpet.script.CarpetScriptServer;
@@ -46,7 +46,6 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.DistanceManager;
-import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
@@ -59,6 +58,7 @@ import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.goal.Goal;
import net.minecraft.world.entity.ai.goal.GoalSelector;
+import net.minecraft.world.entity.ai.village.poi.PoiRecord;
import net.minecraft.world.entity.animal.horse.AbstractHorse;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.inventory.AbstractContainerMenu;
@@ -143,11 +143,6 @@ public class Vanilla
return ((ServerWorldInterface) world).getWorldPropertiesCM();
}
- public static DistanceManager ServerChunkCache_getCMTicketManager(ServerChunkCache chunkCache)
- {
- return ((ServerChunkManagerInterface) chunkCache).getCMTicketManager();
- }
-
public static Long2ObjectOpenHashMap>> ChunkTicketManager_getTicketsByPosition(DistanceManager ticketManager)
{
return ((ChunkTicketManagerInterface) ticketManager).getTicketsByPosition();
@@ -353,6 +348,16 @@ public class Vanilla
return Math.max(server.getGameRules().getInt(GameRules.RULE_COMMAND_MODIFICATION_BLOCK_LIMIT), CarpetSettings.fillLimit);
}
+ public static int PoiRecord_getFreeTickets(PoiRecord record)
+ {
+ return ((PoiRecord_scarpetMixin) record).getFreeTickets();
+ }
+
+ public static void PoiRecord_callAcquireTicket(PoiRecord record)
+ {
+ ((PoiRecord_scarpetMixin) record).callAcquireTicket();
+ }
+
public record BlockPredicatePayload(BlockState state, TagKey tagKey, Map properties, CompoundTag tag) {
public static BlockPredicatePayload of(Predicate blockPredicate)
{
diff --git a/src/main/java/carpet/script/utils/AppStoreManager.java b/src/main/java/carpet/script/utils/AppStoreManager.java
index 9a5f3878..e5ab6aec 100644
--- a/src/main/java/carpet/script/utils/AppStoreManager.java
+++ b/src/main/java/carpet/script/utils/AppStoreManager.java
@@ -12,7 +12,6 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandRuntimeException;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.world.level.storage.LevelResource;
@@ -262,7 +261,7 @@ public class AppStoreManager
{
throw new CommandRuntimeException(Carpet.Messenger_compose("rb Failed to obtain app file content: " + e.getMessage()));
}
- if (!saveScriptToFile(source, path, nodeInfo.name(), code, false, useTrash))
+ if (!saveScriptToFile(source, path, nodeInfo.name(), code, useTrash))
{
return 0;
}
@@ -302,17 +301,9 @@ public class AppStoreManager
}
- public static boolean saveScriptToFile(CommandSourceStack source, String path, String appFileName, String code, boolean globalSavePath, boolean useTrash)
+ public static boolean saveScriptToFile(CommandSourceStack source, String path, String appFileName, String code, boolean useTrash)
{
- Path scriptLocation;
- if (globalSavePath && !source.getServer().isDedicatedServer()) // never happens, this is always called with globalSavePath being false
- { //cos config folder only is in clients
- scriptLocation = FabricLoader.getInstance().getConfigDir().resolve("carpet/scripts/appstore").toAbsolutePath().resolve(path);
- }
- else
- {
- scriptLocation = source.getServer().getWorldPath(LevelResource.ROOT).resolve("scripts").toAbsolutePath().resolve(appFileName);
- }
+ Path scriptLocation = source.getServer().getWorldPath(LevelResource.ROOT).resolve("scripts").toAbsolutePath().resolve(appFileName);
try
{
Files.createDirectories(scriptLocation.getParent());
diff --git a/src/main/java/carpet/script/utils/Colors.java b/src/main/java/carpet/script/utils/Colors.java
new file mode 100644
index 00000000..a746a7d7
--- /dev/null
+++ b/src/main/java/carpet/script/utils/Colors.java
@@ -0,0 +1,207 @@
+package carpet.script.utils;
+
+import net.minecraft.world.level.block.SoundType;
+import net.minecraft.world.level.material.Material;
+import net.minecraft.world.level.material.MaterialColor;
+
+import java.util.Map;
+
+import static java.util.Map.entry;
+
+public class Colors
+{
+ public static final Map soundName = Map.ofEntries(
+ entry(SoundType.WOOD, "wood" ),
+ entry(SoundType.GRAVEL, "gravel"),
+ entry(SoundType.GRASS, "grass" ),
+ entry(SoundType.LILY_PAD, "lily_pad"),
+ entry(SoundType.STONE, "stone" ),
+ entry(SoundType.METAL, "metal" ),
+ entry(SoundType.GLASS , "glass" ),
+ entry(SoundType.WOOL , "wool" ),
+ entry(SoundType.SAND , "sand" ),
+ entry(SoundType.SNOW , "snow" ),
+ entry(SoundType.POWDER_SNOW , "powder_snow" ),
+ entry(SoundType.LADDER, "ladder"),
+ entry(SoundType.ANVIL , "anvil" ),
+ entry(SoundType.SLIME_BLOCK , "slime" ),
+ entry(SoundType.HONEY_BLOCK , "honey" ),
+ entry(SoundType.WET_GRASS , "sea_grass" ),
+ entry(SoundType.CORAL_BLOCK , "coral" ),
+ entry(SoundType.BAMBOO , "bamboo" ),
+ entry(SoundType.BAMBOO_SAPLING , "shoots" ),
+ entry(SoundType.SCAFFOLDING , "scaffolding" ),
+ entry(SoundType.SWEET_BERRY_BUSH , "berry" ),
+ entry(SoundType.CROP , "crop" ),
+ entry(SoundType.HARD_CROP , "stem" ),
+ entry(SoundType.VINE , "vine" ),
+ entry(SoundType.NETHER_WART , "wart" ),
+ entry(SoundType.LANTERN , "lantern" ),
+ entry(SoundType.STEM, "fungi_stem"),
+ entry(SoundType.NYLIUM, "nylium"),
+ entry(SoundType.FUNGUS, "fungus"),
+ entry(SoundType.ROOTS, "roots"),
+ entry(SoundType.SHROOMLIGHT, "shroomlight"),
+ entry(SoundType.WEEPING_VINES, "weeping_vine"),
+ entry(SoundType.TWISTING_VINES, "twisting_vine"),
+ entry(SoundType.SOUL_SAND, "soul_sand"),
+ entry(SoundType.SOUL_SOIL, "soul_soil"),
+ entry(SoundType.BASALT, "basalt"),
+ entry(SoundType.WART_BLOCK, "wart"),
+ entry(SoundType.NETHERRACK, "netherrack"),
+ entry(SoundType.NETHER_BRICKS, "nether_bricks"),
+ entry(SoundType.NETHER_SPROUTS, "nether_sprouts"),
+ entry(SoundType.NETHER_ORE, "nether_ore"),
+ entry(SoundType.BONE_BLOCK, "bone"),
+ entry(SoundType.NETHERITE_BLOCK, "netherite"),
+ entry(SoundType.ANCIENT_DEBRIS, "ancient_debris"),
+ entry(SoundType.LODESTONE, "lodestone"),
+ entry(SoundType.CHAIN, "chain"),
+ entry(SoundType.NETHER_GOLD_ORE, "nether_gold_ore"),
+ entry(SoundType.GILDED_BLACKSTONE, "gilded_blackstone"),
+ entry(SoundType.CANDLE, "candle"),
+ entry(SoundType.AMETHYST, "amethyst"),
+ entry(SoundType.AMETHYST_CLUSTER, "amethyst_cluster"),
+ entry(SoundType.SMALL_AMETHYST_BUD, "small_amethyst_bud"),
+ entry(SoundType.MEDIUM_AMETHYST_BUD, "medium_amethyst_bud"),
+ entry(SoundType.LARGE_AMETHYST_BUD, "large_amethyst_bud"),
+
+ entry(SoundType.TUFF, "tuff"),
+ entry(SoundType.CALCITE, "calcite"),
+ entry(SoundType.DRIPSTONE_BLOCK, "dripstone"),
+ entry(SoundType.POINTED_DRIPSTONE, "pointed_dripstone"),
+ entry(SoundType.COPPER, "copper"),
+ entry(SoundType.CAVE_VINES, "cave_vine"),
+ entry(SoundType.SPORE_BLOSSOM, "spore_blossom"),
+ entry(SoundType.AZALEA, "azalea"),
+ entry(SoundType.FLOWERING_AZALEA, "flowering_azalea"),
+ entry(SoundType.MOSS_CARPET, "moss_carpet"),
+ entry(SoundType.MOSS, "moss"),
+ entry(SoundType.BIG_DRIPLEAF, "big_dripleaf"),
+ entry(SoundType.SMALL_DRIPLEAF, "small_dripleaf"),
+ entry(SoundType.ROOTED_DIRT, "rooted_dirt"),
+ entry(SoundType.HANGING_ROOTS, "hanging_roots"),
+ entry(SoundType.AZALEA_LEAVES, "azalea_leaves"),
+ entry(SoundType.SCULK_SENSOR, "sculk_sensor"),
+ entry(SoundType.GLOW_LICHEN, "glow_lichen"),
+ entry(SoundType.DEEPSLATE, "deepslate"),
+ entry(SoundType.DEEPSLATE_BRICKS, "deepslate_bricks"),
+ entry(SoundType.DEEPSLATE_TILES, "deepslate_tiles"),
+ entry(SoundType.POLISHED_DEEPSLATE, "polished_deepslate")
+ );
+
+ public static final Map mapColourName = Map.ofEntries(
+ entry(MaterialColor.NONE , "air" ),
+ entry(MaterialColor.GRASS , "grass" ),
+ entry(MaterialColor.SAND , "sand" ),
+ entry(MaterialColor.WOOL , "wool" ),
+ entry(MaterialColor.FIRE , "tnt" ),
+ entry(MaterialColor.ICE , "ice" ),
+ entry(MaterialColor.METAL , "iron" ),
+ entry(MaterialColor.PLANT , "foliage" ),
+ entry(MaterialColor.SNOW , "snow" ),
+ entry(MaterialColor.CLAY , "clay" ),
+ entry(MaterialColor.DIRT , "dirt" ),
+ entry(MaterialColor.STONE , "stone" ),
+ entry(MaterialColor.WATER , "water" ),
+ entry(MaterialColor.WOOD , "wood" ),
+ entry(MaterialColor.QUARTZ , "quartz" ),
+ entry(MaterialColor.COLOR_ORANGE , "adobe" ),
+ entry(MaterialColor.COLOR_MAGENTA , "magenta" ),
+ entry(MaterialColor.COLOR_LIGHT_BLUE, "light_blue"),
+ entry(MaterialColor.COLOR_YELLOW , "yellow" ),
+ entry(MaterialColor.COLOR_LIGHT_GREEN , "lime" ),
+ entry(MaterialColor.COLOR_PINK , "pink" ),
+ entry(MaterialColor.COLOR_GRAY , "gray" ),
+ entry(MaterialColor.COLOR_LIGHT_GRAY, "light_gray"),
+ entry(MaterialColor.COLOR_CYAN , "cyan" ),
+ entry(MaterialColor.COLOR_PURPLE , "purple" ),
+ entry(MaterialColor.COLOR_BLUE , "blue" ),
+ entry(MaterialColor.COLOR_BROWN , "brown" ),
+ entry(MaterialColor.COLOR_GREEN , "green" ),
+ entry(MaterialColor.COLOR_RED , "red" ),
+ entry(MaterialColor.COLOR_BLACK , "black" ),
+ entry(MaterialColor.GOLD , "gold" ),
+ entry(MaterialColor.DIAMOND , "diamond" ),
+ entry(MaterialColor.LAPIS , "lapis" ),
+ entry(MaterialColor.EMERALD , "emerald" ),
+ entry(MaterialColor.PODZOL , "obsidian" ),
+ entry(MaterialColor.NETHER , "netherrack"), //TODO fix these
+ entry(MaterialColor.TERRACOTTA_WHITE , "white_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_ORANGE , "orange_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_MAGENTA , "magenta_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_LIGHT_BLUE, "light_blue_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_YELLOW , "yellow_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_LIGHT_GREEN , "lime_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_PINK , "pink_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_GRAY , "gray_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_LIGHT_GRAY, "light_gray_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_CYAN , "cyan_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_PURPLE , "purple_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_BLUE , "blue_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_BROWN , "brown_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_GREEN , "green_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_RED , "red_terracotta" ),
+ entry(MaterialColor.TERRACOTTA_BLACK , "black_terracotta" ),
+ entry(MaterialColor.CRIMSON_NYLIUM , "crimson_nylium" ),
+ entry(MaterialColor.CRIMSON_STEM , "crimson_stem" ),
+ entry(MaterialColor.CRIMSON_HYPHAE , "crimson_hyphae" ),
+ entry(MaterialColor.WARPED_NYLIUM , "warped_nylium" ),
+ entry(MaterialColor.WARPED_STEM , "warped_stem" ),
+ entry(MaterialColor.WARPED_HYPHAE , "warped_hyphae" ),
+ entry(MaterialColor.WARPED_WART_BLOCK , "warped_wart" ),
+ entry(MaterialColor.DEEPSLATE , "deepslate" ),
+ entry(MaterialColor.RAW_IRON , "raw_iron" ),
+ entry(MaterialColor.GLOW_LICHEN , "glow_lichen" )
+ );
+
+ public static final Map materialName = Map.ofEntries(
+ entry(Material.AIR , "air" ),
+ entry(Material.STRUCTURAL_AIR , "void" ),
+ entry(Material.PORTAL , "portal" ),
+ entry(Material.CLOTH_DECORATION , "carpet" ),
+ entry(Material.PLANT , "plant" ),
+ entry(Material.WATER_PLANT, "water_plant" ),
+ entry(Material.REPLACEABLE_PLANT, "vegetation" ),
+ entry(Material.REPLACEABLE_FIREPROOF_PLANT, "nether_shoots" ),
+ entry(Material.REPLACEABLE_WATER_PLANT, "sea_grass" ),
+ entry(Material.WATER , "water" ),
+ entry(Material.BUBBLE_COLUMN , "bubble_column"),
+ entry(Material.LAVA , "lava" ),
+ entry(Material.TOP_SNOW , "snow_layer" ),
+ entry(Material.FIRE , "fire" ),
+ entry(Material.DECORATION , "decoration" ),
+ entry(Material.WEB , "cobweb" ),
+ entry(Material.SCULK , "sculk" ),
+ entry(Material.BUILDABLE_GLASS , "redstone_lamp"),
+ entry(Material.CLAY, "clay" ),
+ entry(Material.DIRT , "dirt" ),
+ entry(Material.GRASS , "grass" ),
+ entry(Material.ICE_SOLID , "packed_ice" ),
+ entry(Material.SAND , "sand" ),
+ entry(Material.SPONGE , "sponge" ),
+ entry(Material.SHULKER_SHELL , "shulker" ),
+ entry(Material.WOOD , "wood" ),
+ entry(Material.NETHER_WOOD , "nether_wood" ),
+ entry(Material.BAMBOO_SAPLING , "shoots" ),
+ entry(Material.BAMBOO , "bamboo" ),
+ entry(Material.WOOL , "wool" ),
+ entry(Material.EXPLOSIVE , "tnt" ),
+ entry(Material.LEAVES , "leaves" ),
+ entry(Material.GLASS , "glass" ),
+ entry(Material.ICE , "ice" ),
+ entry(Material.CACTUS , "cactus" ),
+ entry(Material.STONE , "stone" ),
+ entry(Material.METAL , "metal" ),
+ entry(Material.SNOW , "snow" ),
+ entry(Material.HEAVY_METAL , "anvil" ),
+ entry(Material.BARRIER , "barrier" ),
+ entry(Material.PISTON , "piston" ),
+ entry(Material.MOSS , "moss" ),
+ entry(Material.VEGETABLE , "gourd" ),
+ entry(Material.EGG , "dragon_egg" ),
+ entry(Material.CAKE , "cake" ),
+ entry(Material.AMETHYST , "amethyst" ),
+ entry(Material.POWDER_SNOW , "powder_snow")
+ );
+}
diff --git a/src/main/java/carpet/script/utils/ShapesRenderer.java b/src/main/java/carpet/script/utils/ShapesRenderer.java
index 45c1100e..a83851a7 100644
--- a/src/main/java/carpet/script/utils/ShapesRenderer.java
+++ b/src/main/java/carpet/script/utils/ShapesRenderer.java
@@ -73,6 +73,35 @@ public class ShapesRenderer
put("item", (c, s) -> new RenderedSprite(c, s, true));
}};
+ public static void rotatePoseStackByShapeDirection(PoseStack poseStack, ShapeDirection shapeDirection, Camera camera, Vec3 objectPos)
+ {
+ switch (shapeDirection)
+ {
+ case NORTH -> {}
+ case SOUTH -> poseStack.mulPose(Axis.YP.rotationDegrees(180));
+ case EAST -> poseStack.mulPose(Axis.YP.rotationDegrees(270));
+ case WEST -> poseStack.mulPose(Axis.YP.rotationDegrees(90));
+ case UP -> poseStack.mulPose(Axis.XP.rotationDegrees(90));
+ case DOWN -> poseStack.mulPose(Axis.XP.rotationDegrees(-90));
+ case CAMERA -> poseStack.mulPose(camera.rotation());
+ case PLAYER -> {
+ Vec3 vector = objectPos.subtract(camera.getPosition());
+ double x = vector.x;
+ double y = vector.y;
+ double z = vector.z;
+ double d = Math.sqrt(x * x + z * z);
+ float rotX = (float) (Math.atan2(x, z));
+ float rotY = (float) (Math.atan2(y, d));
+
+ // that should work somehow but it doesn't for some reason
+ //matrices.mulPose(new Quaternion( -rotY, rotX, 0, false));
+
+ poseStack.mulPose(Axis.YP.rotation(rotX));
+ poseStack.mulPose(Axis.XP.rotation(-rotY));
+ }
+ }
+ }
+
public ShapesRenderer(Minecraft minecraftClient)
{
this.client = minecraftClient;
@@ -322,7 +351,7 @@ public class ShapesRenderer
}
matrices.translate(v1.x - cx, v1.y - cy, v1.z - cz);
- ShapeDirection.rotatePoseStackByShapeDirection(matrices, shape.facing, camera1, isitem ? v1 : v1.add(0.5, 0.5, 0.5));
+ rotatePoseStackByShapeDirection(matrices, shape.facing, camera1, isitem ? v1 : v1.add(0.5, 0.5, 0.5));
if (shape.tilt != 0.0f)
{
matrices.mulPose(Axis.ZP.rotationDegrees(-shape.tilt));
@@ -508,7 +537,7 @@ public class ShapesRenderer
matrices.pushPose();
matrices.translate(v1.x - cx, v1.y - cy, v1.z - cz);
- ShapeDirection.rotatePoseStackByShapeDirection(matrices, shape.facing, camera1, v1);
+ rotatePoseStackByShapeDirection(matrices, shape.facing, camera1, v1);
matrices.scale(shape.size * 0.0025f, -shape.size * 0.0025f, shape.size * 0.0025f);
//RenderSystem.scalef(shape.size* 0.0025f, -shape.size*0.0025f, shape.size*0.0025f);
diff --git a/src/main/java/carpet/script/utils/shapes/ShapeDirection.java b/src/main/java/carpet/script/utils/shapes/ShapeDirection.java
index 54774263..29bc08a6 100644
--- a/src/main/java/carpet/script/utils/shapes/ShapeDirection.java
+++ b/src/main/java/carpet/script/utils/shapes/ShapeDirection.java
@@ -1,10 +1,5 @@
package carpet.script.utils.shapes;
-import com.mojang.blaze3d.vertex.PoseStack;
-import com.mojang.math.Axis;
-import net.minecraft.client.Camera;
-import net.minecraft.world.phys.Vec3;
-
import javax.annotation.Nullable;
import java.util.Locale;
@@ -35,33 +30,4 @@ public enum ShapeDirection
default -> null;
};
}
-
- public static void rotatePoseStackByShapeDirection(PoseStack poseStack, ShapeDirection shapeDirection, Camera camera, Vec3 objectPos)
- {
- switch (shapeDirection)
- {
- case NORTH -> {}
- case SOUTH -> poseStack.mulPose(Axis.YP.rotationDegrees(180));
- case EAST -> poseStack.mulPose(Axis.YP.rotationDegrees(270));
- case WEST -> poseStack.mulPose(Axis.YP.rotationDegrees(90));
- case UP -> poseStack.mulPose(Axis.XP.rotationDegrees(90));
- case DOWN -> poseStack.mulPose(Axis.XP.rotationDegrees(-90));
- case CAMERA -> poseStack.mulPose(camera.rotation());
- case PLAYER -> {
- Vec3 vector = objectPos.subtract(camera.getPosition());
- double x = vector.x;
- double y = vector.y;
- double z = vector.z;
- double d = Math.sqrt(x * x + z * z);
- float rotX = (float) (Math.atan2(x, z));
- float rotY = (float) (Math.atan2(y, d));
-
- // that should work somehow but it doesn't for some reason
- //matrices.mulPose(new Quaternion( -rotY, rotX, 0, false));
-
- poseStack.mulPose(Axis.YP.rotation(rotX));
- poseStack.mulPose(Axis.XP.rotation(-rotY));
- }
- }
- }
}
diff --git a/src/main/java/carpet/script/value/ValueConversions.java b/src/main/java/carpet/script/value/ValueConversions.java
index 646ec1af..d93bcb16 100644
--- a/src/main/java/carpet/script/value/ValueConversions.java
+++ b/src/main/java/carpet/script/value/ValueConversions.java
@@ -5,6 +5,7 @@ import carpet.script.exception.ThrowStatement;
import carpet.script.exception.Throwables;
import carpet.script.external.Carpet;
import carpet.script.external.Vanilla;
+import carpet.script.utils.Colors;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import net.minecraft.advancements.critereon.MinMaxBounds;
@@ -85,7 +86,7 @@ public class ValueConversions
public static Value of(MaterialColor color)
{
- return ListValue.of(StringValue.of(Carpet.getMapColorNames().get(color)), ofRGB(color.col));
+ return ListValue.of(StringValue.of(Colors.mapColourName.get(color)), ofRGB(color.col));
}
public static Value of(MinMaxBounds range)
diff --git a/src/main/java/carpet/utils/BlockInfo.java b/src/main/java/carpet/utils/BlockInfo.java
index e1c01773..c000acdc 100644
--- a/src/main/java/carpet/utils/BlockInfo.java
+++ b/src/main/java/carpet/utils/BlockInfo.java
@@ -2,10 +2,10 @@ package carpet.utils;
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
+
+import carpet.script.utils.Colors;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
-import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
@@ -17,212 +17,13 @@ import net.minecraft.world.entity.ai.util.DefaultRandomPos;
import net.minecraft.world.entity.monster.ZombifiedPiglin;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.block.Block;
-import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
-import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.Vec3;
-import static java.util.Map.entry;
-
public class BlockInfo
{
- public static final Map soundName = Map.ofEntries(
- entry(SoundType.WOOD, "wood" ),
- entry(SoundType.GRAVEL, "gravel"),
- entry(SoundType.GRASS, "grass" ),
- entry(SoundType.LILY_PAD, "lily_pad"),
- entry(SoundType.STONE, "stone" ),
- entry(SoundType.METAL, "metal" ),
- entry(SoundType.GLASS , "glass" ),
- entry(SoundType.WOOL , "wool" ),
- entry(SoundType.SAND , "sand" ),
- entry(SoundType.SNOW , "snow" ),
- entry(SoundType.POWDER_SNOW , "powder_snow" ),
- entry(SoundType.LADDER, "ladder"),
- entry(SoundType.ANVIL , "anvil" ),
- entry(SoundType.SLIME_BLOCK , "slime" ),
- entry(SoundType.HONEY_BLOCK , "honey" ),
- entry(SoundType.WET_GRASS , "sea_grass" ),
- entry(SoundType.CORAL_BLOCK , "coral" ),
- entry(SoundType.BAMBOO , "bamboo" ),
- entry(SoundType.BAMBOO_SAPLING , "shoots" ),
- entry(SoundType.SCAFFOLDING , "scaffolding" ),
- entry(SoundType.SWEET_BERRY_BUSH , "berry" ),
- entry(SoundType.CROP , "crop" ),
- entry(SoundType.HARD_CROP , "stem" ),
- entry(SoundType.VINE , "vine" ),
- entry(SoundType.NETHER_WART , "wart" ),
- entry(SoundType.LANTERN , "lantern" ),
- entry(SoundType.STEM, "fungi_stem"),
- entry(SoundType.NYLIUM, "nylium"),
- entry(SoundType.FUNGUS, "fungus"),
- entry(SoundType.ROOTS, "roots"),
- entry(SoundType.SHROOMLIGHT, "shroomlight"),
- entry(SoundType.WEEPING_VINES, "weeping_vine"),
- entry(SoundType.TWISTING_VINES, "twisting_vine"),
- entry(SoundType.SOUL_SAND, "soul_sand"),
- entry(SoundType.SOUL_SOIL, "soul_soil"),
- entry(SoundType.BASALT, "basalt"),
- entry(SoundType.WART_BLOCK, "wart"),
- entry(SoundType.NETHERRACK, "netherrack"),
- entry(SoundType.NETHER_BRICKS, "nether_bricks"),
- entry(SoundType.NETHER_SPROUTS, "nether_sprouts"),
- entry(SoundType.NETHER_ORE, "nether_ore"),
- entry(SoundType.BONE_BLOCK, "bone"),
- entry(SoundType.NETHERITE_BLOCK, "netherite"),
- entry(SoundType.ANCIENT_DEBRIS, "ancient_debris"),
- entry(SoundType.LODESTONE, "lodestone"),
- entry(SoundType.CHAIN, "chain"),
- entry(SoundType.NETHER_GOLD_ORE, "nether_gold_ore"),
- entry(SoundType.GILDED_BLACKSTONE, "gilded_blackstone"),
- entry(SoundType.CANDLE, "candle"),
- entry(SoundType.AMETHYST, "amethyst"),
- entry(SoundType.AMETHYST_CLUSTER, "amethyst_cluster"),
- entry(SoundType.SMALL_AMETHYST_BUD, "small_amethyst_bud"),
- entry(SoundType.MEDIUM_AMETHYST_BUD, "medium_amethyst_bud"),
- entry(SoundType.LARGE_AMETHYST_BUD, "large_amethyst_bud"),
-
- entry(SoundType.TUFF, "tuff"),
- entry(SoundType.CALCITE, "calcite"),
- entry(SoundType.DRIPSTONE_BLOCK, "dripstone"),
- entry(SoundType.POINTED_DRIPSTONE, "pointed_dripstone"),
- entry(SoundType.COPPER, "copper"),
- entry(SoundType.CAVE_VINES, "cave_vine"),
- entry(SoundType.SPORE_BLOSSOM, "spore_blossom"),
- entry(SoundType.AZALEA, "azalea"),
- entry(SoundType.FLOWERING_AZALEA, "flowering_azalea"),
- entry(SoundType.MOSS_CARPET, "moss_carpet"),
- entry(SoundType.MOSS, "moss"),
- entry(SoundType.BIG_DRIPLEAF, "big_dripleaf"),
- entry(SoundType.SMALL_DRIPLEAF, "small_dripleaf"),
- entry(SoundType.ROOTED_DIRT, "rooted_dirt"),
- entry(SoundType.HANGING_ROOTS, "hanging_roots"),
- entry(SoundType.AZALEA_LEAVES, "azalea_leaves"),
- entry(SoundType.SCULK_SENSOR, "sculk_sensor"),
- entry(SoundType.GLOW_LICHEN, "glow_lichen"),
- entry(SoundType.DEEPSLATE, "deepslate"),
- entry(SoundType.DEEPSLATE_BRICKS, "deepslate_bricks"),
- entry(SoundType.DEEPSLATE_TILES, "deepslate_tiles"),
- entry(SoundType.POLISHED_DEEPSLATE, "polished_deepslate")
- );
-
- public static final Map mapColourName = Map.ofEntries(
- entry(MaterialColor.NONE , "air" ),
- entry(MaterialColor.GRASS , "grass" ),
- entry(MaterialColor.SAND , "sand" ),
- entry(MaterialColor.WOOL , "wool" ),
- entry(MaterialColor.FIRE , "tnt" ),
- entry(MaterialColor.ICE , "ice" ),
- entry(MaterialColor.METAL , "iron" ),
- entry(MaterialColor.PLANT , "foliage" ),
- entry(MaterialColor.SNOW , "snow" ),
- entry(MaterialColor.CLAY , "clay" ),
- entry(MaterialColor.DIRT , "dirt" ),
- entry(MaterialColor.STONE , "stone" ),
- entry(MaterialColor.WATER , "water" ),
- entry(MaterialColor.WOOD , "wood" ),
- entry(MaterialColor.QUARTZ , "quartz" ),
- entry(MaterialColor.COLOR_ORANGE , "adobe" ),
- entry(MaterialColor.COLOR_MAGENTA , "magenta" ),
- entry(MaterialColor.COLOR_LIGHT_BLUE, "light_blue"),
- entry(MaterialColor.COLOR_YELLOW , "yellow" ),
- entry(MaterialColor.COLOR_LIGHT_GREEN , "lime" ),
- entry(MaterialColor.COLOR_PINK , "pink" ),
- entry(MaterialColor.COLOR_GRAY , "gray" ),
- entry(MaterialColor.COLOR_LIGHT_GRAY, "light_gray"),
- entry(MaterialColor.COLOR_CYAN , "cyan" ),
- entry(MaterialColor.COLOR_PURPLE , "purple" ),
- entry(MaterialColor.COLOR_BLUE , "blue" ),
- entry(MaterialColor.COLOR_BROWN , "brown" ),
- entry(MaterialColor.COLOR_GREEN , "green" ),
- entry(MaterialColor.COLOR_RED , "red" ),
- entry(MaterialColor.COLOR_BLACK , "black" ),
- entry(MaterialColor.GOLD , "gold" ),
- entry(MaterialColor.DIAMOND , "diamond" ),
- entry(MaterialColor.LAPIS , "lapis" ),
- entry(MaterialColor.EMERALD , "emerald" ),
- entry(MaterialColor.PODZOL , "obsidian" ),
- entry(MaterialColor.NETHER , "netherrack"), //TODO fix these
- entry(MaterialColor.TERRACOTTA_WHITE , "white_terracotta" ),
- entry(MaterialColor.TERRACOTTA_ORANGE , "orange_terracotta" ),
- entry(MaterialColor.TERRACOTTA_MAGENTA , "magenta_terracotta" ),
- entry(MaterialColor.TERRACOTTA_LIGHT_BLUE, "light_blue_terracotta" ),
- entry(MaterialColor.TERRACOTTA_YELLOW , "yellow_terracotta" ),
- entry(MaterialColor.TERRACOTTA_LIGHT_GREEN , "lime_terracotta" ),
- entry(MaterialColor.TERRACOTTA_PINK , "pink_terracotta" ),
- entry(MaterialColor.TERRACOTTA_GRAY , "gray_terracotta" ),
- entry(MaterialColor.TERRACOTTA_LIGHT_GRAY, "light_gray_terracotta" ),
- entry(MaterialColor.TERRACOTTA_CYAN , "cyan_terracotta" ),
- entry(MaterialColor.TERRACOTTA_PURPLE , "purple_terracotta" ),
- entry(MaterialColor.TERRACOTTA_BLUE , "blue_terracotta" ),
- entry(MaterialColor.TERRACOTTA_BROWN , "brown_terracotta" ),
- entry(MaterialColor.TERRACOTTA_GREEN , "green_terracotta" ),
- entry(MaterialColor.TERRACOTTA_RED , "red_terracotta" ),
- entry(MaterialColor.TERRACOTTA_BLACK , "black_terracotta" ),
- entry(MaterialColor.CRIMSON_NYLIUM , "crimson_nylium" ),
- entry(MaterialColor.CRIMSON_STEM , "crimson_stem" ),
- entry(MaterialColor.CRIMSON_HYPHAE , "crimson_hyphae" ),
- entry(MaterialColor.WARPED_NYLIUM , "warped_nylium" ),
- entry(MaterialColor.WARPED_STEM , "warped_stem" ),
- entry(MaterialColor.WARPED_HYPHAE , "warped_hyphae" ),
- entry(MaterialColor.WARPED_WART_BLOCK , "warped_wart" ),
- entry(MaterialColor.DEEPSLATE , "deepslate" ),
- entry(MaterialColor.RAW_IRON , "raw_iron" ),
- entry(MaterialColor.GLOW_LICHEN , "glow_lichen" )
- );
-
- public static final Map materialName = Map.ofEntries(
- entry(Material.AIR , "air" ),
- entry(Material.STRUCTURAL_AIR , "void" ),
- entry(Material.PORTAL , "portal" ),
- entry(Material.CLOTH_DECORATION , "carpet" ),
- entry(Material.PLANT , "plant" ),
- entry(Material.WATER_PLANT, "water_plant" ),
- entry(Material.REPLACEABLE_PLANT, "vegetation" ),
- entry(Material.REPLACEABLE_FIREPROOF_PLANT, "nether_shoots" ),
- entry(Material.REPLACEABLE_WATER_PLANT, "sea_grass" ),
- entry(Material.WATER , "water" ),
- entry(Material.BUBBLE_COLUMN , "bubble_column"),
- entry(Material.LAVA , "lava" ),
- entry(Material.TOP_SNOW , "snow_layer" ),
- entry(Material.FIRE , "fire" ),
- entry(Material.DECORATION , "decoration" ),
- entry(Material.WEB , "cobweb" ),
- entry(Material.SCULK , "sculk" ),
- entry(Material.BUILDABLE_GLASS , "redstone_lamp"),
- entry(Material.CLAY, "clay" ),
- entry(Material.DIRT , "dirt" ),
- entry(Material.GRASS , "grass" ),
- entry(Material.ICE_SOLID , "packed_ice" ),
- entry(Material.SAND , "sand" ),
- entry(Material.SPONGE , "sponge" ),
- entry(Material.SHULKER_SHELL , "shulker" ),
- entry(Material.WOOD , "wood" ),
- entry(Material.NETHER_WOOD , "nether_wood" ),
- entry(Material.BAMBOO_SAPLING , "shoots" ),
- entry(Material.BAMBOO , "bamboo" ),
- entry(Material.WOOL , "wool" ),
- entry(Material.EXPLOSIVE , "tnt" ),
- entry(Material.LEAVES , "leaves" ),
- entry(Material.GLASS , "glass" ),
- entry(Material.ICE , "ice" ),
- entry(Material.CACTUS , "cactus" ),
- entry(Material.STONE , "stone" ),
- entry(Material.METAL , "metal" ),
- entry(Material.SNOW , "snow" ),
- entry(Material.HEAVY_METAL , "anvil" ),
- entry(Material.BARRIER , "barrier" ),
- entry(Material.PISTON , "piston" ),
- entry(Material.MOSS , "moss" ),
- entry(Material.VEGETABLE , "gourd" ),
- entry(Material.EGG , "dragon_egg" ),
- entry(Material.CAKE , "cake" ),
- entry(Material.AMETHYST , "amethyst" ),
- entry(Material.POWDER_SNOW , "powder_snow")
- );
-
public static List blockInfo(BlockPos pos, ServerLevel world)
{
BlockState state = world.getBlockState(pos);
@@ -238,9 +39,9 @@ public class BlockInfo
lst.add(Messenger.s(""));
lst.add(Messenger.s("====================================="));
lst.add(Messenger.s(String.format("Block info for %s%s (id %d%s):", blocks.getKey(block),metastring, blocks.getId(block), metastring )));
- lst.add(Messenger.s(String.format(" - Material: %s", materialName.get(material))));
- lst.add(Messenger.s(String.format(" - Map colour: %s", mapColourName.get(state.getMapColor(world, pos)))));
- lst.add(Messenger.s(String.format(" - Sound type: %s", soundName.get(block.getSoundType(state)))));
+ lst.add(Messenger.s(String.format(" - Material: %s", Colors.materialName.get(material))));
+ lst.add(Messenger.s(String.format(" - Map colour: %s", Colors.mapColourName.get(state.getMapColor(world, pos)))));
+ lst.add(Messenger.s(String.format(" - Sound type: %s", Colors.soundName.get(block.getSoundType(state)))));
lst.add(Messenger.s(""));
lst.add(Messenger.s(String.format(" - Full block: %s", state.isCollisionShapeFullBlock(world, pos)))); // isFullCube() )));
lst.add(Messenger.s(String.format(" - Normal cube: %s", state.isRedstoneConductor(world, pos)))); //isNormalCube()))); isSimpleFullBlock
diff --git a/src/main/java/carpet/utils/SpawnChunks.java b/src/main/java/carpet/utils/SpawnChunks.java
index 5c905d17..9631d468 100644
--- a/src/main/java/carpet/utils/SpawnChunks.java
+++ b/src/main/java/carpet/utils/SpawnChunks.java
@@ -1,7 +1,6 @@
package carpet.utils;
import carpet.fakes.ChunkTicketManagerInterface;
-import carpet.fakes.ServerChunkManagerInterface;
import net.minecraft.server.level.DistanceManager;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.world.level.ChunkPos;
@@ -10,7 +9,7 @@ public class SpawnChunks
{
public static void changeSpawnChunks(ServerChunkCache chunkManager, ChunkPos pos, int size)
{
- DistanceManager ticketManager = ((ServerChunkManagerInterface)chunkManager).getCMTicketManager();
+ DistanceManager ticketManager = chunkManager.chunkMap.getDistanceManager();
((ChunkTicketManagerInterface)ticketManager).changeSpawnChunks(pos, size);
}
}