Skip to content

Commit 08833bf

Browse files
committed
1.20
1 parent d73ec4a commit 08833bf

File tree

212 files changed

+2
-41078
lines changed

Some content is hidden

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

212 files changed

+2
-41078
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

-33
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,16 @@
1616
import carpet.commands.ProfileCommand;
1717
import carpet.fakes.MinecraftServerInterface;
1818
import carpet.helpers.ServerTickRateManager;
19-
import carpet.script.ScriptCommand;
2019
import carpet.commands.SpawnCommand;
2120
import carpet.commands.TestCommand;
2221
import carpet.commands.TickCommand;
2322
import carpet.network.ServerNetworkHandler;
2423
import carpet.helpers.HopperCounter;
2524
import carpet.logging.LoggerRegistry;
26-
import carpet.script.CarpetScriptServer;
2725
import carpet.api.settings.CarpetRule;
2826
import carpet.api.settings.InvalidRuleValueException;
2927
import carpet.api.settings.SettingsManager;
3028
import carpet.logging.HUDController;
31-
import carpet.script.external.Carpet;
3229
import carpet.script.external.Vanilla;
3330
import carpet.script.utils.ParticleParser;
3431
import carpet.utils.MobAI;
@@ -47,7 +44,6 @@
4744
public class CarpetServer // static for now - easier to handle all around the code, its one anyways
4845
{
4946
public static MinecraftServer minecraft_server;
50-
public static CarpetScriptServer scriptServer;
5147
public static carpet.settings.SettingsManager settingsManager; // to change type to api type, can't change right now because of binary and source compat
5248
public static final List<CarpetExtension> extensions = new ArrayList<>();
5349

@@ -79,7 +75,6 @@ public static void onGameStarted()
7975
settingsManager.parseSettingsClass(CarpetSettings.class);
8076
extensions.forEach(CarpetExtension::onGameStarted);
8177
//FabricAPIHooks.initialize();
82-
CarpetScriptServer.parseFunctionClasses();
8378
}
8479

8580
public static void onServerLoaded(MinecraftServer server)
@@ -94,8 +89,6 @@ public static void onServerLoaded(MinecraftServer server)
9489
if (sm != null) sm.attachServer(server);
9590
e.onServerLoaded(server);
9691
});
97-
scriptServer = new CarpetScriptServer(server);
98-
Carpet.MinecraftServer_addScriptServer(server, scriptServer);
9992
MobAI.resetTrackers();
10093
LoggerRegistry.initLoggers();
10194
//TickSpeed.reset();
@@ -106,7 +99,6 @@ public static void onServerLoadedWorlds(MinecraftServer minecraftServer)
10699
HopperCounter.resetAll(minecraftServer, true);
107100
extensions.forEach(e -> e.onServerLoadedWorlds(minecraftServer));
108101
// initialize scarpet rules after all extensions are loaded
109-
settingsManager.initializeScarpetRules();
110102
// run fillLimit rule migration now that gamerules are available
111103
@SuppressWarnings("unchecked")
112104
CarpetRule<Integer> fillLimit = (CarpetRule<Integer>) settingsManager.getCarpetRule("fillLimit");
@@ -117,21 +109,13 @@ public static void onServerLoadedWorlds(MinecraftServer minecraftServer)
117109
{
118110
throw new AssertionError();
119111
}
120-
extensions.forEach(e -> {
121-
if (e.extensionSettingsManager() != null)
122-
{
123-
e.extensionSettingsManager().initializeScarpetRules();
124-
}
125-
});
126-
scriptServer.initializeForWorld();
127112
}
128113

129114
public static void tick(MinecraftServer server)
130115
{
131116
ServerTickRateManager trm = ((MinecraftServerInterface)server).getTickRateManager();
132117
trm.tick();
133118
HUDController.update_hud(server, null);
134-
if (scriptServer != null) scriptServer.tick();
135119

136120
//in case something happens
137121
CarpetSettings.impendingFillSkipUpdates.set(false);
@@ -160,7 +144,6 @@ public static void registerCarpetCommands(CommandDispatcher<CommandSourceStack>
160144
DistanceCommand.register(dispatcher, commandBuildContext);
161145
PerimeterInfoCommand.register(dispatcher, commandBuildContext);
162146
DrawCommand.register(dispatcher, commandBuildContext);
163-
ScriptCommand.register(dispatcher, commandBuildContext);
164147
MobAICommand.register(dispatcher, commandBuildContext);
165148
// registering command of extensions that has registered before either server is created
166149
// for all other, they will have them registered when they add themselves
@@ -181,7 +164,6 @@ public static void onPlayerLoggedIn(ServerPlayer player)
181164
ServerNetworkHandler.onPlayerJoin(player);
182165
LoggerRegistry.playerConnected(player);
183166
extensions.forEach(e -> e.onPlayerLoggedIn(player));
184-
scriptServer.onPlayerJoin(player);
185167
}
186168

187169
@Deprecated(forRemoval = true)
@@ -194,17 +176,10 @@ public static void onPlayerLoggedOut(ServerPlayer player, Component reason)
194176
ServerNetworkHandler.onPlayerLoggedOut(player);
195177
LoggerRegistry.playerDisconnected(player);
196178
extensions.forEach(e -> e.onPlayerLoggedOut(player));
197-
// first case client, second case server
198-
CarpetScriptServer runningScriptServer = (player.getServer() == null) ? scriptServer : Vanilla.MinecraftServer_getScriptServer(player.getServer());
199-
if (runningScriptServer != null && !runningScriptServer.stopAll) {
200-
runningScriptServer.onPlayerLoggedOut(player, reason);
201-
}
202179
}
203180

