Skip to content

Commit 23898d1

Browse files
committed
1.20.4
1 parent ab79e76 commit 23898d1

File tree

215 files changed

+2
-41225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

215 files changed

+2
-41225
lines changed

src/main/java/carpet/CarpetExtension.java

-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package carpet;
22

3-
import carpet.script.CarpetExpression;
43
import carpet.api.settings.SettingsManager;
54
import com.mojang.brigadier.CommandDispatcher;
65
import net.minecraft.commands.CommandBuildContext;
@@ -150,21 +149,4 @@ default void registerLoggers() {}
150149
*/
151150
default Map<String, String> canHasTranslations(String lang) { return Collections.emptyMap();}
152151

153-
/**
154-
* Handles each call that creates / parses the scarpet expression.
155-
* Extensions can add their own built-in functions here.
156-
*
157-
* Events such as generic events or entity events, can be added statically
158-
* by creating new events as
159-
*
160-
* CarpetEventServer.Event class: to handle `__on_foo()` type of call definitions
161-
*
162-
* or
163-
*
164-
* EntityEventsGroup.Event class: to handle `entity_event('foo', ...)` type of events
165-
*
166-
* @param expression Passed {@link CarpetExpression} to add built-in functions to
167-
*/
168-
default void scarpetApi(CarpetExpression expression) {}
169-
170152
}

src/main/java/carpet/CarpetServer.java

-29
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@
1515
import carpet.commands.PerimeterInfoCommand;
1616
import carpet.commands.PlayerCommand;
1717
import carpet.commands.ProfileCommand;
18-
import carpet.script.ScriptCommand;
1918
import carpet.commands.SpawnCommand;
2019
import carpet.commands.TestCommand;
2120
import carpet.network.ServerNetworkHandler;
2221
import carpet.helpers.HopperCounter;
2322
import carpet.logging.LoggerRegistry;
24-
import carpet.script.CarpetScriptServer;
2523
import carpet.api.settings.SettingsManager;
2624
import carpet.logging.HUDController;
27-
import carpet.script.external.Carpet;
28-
import carpet.script.external.Vanilla;
2925
import carpet.script.utils.ParticleParser;
3026
import carpet.utils.MobAI;
3127
import carpet.utils.SpawnReporter;
@@ -43,7 +39,6 @@
4339
public class CarpetServer // static for now - easier to handle all around the code, its one anyways
4440
{
4541
public static MinecraftServer minecraft_server;
46-
public static CarpetScriptServer scriptServer;
4742
public static carpet.settings.SettingsManager settingsManager; // to change type to api type, can't change right now because of binary and source compat
4843
public static final List<CarpetExtension> extensions = new ArrayList<>();
4944

@@ -75,7 +70,6 @@ public static void onGameStarted()
7570
settingsManager.parseSettingsClass(CarpetSettings.class);
7671
extensions.forEach(CarpetExtension::onGameStarted);
7772
//FabricAPIHooks.initialize();
78-
CarpetScriptServer.parseFunctionClasses();
7973
}
8074

8175
public static void onServerLoaded(MinecraftServer server)
@@ -86,8 +80,6 @@ public static void onServerLoaded(MinecraftServer server)
8680

8781
forEachManager(sm -> sm.attachServer(server));
8882
extensions.forEach(e -> e.onServerLoaded(server));
89-
scriptServer = new CarpetScriptServer(server);
90-
Carpet.MinecraftServer_addScriptServer(server, scriptServer);
9183
MobAI.resetTrackers();
9284
LoggerRegistry.initLoggers();
9385
//TickSpeed.reset();
@@ -97,15 +89,11 @@ public static void onServerLoadedWorlds(MinecraftServer minecraftServer)
9789
{
9890
HopperCounter.resetAll(minecraftServer, true);
9991
extensions.forEach(e -> e.onServerLoadedWorlds(minecraftServer));
100-
// initialize scarpet rules after all extensions are loaded
101-
forEachManager(SettingsManager::initializeScarpetRules);
102-
scriptServer.initializeForWorld();
10392
}
10493

