Skip to content

Commit 47cf177

Browse files
committed
1.21
2 parents e8ea849 + 23898d1 commit 47cf177

File tree

229 files changed

+9
-41536
lines changed

Some content is hidden

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

229 files changed

+9
-41536
lines changed

build.gradle

+1-32
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,4 @@ tasks.withType(JavaCompile).configureEach {
4949

5050
// Minecraft 1.20.5 upwards uses Java 21.
5151
it.options.release = 21
52-
}
53-
54-
java {
55-
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
56-
// if it is present.
57-
// If you remove this line, sources will not be generated.
58-
withSourcesJar()
59-
}
60-
61-
jar {
62-
from("LICENSE") {
63-
rename { "${it}_${project.archivesBaseName}"}
64-
}
65-
}
66-
67-
// configure the maven publication
68-
publishing {
69-
publications {
70-
mavenJava(MavenPublication) {
71-
from components.java
72-
}
73-
}
74-
75-
// Select the repositories you want to publish to
76-
// To publish to maven local, no extra repositories are necessary. Just use the task `publishToMavenLocal`.
77-
repositories {
78-
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
79-
maven {
80-
url "$projectDir/publish"
81-
}
82-
}
83-
}
52+
}

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;
@@ -54,7 +53,6 @@ public class CarpetSettings
5453
((SemanticVersion)FabricLoader.getInstance().getModContainer("minecraft").orElseThrow().getMetadata().getVersion()).getVersionComponent(2)
5554
};
5655
public static final Logger LOG = LoggerFactory.getLogger("carpet");
57-
public static final ThreadLocal<Boolean> skipGenerationChecks = ThreadLocal.withInitial(() -> false);
5856
public static final ThreadLocal<Boolean> impendingFillSkipUpdates = ThreadLocal.withInitial(() -> false);
5957
public static int runPermissionLevel = 2;
6058
public static Block structureBlockIgnoredBlock = Blocks.STRUCTURE_VOID;
@@ -466,105 +464,6 @@ public boolean enabled() {
466464
@Rule(desc = "Enables /draw commands", extra = {"... allows for drawing simple shapes or","other shapes which are sorta difficult to do normally"}, category = COMMAND)
467465
public static String commandDraw = "ops";
468466

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

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/commands/SpawnCommand.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package carpet.commands;
22

33
import carpet.CarpetSettings;
4-
import carpet.fakes.SpawnGroupInterface;
54
import carpet.helpers.HopperCounter;
65
import carpet.utils.CommandHelper;
76
import carpet.utils.Messenger;
@@ -229,7 +228,7 @@ private static int setSpawnRates(CommandSourceStack source, String mobtype, int
229228

230229
private static int setMobcaps(CommandSourceStack source, int hostile_cap)
231230
{
232-
double desired_ratio = (double)hostile_cap/ ((SpawnGroupInterface)(Object)MobCategory.MONSTER).getInitialSpawnCap();
231+
double desired_ratio = (double)hostile_cap/ MobCategory.MONSTER.getMaxInstancesPerChunk();
233232
SpawnReporter.mobcap_exponent = 4.0*Math.log(desired_ratio)/Math.log(2.0);
234233
Messenger.m(source, String.format("gi Mobcaps for hostile mobs changed to %d, other groups will follow", hostile_cap));
235234
return 1;

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

-13
This file was deleted.

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

-7
This file was deleted.

0 commit comments

Comments
 (0)