204181
public static void clientPreClosing()
205182
{
206-
if (scriptServer != null) scriptServer.onClose();
207-
scriptServer = null;
208183
}
209184

210185
public static void onServerClosed(MinecraftServer server)
@@ -213,13 +188,6 @@ public static void onServerClosed(MinecraftServer server)
213188
// so we allow to pass multiple times gating it only on existing server ref
214189
if (minecraft_server != null)
215190
{
216-
if (scriptServer != null) scriptServer.onClose();
217-
// this is a mess, will cleanip onlly when global reference is gone
218-
if (!Vanilla.MinecraftServer_getScriptServer(server).stopAll) {
219-
Vanilla.MinecraftServer_getScriptServer(server).onClose();
220-
}
221-
222-
scriptServer = null;
223191
ServerNetworkHandler.close();
224192

225193
LoggerRegistry.stopLoggers();
@@ -245,7 +213,6 @@ public static void registerExtensionLoggers()
245213

246214
public static void onReload(MinecraftServer server)
247215
{
248-
scriptServer.reload(server);
249216
extensions.forEach(e -> e.onReload(server));
250217
}
251218

src/main/java/carpet/CarpetSettings.java

-75
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.external.Carpet;
87
import carpet.settings.Rule;
98
import carpet.utils.Translations;
109
import carpet.utils.CommandHelper;
@@ -52,7 +51,6 @@ public class CarpetSettings
5251
public static final String carpetVersion = FabricLoader.getInstance().getModContainer("carpet").orElseThrow().getMetadata().getVersion().toString();
5352
public static final String releaseTarget = "1.19.4";
5453
public static final Logger LOG = LoggerFactory.getLogger("carpet");
55-
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
5654
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
5755
public static int runPermissionLevel = 2;
5856
public static Block structureBlockIgnoredBlock = Blocks.STRUCTURE_VOID;
@@ -492,79 +490,6 @@ public boolean enabled() {
492490
@Rule(desc = "Enables /draw commands", extra = {"... allows for drawing simple shapes or","other shapes which are sorta difficult to do normally"}, category = COMMAND)
493491
public static String commandDraw = "ops";
494492

495-
496-
@Rule(
497-
desc = "Enables /script command",
498-
extra = "An in-game scripting API for Scarpet programming language",
499-
category = {COMMAND, SCARPET}
500-
)
501-
public static String commandScript = "true";
502-
503-
private static class ModulePermissionLevel extends Validator<String> {
504-
@Override public String validate(CommandSourceStack source, CarpetRule<String> currentRule, String newValue, String string) {
505-
int permissionLevel = switch (newValue) {
506-
case "false" -> 0;
507-
case "true", "ops" -> 2;
508-
case "0", "1", "2", "3", "4" -> Integer.parseInt(newValue);
509-
default -> throw new IllegalArgumentException(); // already checked by previous validator
510-
};
511-
if (source != null && !source.hasPermission(permissionLevel))
512-
return null;
513-
CarpetSettings.runPermissionLevel = permissionLevel;
514-
if (source != null)
515-
CommandHelper.notifyPlayersCommandsChanged(source.getServer());
516-
return newValue;
517-
}
518-
@Override
519-
public String description() { return "When changing the rule, you must at least have the permission level you are trying to give it";}
520-
}
521-
@Rule(
522-
desc = "Enables restrictions for arbitrary code execution with scarpet",
523-
extra = {
524-
"Users that don't have this permission level",
525-
"won't be able to load apps or /script run.",
526-
"It is also the permission level apps will",
527-
"have when running commands with run()"
528-
},
529-
category = {SCARPET},
530-
options = {"ops", "0", "1", "2", "3", "4"},
531-
validate = {Validators.CommandLevel.class, ModulePermissionLevel.class}
532-
)
533-
public static String commandScriptACE = "ops";
534-
535-
@Rule(
536-
desc = "Scarpet script from world files will autoload on server/world start ",
537-
extra = "if /script is enabled",
538-
category = SCARPET
539-
)
540-
public static boolean scriptsAutoload = true;
541-
542-
@Rule(
543-
desc = "Enables scripts debugging messages in system log",
544-
category = SCARPET
545-
)
546-
public static boolean scriptsDebugging = false;
547-
548-
@Rule(
549-
desc = "Enables scripts optimization",
550-
category = SCARPET
551-
)
552-
public static boolean scriptsOptimization = true;
553-
554-
@Rule(
555-
desc = "Location of the online repository of scarpet apps",
556-
extra = {
557-
"set to 'none' to disable.",
558-
"Point to any github repo with scarpet apps",
559-
"using <user>/<repo>/contents/<path...>"
560-
},
561-
category = SCARPET,
562-
strict = false,
563-
validate= Carpet.ScarpetAppStoreValidator.class
564-
)
565-
public static String scriptsAppStore = "gnembon/scarpet/contents/programs";
566-
567-
568493
@Rule(desc = "Enables /player command to control/spawn players", category = COMMAND)
569494
public static String commandPlayer = "ops";
570495

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)