10594
public static void tick(MinecraftServer server)
10695
{
10796
HUDController.update_hud(server, null);
108-
if (scriptServer != null) scriptServer.tick();
10997

11098
//in case something happens
11199
CarpetSettings.impendingFillSkipUpdates.set(false);
@@ -130,7 +118,6 @@ public static void registerCarpetCommands(CommandDispatcher<CommandSourceStack>
130118
DistanceCommand.register(dispatcher, commandBuildContext);
131119
PerimeterInfoCommand.register(dispatcher, commandBuildContext);
132120
DrawCommand.register(dispatcher, commandBuildContext);
133-
ScriptCommand.register(dispatcher, commandBuildContext);
134121
MobAICommand.register(dispatcher, commandBuildContext);
135122
// registering command of extensions that has registered before either server is created
136123
// for all other, they will have them registered when they add themselves
@@ -151,25 +138,17 @@ public static void onPlayerLoggedIn(ServerPlayer player)
151138
ServerNetworkHandler.onPlayerJoin(player);
152139
LoggerRegistry.playerConnected(player);
153140
extensions.forEach(e -> e.onPlayerLoggedIn(player));
154-
scriptServer.onPlayerJoin(player);
155141
}
156142

157143
public static void onPlayerLoggedOut(ServerPlayer player, Component reason)
158144
{
159145
ServerNetworkHandler.onPlayerLoggedOut(player);
160146
LoggerRegistry.playerDisconnected(player);
161147
extensions.forEach(e -> e.onPlayerLoggedOut(player));
162-
// first case client, second case server
163-
CarpetScriptServer runningScriptServer = (player.getServer() == null) ? scriptServer : Vanilla.MinecraftServer_getScriptServer(player.getServer());
164-
if (runningScriptServer != null && !runningScriptServer.stopAll) {
165-
runningScriptServer.onPlayerLoggedOut(player, reason);
166-
}
167148
}
168149

169150
public static void clientPreClosing()
170151
{
171-
if (scriptServer != null) scriptServer.onClose();
172-
scriptServer = null;
173152
}
174153

175154
public static void onServerClosed(MinecraftServer server)
@@ -178,13 +157,6 @@ public static void onServerClosed(MinecraftServer server)
178157
// so we allow to pass multiple times gating it only on existing server ref
179158
if (minecraft_server != null)
180159
{
181-
if (scriptServer != null) scriptServer.onClose();
182-
// this is a mess, will cleanip onlly when global reference is gone
183-
if (!Vanilla.MinecraftServer_getScriptServer(server).stopAll) {
184-
Vanilla.MinecraftServer_getScriptServer(server).onClose();
185-
}
186-
187-
scriptServer = null;
188160
ServerNetworkHandler.close();
189161

190162
LoggerRegistry.stopLoggers();
@@ -221,7 +193,6 @@ public static void registerExtensionLoggers()
221193

222194
public static void onReload(MinecraftServer server)
223195
{
224-
scriptServer.reload(server);
225196
extensions.forEach(e -> e.onReload(server));
226197
}
227198

src/main/java/carpet/CarpetSettings.java

-101
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import carpet.api.settings.RuleCategory;
55
import carpet.api.settings.Validators;
66
import carpet.api.settings.Validator;
7-
import carpet.script.utils.AppStoreManager;
87
import carpet.settings.Rule;
98
import carpet.utils.Translations;
109
import carpet.utils.CommandHelper;
@@ -51,7 +50,6 @@ public class CarpetSettings
5150
public static final String carpetVersion = FabricLoader.getInstance().getModContainer("carpet").orElseThrow().getMetadata().getVersion().toString();
5251
public static final String releaseTarget = "1.20.3";
5352
public static final Logger LOG = LoggerFactory.getLogger("carpet");
54-
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
5553
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
5654
public static int runPermissionLevel = 2;
5755
public static Block structureBlockIgnoredBlock = Blocks.STRUCTURE_VOID;
@@ -463,105 +461,6 @@ public boolean enabled() {
463461
@Rule(desc = "Enables /draw commands", extra = {"... allows for drawing simple shapes or","other shapes which are sorta difficult to do normally"}, category = COMMAND)
464462
public static String commandDraw = "ops";
465463

466-
467-
@Rule(
468-
desc = "Enables /script command",
469-
extra = "An in-game scripting API for Scarpet programming language",
470-
category = {COMMAND, SCARPET}
471-
)
472-
public static String commandScript = "true";
473-
474-
private static class ModulePermissionLevel extends Validator<String> {
475-
@Override public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
476-
int permissionLevel = switch (newValue) {
477-
case "false" -> 0;
478-
case "true", "ops" -> 2;
479-
case "0", "1", "2", "3", "4" -> Integer.parseInt(newValue);
480-
default -> throw new IllegalArgumentException(); // already checked by previous validator
481-
};
482-
if (source != null && !source.hasPermission(permissionLevel))
483-
return null;
484-
CarpetSettings.runPermissionLevel = permissionLevel;
485-
if (source != null)
486-
CommandHelper.notifyPlayersCommandsChanged(source.getServer());
487-
return newValue;
488-
}
489-
@Override
490-
public String description() { return "When changing the rule, you must at least have the permission level you are trying to give it";}
491-
}
492-
@Rule(
493-
desc = "Enables restrictions for arbitrary code execution with scarpet",
494-
extra = {
495-
"Users that don't have this permission level",
496-
"won't be able to load apps or /script run.",
497-
"It is also the permission level apps will",
498-
"have when running commands with run()"
499-
},
500-
category = {SCARPET},
501-
options = {"ops", "0", "1", "2", "3", "4"},
502-
validate = {Validators.CommandLevel.class, ModulePermissionLevel.class}
503-
)
504-
public static String commandScriptACE = "ops";
505-
506-
@Rule(
507-
desc = "Scarpet script from world files will autoload on server/world start ",
508-
extra = "if /script is enabled",
509-
category = SCARPET
510-
)
511-
public static boolean scriptsAutoload = true;
512-
513-
@Rule(
514-
desc = "Enables scripts debugging messages in system log",
515-
category = SCARPET
516-
)
517-
public static boolean scriptsDebugging = false;
518-
519-
@Rule(
520-
desc = "Enables scripts optimization",
521-
category = SCARPET
522-
)
523-
public static boolean scriptsOptimization = true;
524-
525-
private static class ScarpetAppStore extends Validator<String> {
526-
@Override
527-
public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String stringInput) {
528-
if (newValue.equals(currentRule.value())) {
529-
// Don't refresh the local repo if it's the same (world change), helps preventing hitting rate limits from github when
530-
// getting suggestions. Pending is a way to invalidate the cache when it gets old, and investigating api usage further
531-
return newValue;
532-
}
533-
if (newValue.equals("none")) {
534-
AppStoreManager.setScarpetRepoLink(null);
535-
} else {
536-
if (newValue.endsWith("/"))
537-
newValue = newValue.substring(0, newValue.length() - 1);
538-
AppStoreManager.setScarpetRepoLink("https://api.github.com/repos/" + newValue + "/");
539-
}
540-
if (source != null)
541-
CommandHelper.notifyPlayersCommandsChanged(source.getServer());
542-
return newValue;
543-
}
544-
545-
@Override
546-
public String description() {
547-
return "Appstore link should point to a valid github repository";
548-
}
549-
}
550-
551-
@Rule(
552-
desc = "Location of the online repository of scarpet apps",
553-
extra = {
554-
"set to 'none' to disable.",
555-
"Point to any github repo with scarpet apps",
556-
"using <user>/<repo>/contents/<path...>"
557-
},
558-
category = SCARPET,
559-
strict = false,
560-
validate = ScarpetAppStore.class
561-
)
562-
public static String scriptsAppStore = "gnembon/scarpet/contents/programs";
563-
564-
565464
@Rule(desc = "Enables /player command to control/spawn players", category = COMMAND)
566465
public static String commandPlayer = "ops";
567466

src/main/java/carpet/api/settings/SettingsManager.java

-27
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,6 @@ public void notifyRuleChanged(CommandSourceStack source, CarpetRule<?> rule, Str
262262
observers.forEach(observer -> observer.ruleChanged(source, rule, userInput));
263263
staticObservers.forEach(observer -> observer.ruleChanged(source, rule, userInput));
264264
ServerNetworkHandler.updateRuleWithConnectedClients(rule);
265-
switchScarpetRuleIfNeeded(source, rule); //TODO move into rule
266265
}
267266

268267
/**
@@ -287,19 +286,6 @@ public void detachServer()
287286
for (CarpetRule<?> rule : rules.values()) RuleHelper.resetToDefault(rule, null);
288287
server = null;
289288
}
290-
291-
/**
292-
* <p>Initializes Scarpet rules in this {@link SettingsManager}, if any.</p>
293-
* <p>This is handled automatically by Carpet and calling it is not supported.</p>
294-
*/
295-
public void initializeScarpetRules() { //TODO try remove
296-
for (CarpetRule<?> rule : rules.values())
297-
{
298-
if (rule instanceof ParsedRule<?> pr && !pr.scarpetApp.isEmpty()) {
299-
switchScarpetRuleIfNeeded(server.createCommandSourceStack(), pr);
300-
}
301-
}
302-
}
303289

304290
/**
305291
* Calling this method is not supported.
@@ -324,19 +310,6 @@ public void inspectClientsideCommand(CommandSourceStack source, String string)
324310
}
325311
}
326312
}
327-
328-
private void switchScarpetRuleIfNeeded(CommandSourceStack source, CarpetRule<?> carpetRule) //TODO remove. This should be handled by the rule
329-
{
330-
if (carpetRule instanceof ParsedRule<?> rule && !rule.scarpetApp.isEmpty() && CarpetServer.scriptServer != null) // null check because we may be in server init
331-
{
332-
if (RuleHelper.getBooleanValue(rule) || (rule.type() == String.class && !rule.value().equals("false")))
333-
{
334-
CarpetServer.scriptServer.addScriptHost(source, rule.scarpetApp, s -> CommandHelper.canUseCommand(s, rule.value()), false, false, true, null);
335-
} else {
336-
CarpetServer.scriptServer.removeScriptHost(source, rule.scarpetApp, false, true);
337-
}
338-
}
339-
}
340313

341314
private Path getFile()
342315
{

src/main/java/carpet/fakes/AbstractContainerMenuInterface.java

-13
This file was deleted.

src/main/java/carpet/fakes/BiomeInterface.java

-7
This file was deleted.

src/main/java/carpet/fakes/BlockPredicateInterface.java

-16
This file was deleted.

src/main/java/carpet/fakes/BlockStateArgumentInterface.java

-8
This file was deleted.

src/main/java/carpet/fakes/ChunkHolderInterface.java

-14
This file was deleted.

src/main/java/carpet/fakes/CommandDispatcherInterface.java

-5
This file was deleted.

src/main/java/carpet/fakes/CommandNodeInterface.java

-5
This file was deleted.

0 commit comments

Comments
 (0)