From 14be166935b09bb2ed7cf86e495813a067a47d5d Mon Sep 17 00:00:00 2001 From: Yuuta Liang Date: Wed, 29 Sep 2021 20:01:56 -0700 Subject: [PATCH 1/9] allow specifying game modes when spawning fake players (#1117) This enables administrators to flexibly spawn players in game modes other than their current modes, and also allows administrators to spawn non-creative players from the console or rcon. Usage: /player spawn bot in Usage: /player spawn bot at ~ ~ ~ face 0 0 in minecraft:overworld in Permissions required: OP Level 2 and above. Note on flying: For spectator players, flying is always enabled. For other game modes, whether they are flying depends on the command caller. Therefore, it is possible to spawn a flying survival player when you are currently flying. --- .../java/carpet/commands/PlayerCommand.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/commands/PlayerCommand.java b/src/main/java/carpet/commands/PlayerCommand.java index b849276b..69dcce4b 100644 --- a/src/main/java/carpet/commands/PlayerCommand.java +++ b/src/main/java/carpet/commands/PlayerCommand.java @@ -35,6 +35,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Set; import java.util.function.Consumer; +import java.util.stream.Collectors; import static net.minecraft.server.command.CommandManager.argument; import static net.minecraft.server.command.CommandManager.literal; @@ -46,6 +47,10 @@ public class PlayerCommand // TODO: allow any order like execute public static void register(CommandDispatcher dispatcher) { + final String[] gamemodeStrings = Arrays.stream(GameMode.values()) + .map(GameMode::getName) + .collect(Collectors.toList()) + .toArray(new String[]{}); LiteralArgumentBuilder literalargumentbuilder = literal("player") .requires((player) -> SettingsManager.canUseCommand(player, CarpetSettings.commandPlayer)) .then(argument("player", StringArgumentType.word()) @@ -93,10 +98,18 @@ public class PlayerCommand .then(literal("left").executes(c -> manipulate(c, ap -> ap.setStrafing(1)))) .then(literal("right").executes(c -> manipulate(c, ap -> ap.setStrafing(-1)))) ).then(literal("spawn").executes(PlayerCommand::spawn) + .then(literal("in").requires((player) -> player.hasPermissionLevel(2)) + .then(argument("gamemode", StringArgumentType.word()) + .suggests( (c, b) -> suggestMatching(gamemodeStrings, b)) + .executes(PlayerCommand::spawn))) .then(literal("at").then(argument("position", Vec3ArgumentType.vec3()).executes(PlayerCommand::spawn) .then(literal("facing").then(argument("direction", RotationArgumentType.rotation()).executes(PlayerCommand::spawn) - .then(literal("in").then(argument("dimension", DimensionArgumentType.dimension()).executes(PlayerCommand::spawn))) - )) + .then(literal("in").then(argument("dimension", DimensionArgumentType.dimension()).executes(PlayerCommand::spawn) + .then(literal("in").requires((player) -> player.hasPermissionLevel(2)) + .then(argument("gamemode", StringArgumentType.word()).suggests( (c, b) -> suggestMatching(gamemodeStrings, b)) + .executes(PlayerCommand::spawn) + ))) + ))) )) ) ); @@ -273,6 +286,20 @@ public class PlayerCommand flying = player.getAbilities().flying; } catch (CommandSyntaxException ignored) {} + try { + String opGameMode = StringArgumentType.getString(context, "gamemode"); + mode = GameMode.byName(opGameMode, null); + if(mode == null) + { + Messenger.m(context.getSource(), "rb Invalid game mode: "+opGameMode+"."); + return 0; + } + } catch (IllegalArgumentException ignored) {} + if(mode == GameMode.SPECTATOR) + { + // Force override flying to true for spectator players, or they will fell out of the world. + flying = true; + } String playerName = StringArgumentType.getString(context, "player"); if (playerName.length()>maxPlayerLength(source.getServer())) { From d034b8945adc26b950ff76ceb3b3bafd0c3a4328 Mon Sep 17 00:00:00 2001 From: altrisi Date: Wed, 6 Oct 2021 02:21:29 +0200 Subject: [PATCH 2/9] Move some functions into `system_info` (#1084) * Move some functions into `system_info` * Add docs for new `system_info()` properties --- docs/scarpet/api/Auxiliary.md | 13 ++++++++++ .../java/carpet/script/api/Auxiliary.java | 25 ++++++++----------- .../java/carpet/script/utils/SystemInfo.java | 15 +++++++++++ 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/docs/scarpet/api/Auxiliary.md b/docs/scarpet/api/Auxiliary.md index 3ae4e775..9c0eb46d 100644 --- a/docs/scarpet/api/Auxiliary.md +++ b/docs/scarpet/api/Auxiliary.md @@ -540,6 +540,8 @@ Returns server tick counter. Can be used to run certain operations every n-th ti ### `world_time()` +_**Deprecated**. Use `system_info('world_time')` instead._ + Returns dimension-specific tick counter. ### `day_time(new_time?)` @@ -549,6 +551,8 @@ to that value. Daytime clocks are shared between all dimensions. ### `last_tick_times()` +_**Deprecated**. Use `system_info('server_last_tick_times')` instead._ + Returns a 100-long array of recent tick times, in milliseconds. First item on the list is the most recent tick If called outside of the main tick (either throgh scheduled tasks, or async execution), then the first item on the list may refer to the previous tick performance. In this case the last entry (tick 100) would refer to the most current @@ -600,6 +604,9 @@ world-localized block, so not `block('stone')`, or a string representing a dimen Throws `unknown_dimension` if provided dimension can't be found. ### `view_distance()` + +_**Deprecated**. Use `system_info('server_view_distance')` instead._ + Returns the view distance of the server. ### `get_mob_counts()`, `get_mob_counts(category)` 1.16+ @@ -659,6 +666,7 @@ Available options in the scarpet app space: * `world_carpet_rules` - returns all Carpet rules in a map form (`rule`->`value`). Note that the values are always returned as strings, so you can't do boolean comparisons directly. Includes rules from extensions with their namespace (`namespace:rule`->`value`). You can later listen to rule changes with the `on_carpet_rule_changes(rule, newValue)` event. * `world_gamerules` - returns all gamerules in a map form (`rule`->`value`). Like carpet rules, values are returned as strings, so you can use appropriate value conversions using `bool()` or `number()` to convert them to other values. Gamerules are read-only to discourage app programmers to mess up with the settings intentionally applied by server admins. Isn't that just super annoying when a datapack messes up with your gamerule settings? It is still possible to change them though using `run('gamerule ...`. * `world_spawn_point` - world spawn point + * `world_time` - Returns dimension-specific tick counter. Relevant gameplay related properties * `game_difficulty` - current difficulty of the game: `'peaceful'`, `'easy'`, `'normal'`, or `'hard'` @@ -686,6 +694,11 @@ Available options in the scarpet app space: * `server_banned_ips` - list of banned IP addresses * `server_dev_environment` - boolean indicating whether this server is in a development environment. * `server_mods` - map with all loaded mods mapped to their versions as strings + * `server_last_tick_times` - Returns a 100-long array of recent tick times, in milliseconds. First item on the list is the most recent tick +If called outside of the main tick (either throgh scheduled tasks, or async execution), then the first item on the +list may refer to the previous tick performance. In this case the last entry (tick 100) would refer to the most current +tick. For all intent and purpose, `system_info('last_tick_times'):0` should be used as last tick execution time, but +individual tick times may vary greatly, and these need to be taken with the little grain of averaging. System related properties * `java_max_memory` - maximum allowed memory accessible by JVM diff --git a/src/main/java/carpet/script/api/Auxiliary.java b/src/main/java/carpet/script/api/Auxiliary.java index 4ee85a2b..5a913dd7 100644 --- a/src/main/java/carpet/script/api/Auxiliary.java +++ b/src/main/java/carpet/script/api/Auxiliary.java @@ -21,6 +21,7 @@ import carpet.script.exception.InternalExpressionException; import carpet.script.exception.ThrowStatement; import carpet.script.exception.Throwables; import carpet.script.utils.SnoopyCommandSource; +import carpet.script.utils.SystemInfo; import carpet.script.utils.InputValidator; import carpet.script.utils.ScarpetJsonDeserializer; import carpet.script.utils.ShapeDispatcher; @@ -655,8 +656,10 @@ public class Auxiliary { expression.addContextFunction("tick_time", 0, (c, t, lv) -> new NumericValue(((CarpetContext) c).s.getServer().getTicks())); - expression.addContextFunction("world_time", 0, (c, t, lv) -> - new NumericValue(((CarpetContext) c).s.getWorld().getTime())); + expression.addContextFunction("world_time", 0, (c, t, lv) -> { + c.host.issueDeprecation("world_time()"); + return new NumericValue(((CarpetContext) c).s.getWorld().getTime()); + }); expression.addContextFunction("day_time", -1, (c, t, lv) -> { @@ -672,16 +675,8 @@ public class Auxiliary { expression.addContextFunction("last_tick_times", -1, (c, t, lv) -> { - //assuming we are in the tick world section - // might be off one tick when run in the off tasks or asynchronously. - int currentReportedTick = ((CarpetContext) c).s.getServer().getTicks()-1; - List ticks = new ArrayList<>(100); - final long[] tickArray = ((CarpetContext) c).s.getServer().lastTickLengths; - for (int i=currentReportedTick+100; i > currentReportedTick; i--) - { - ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0)); - } - return ListValue.wrap(ticks); + c.host.issueDeprecation("last_tick_times()"); + return SystemInfo.get("last_tick_times", (CarpetContext)c); }); @@ -742,8 +737,10 @@ public class Auxiliary { expression.addContextFunction("current_dimension", 0, (c, t, lv) -> ValueConversions.of( ((CarpetContext)c).s.getWorld())); - expression.addContextFunction("view_distance", 0, (c, t, lv) -> - new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance())); + expression.addContextFunction("view_distance", 0, (c, t, lv) -> { + c.host.issueDeprecation("view_distance()"); + return new NumericValue(((CarpetContext)c).s.getServer().getPlayerManager().getViewDistance()); + }); // lazy due to passthrough and context changing ability expression.addLazyFunction("in_dimension", 2, (c, t, lv) -> { diff --git a/src/main/java/carpet/script/utils/SystemInfo.java b/src/main/java/carpet/script/utils/SystemInfo.java index 227387c1..1f55ba65 100644 --- a/src/main/java/carpet/script/utils/SystemInfo.java +++ b/src/main/java/carpet/script/utils/SystemInfo.java @@ -23,9 +23,11 @@ import net.minecraft.world.WorldProperties; import java.lang.management.ManagementFactory; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Function; @@ -58,6 +60,7 @@ public class SystemInfo { WorldProperties prop = c.s.getServer().getOverworld().getLevelProperties(); return ListValue.of(NumericValue.of(prop.getSpawnX()), NumericValue.of(prop.getSpawnY()), NumericValue.of(prop.getSpawnZ())); }); + put("world_time", c -> new NumericValue(c.s.getWorld().getTime())); put("game_difficulty", c -> StringValue.of(c.s.getServer().getSaveProperties().getDifficulty().getName())); put("game_hardcore", c -> BooleanValue.of(c.s.getServer().getSaveProperties().isHardcore())); @@ -114,6 +117,18 @@ public class SystemInfo { ret.put(new StringValue(mod.getMetadata().getName()), new StringValue(mod.getMetadata().getVersion().getFriendlyString())); return MapValue.wrap(ret); }); + put("server_last_tick_times", c -> { + //assuming we are in the tick world section + // might be off one tick when run in the off tasks or asynchronously. + int currentReportedTick = c.s.getServer().getTicks()-1; + List ticks = new ArrayList<>(100); + final long[] tickArray = c.s.getServer().lastTickLengths; + for (int i=currentReportedTick+100; i > currentReportedTick; i--) + { + ticks.add(new NumericValue(((double)tickArray[i % 100])/1000000.0)); + } + return ListValue.wrap(ticks); + }); put("java_max_memory", c -> new NumericValue(Runtime.getRuntime().maxMemory())); put("java_allocated_memory", c -> new NumericValue(Runtime.getRuntime().totalMemory())); From 7e04c9dc1de7bcfc7d461f4905c518f5c3c88459 Mon Sep 17 00:00:00 2001 From: Fx Morin Date: Mon, 11 Oct 2021 00:58:45 -0400 Subject: [PATCH 3/9] Better search through rules (#1119) * Better search through rules Changed carpets search from startsWith to Contains. It's been annoying me for a long time now, the fact that you never remember the command name, but you remember something that was in it. * Checking camelCase for contains --- .../java/carpet/settings/SettingsManager.java | 33 ++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/main/java/carpet/settings/SettingsManager.java b/src/main/java/carpet/settings/SettingsManager.java index 8c81d93b..7a2c46fe 100644 --- a/src/main/java/carpet/settings/SettingsManager.java +++ b/src/main/java/carpet/settings/SettingsManager.java @@ -13,6 +13,8 @@ import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.SimpleCommandExceptionType; +import com.mojang.brigadier.suggestion.Suggestions; +import com.mojang.brigadier.suggestion.SuggestionsBuilder; import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.entity.player.PlayerEntity; @@ -34,16 +36,10 @@ import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.TreeMap; +import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; +import java.util.stream.Stream; import static carpet.utils.Translations.tr; import static carpet.script.CarpetEventServer.Event.CARPET_RULE_CHANGES; @@ -544,6 +540,19 @@ public class SettingsManager return rule; } + static CompletableFuture suggestMatchingContains(Stream stream, SuggestionsBuilder suggestionsBuilder) { + String title = suggestionsBuilder.getRemaining().toLowerCase(Locale.ROOT); + Stream filteredSuggestionList = stream.filter((listItem) -> { //Regex camelCase Search + String name = listItem.toLowerCase(Locale.ROOT); + return name.startsWith(title) || Arrays.stream(name.split("(? { + return piece.contains(title); + }); + }); + Objects.requireNonNull(suggestionsBuilder); + filteredSuggestionList.forEach(msg -> suggestionsBuilder.suggest((String)msg)); + return suggestionsBuilder.buildFuture(); + } + /** * Registers the the settings command for this {@link SettingsManager}.
* It is handled automatically by Carpet. @@ -576,17 +585,17 @@ public class SettingsManager then(literal("removeDefault"). requires(s -> !locked). then(argument("rule", StringArgumentType.word()). - suggests( (c, b) -> suggestMatching(getRules().stream().map(r -> r.name), b)). + suggests( (c, b) -> suggestMatchingContains(getRules().stream().map(r -> r.name), b)). executes((c) -> removeDefault(c.getSource(), contextRule(c))))). then(literal("setDefault"). requires(s -> !locked). then(argument("rule", StringArgumentType.word()). - suggests( (c, b) -> suggestMatching(getRules().stream().map(r -> r.name), b)). + suggests( (c, b) -> suggestMatchingContains(getRules().stream().map(r -> r.name), b)). then(argument("value", StringArgumentType.greedyString()). suggests((c, b)-> suggestMatching(contextRule(c).options, b)). executes((c) -> setDefault(c.getSource(), contextRule(c), StringArgumentType.getString(c, "value")))))). then(argument("rule", StringArgumentType.word()). - suggests( (c, b) -> suggestMatching(getRules().stream().map(r -> r.name), b)). + suggests( (c, b) -> suggestMatchingContains(getRules().stream().map(r -> r.name), b)). requires(s -> !locked ). executes( (c) -> displayRuleMenu(c.getSource(), contextRule(c))). then(argument("value", StringArgumentType.greedyString()). From 736c10abe62fa45a8904560a2d4c069fa55613d1 Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 11 Oct 2021 05:30:39 -0300 Subject: [PATCH 4/9] fixed completion --- .../java/carpet/settings/SettingsManager.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/carpet/settings/SettingsManager.java b/src/main/java/carpet/settings/SettingsManager.java index 7a2c46fe..b7af8e69 100644 --- a/src/main/java/carpet/settings/SettingsManager.java +++ b/src/main/java/carpet/settings/SettingsManager.java @@ -36,7 +36,17 @@ import java.lang.reflect.Field; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.nio.file.Path; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeMap; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -541,15 +551,16 @@ public class SettingsManager } static CompletableFuture suggestMatchingContains(Stream stream, SuggestionsBuilder suggestionsBuilder) { - String title = suggestionsBuilder.getRemaining().toLowerCase(Locale.ROOT); - Stream filteredSuggestionList = stream.filter((listItem) -> { //Regex camelCase Search - String name = listItem.toLowerCase(Locale.ROOT); - return name.startsWith(title) || Arrays.stream(name.split("(? { - return piece.contains(title); - }); + String query = suggestionsBuilder.getRemaining().toLowerCase(Locale.ROOT); + var filteredSuggestionList = stream.filter((listItem) -> { //Regex camelCase Search + var words = Arrays.stream(listItem.split("(? s.toLowerCase(Locale.ROOT)).collect(Collectors.toList()); + var prefixes = new ArrayList(words.size()); + for (int i = 0; i < words.size(); i++) + prefixes.add(String.join("",words.subList(i, words.size()))); + return prefixes.stream().anyMatch(s -> s.startsWith(query)); }); Objects.requireNonNull(suggestionsBuilder); - filteredSuggestionList.forEach(msg -> suggestionsBuilder.suggest((String)msg)); + filteredSuggestionList.forEach(suggestionsBuilder::suggest); return suggestionsBuilder.buildFuture(); } From 85464d8b9587b54af68c0c8ba8c40b39caa99ecb Mon Sep 17 00:00:00 2001 From: Alexis Tio <83507082+tioalexis@users.noreply.github.com> Date: Mon, 11 Oct 2021 13:34:46 +0800 Subject: [PATCH 5/9] Fixed number function not returning list length (#1100) * Fixed number function not returning list length * Fixed whitespace --- src/main/java/carpet/script/language/Sys.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/carpet/script/language/Sys.java b/src/main/java/carpet/script/language/Sys.java index c5fbb401..0a3fff33 100644 --- a/src/main/java/carpet/script/language/Sys.java +++ b/src/main/java/carpet/script/language/Sys.java @@ -56,6 +56,10 @@ public class Sys { if (num.isInteger()) return new NumericValue(num.getLong()); return new NumericValue(num.getDouble()); } + if (v instanceof ListValue listVal) + { + return new NumericValue(listVal.length()); + } try { return new NumericValue(v.getString()); From 7486670918f733aaf6ae3b595290947802024d02 Mon Sep 17 00:00:00 2001 From: altrisi Date: Mon, 11 Oct 2021 08:37:30 +0200 Subject: [PATCH 6/9] Report stack traces through the logger (#1050) --- .../java/carpet/mixins/ServerPlayerEntityMixin.java | 12 +++++------- .../java/carpet/mixins/StructureFeatureMixin.java | 3 +-- src/main/java/carpet/script/CarpetEventServer.java | 2 +- src/main/java/carpet/script/Expression.java | 2 +- src/main/java/carpet/script/value/Value.java | 3 ++- src/main/java/carpet/settings/SettingsManager.java | 5 ++--- src/main/java/carpet/utils/SpawnReporter.java | 6 ++++-- 7 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/main/java/carpet/mixins/ServerPlayerEntityMixin.java b/src/main/java/carpet/mixins/ServerPlayerEntityMixin.java index 24acee10..8e68cac4 100644 --- a/src/main/java/carpet/mixins/ServerPlayerEntityMixin.java +++ b/src/main/java/carpet/mixins/ServerPlayerEntityMixin.java @@ -6,9 +6,9 @@ import carpet.helpers.EntityPlayerActionPack; import com.mojang.authlib.GameProfile; import net.minecraft.server.MinecraftServer; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.network.ServerPlayerInteractionManager; import net.minecraft.server.world.ServerWorld; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -16,7 +16,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ServerPlayerEntity.class) public abstract class ServerPlayerEntityMixin implements ServerPlayerEntityInterface { + @Unique public EntityPlayerActionPack actionPack; + @Override public EntityPlayerActionPack getActionPack() { return actionPack; @@ -41,15 +43,11 @@ public abstract class ServerPlayerEntityMixin implements ServerPlayerEntityInter } catch (StackOverflowError soe) { - CarpetSettings.LOG.fatal("Caused stack overflow when performing player action"); + CarpetSettings.LOG.fatal("Caused stack overflow when performing player action", soe); } catch (Throwable exc) { - CarpetSettings.LOG.fatal("Error executing player tasks "+ exc.getMessage()); - exc.printStackTrace(); + CarpetSettings.LOG.fatal("Error executing player tasks", exc); } } - - - } diff --git a/src/main/java/carpet/mixins/StructureFeatureMixin.java b/src/main/java/carpet/mixins/StructureFeatureMixin.java index d1ca1993..fe418407 100644 --- a/src/main/java/carpet/mixins/StructureFeatureMixin.java +++ b/src/main/java/carpet/mixins/StructureFeatureMixin.java @@ -74,8 +74,7 @@ public abstract class StructureFeatureMixin implements } catch (Exception booboo) { - CarpetSettings.LOG.error("Unknown Exception while plopping structure: "+booboo); - booboo.printStackTrace(); + CarpetSettings.LOG.error("Unknown Exception while plopping structure: "+booboo, booboo); return false; } finally diff --git a/src/main/java/carpet/script/CarpetEventServer.java b/src/main/java/carpet/script/CarpetEventServer.java index 890b8584..07449b4a 100644 --- a/src/main/java/carpet/script/CarpetEventServer.java +++ b/src/main/java/carpet/script/CarpetEventServer.java @@ -1174,7 +1174,7 @@ public class CarpetEventServer } catch (NullPointerException | InvalidCallbackException | IntegrityException error) { - CarpetScriptServer.LOG.error("Got exception: "+error.getMessage()); + CarpetScriptServer.LOG.error("Got exception when running event call ", error); return CallbackResult.FAIL; } } diff --git a/src/main/java/carpet/script/Expression.java b/src/main/java/carpet/script/Expression.java index 1e09dc02..ba5cef6a 100644 --- a/src/main/java/carpet/script/Expression.java +++ b/src/main/java/carpet/script/Expression.java @@ -377,7 +377,7 @@ public class Expression if (exc instanceof ResolvedException) return exc; // unexpected really - should be caught earlier and converted to InternalExpressionException - exc.printStackTrace(); + CarpetSettings.LOG.error("Unexpected exception while running Scarpet code", exc); return new ExpressionException(c, e, token, "Error while evaluating expression: "+exc); } diff --git a/src/main/java/carpet/script/value/Value.java b/src/main/java/carpet/script/value/Value.java index 0c004039..8a0cf9b0 100644 --- a/src/main/java/carpet/script/value/Value.java +++ b/src/main/java/carpet/script/value/Value.java @@ -1,5 +1,6 @@ package carpet.script.value; +import carpet.CarpetSettings; import carpet.script.exception.InternalExpressionException; import com.google.gson.JsonElement; import com.google.gson.JsonPrimitive; @@ -42,7 +43,7 @@ public abstract class Value implements Comparable, Cloneable catch (CloneNotSupportedException e) { // should not happen - e.printStackTrace(); + CarpetSettings.LOG.catching(e); throw new InternalExpressionException("Variable of type "+getTypeString()+" is not cloneable. Tell gnembon about it, this shoudn't happen"); } copy.boundVariable = var; diff --git a/src/main/java/carpet/settings/SettingsManager.java b/src/main/java/carpet/settings/SettingsManager.java index b7af8e69..745c5505 100644 --- a/src/main/java/carpet/settings/SettingsManager.java +++ b/src/main/java/carpet/settings/SettingsManager.java @@ -321,8 +321,7 @@ public class SettingsManager } catch (IOException e) { - e.printStackTrace(); - CarpetSettings.LOG.error("[CM]: failed write "+identifier+".conf config file"); + CarpetSettings.LOG.error("[CM]: failed write "+identifier+".conf config file", e); } ///todo is it really needed? resendCommandTree(); } @@ -480,7 +479,7 @@ public class SettingsManager } catch (IOException e) { - e.printStackTrace(); + CarpetSettings.LOG.error("Exception while loading Carpet rules from config", e); return new ConfigReadResult(new HashMap<>(), false); } } diff --git a/src/main/java/carpet/utils/SpawnReporter.java b/src/main/java/carpet/utils/SpawnReporter.java index 87d2cfcd..79755869 100644 --- a/src/main/java/carpet/utils/SpawnReporter.java +++ b/src/main/java/carpet/utils/SpawnReporter.java @@ -34,6 +34,8 @@ import net.minecraft.world.gen.chunk.ChunkGenerator; import net.minecraft.world.gen.feature.StructureFeature; import org.apache.commons.lang3.tuple.Pair; +import carpet.CarpetSettings; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -460,7 +462,7 @@ public class SpawnReporter } catch (Exception exception) { - exception.printStackTrace(); + CarpetSettings.LOG.warn("Exception while creating mob for spawn reporter", exception); return rep; } @@ -517,7 +519,7 @@ public class SpawnReporter } catch (Exception exception) { - exception.printStackTrace(); + CarpetSettings.LOG.warn("Exception while creating mob for spawn reporter", exception); return rep; } } From 4a580a5a4286c8afb6b90993e2b07fb9d92d989a Mon Sep 17 00:00:00 2001 From: gnembon Date: Mon, 11 Oct 2021 06:19:24 -0300 Subject: [PATCH 7/9] clarify number --- src/main/java/carpet/script/language/Sys.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/script/language/Sys.java b/src/main/java/carpet/script/language/Sys.java index 0a3fff33..88ae3888 100644 --- a/src/main/java/carpet/script/language/Sys.java +++ b/src/main/java/carpet/script/language/Sys.java @@ -10,6 +10,7 @@ import carpet.script.utils.SimplexNoiseSampler; import carpet.script.value.BooleanValue; import carpet.script.value.FunctionValue; import carpet.script.value.ListValue; +import carpet.script.value.MapValue; import carpet.script.value.NullValue; import carpet.script.value.NumericValue; import carpet.script.value.StringValue; @@ -56,9 +57,9 @@ public class Sys { if (num.isInteger()) return new NumericValue(num.getLong()); return new NumericValue(num.getDouble()); } - if (v instanceof ListValue listVal) + if (v instanceof ListValue || v instanceof MapValue) { - return new NumericValue(listVal.length()); + return new NumericValue(v.length()); } try { From 5b80c845c6ed8a72435e9c797e427a0ed4b979c6 Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 12 Oct 2021 22:57:47 -0300 Subject: [PATCH 8/9] added liquidDamageDisabled inspired by TIS additions and ported by permission by Fallen Breath --- src/main/java/carpet/CarpetSettings.java | 3 ++ ...owableFluid_liquidDamageDisabledMixin.java | 34 +++++++++++++++++++ src/main/resources/carpet.mixins.json | 2 ++ 3 files changed, 39 insertions(+) create mode 100644 src/main/java/carpet/mixins/FlowableFluid_liquidDamageDisabledMixin.java diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index 5ee47586..86d415a7 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -513,6 +513,9 @@ public class CarpetSettings @Rule(desc = "placing blocks cause block updates", category = CREATIVE) public static boolean interactionUpdates = true; + @Rule(desc = "Disables breaking of blocks caused by flowing liquids", category = CREATIVE) + public static boolean liquidDamageDisabled = false; + @Rule( desc = "smooth client animations with low tps settings", extra = "works only in SP, and will slow down players", diff --git a/src/main/java/carpet/mixins/FlowableFluid_liquidDamageDisabledMixin.java b/src/main/java/carpet/mixins/FlowableFluid_liquidDamageDisabledMixin.java new file mode 100644 index 00000000..1b345e8f --- /dev/null +++ b/src/main/java/carpet/mixins/FlowableFluid_liquidDamageDisabledMixin.java @@ -0,0 +1,34 @@ +package carpet.mixins; + +import carpet.CarpetSettings; +import net.minecraft.block.BlockState; +import net.minecraft.block.Material; +import net.minecraft.fluid.FlowableFluid; +import net.minecraft.fluid.Fluid; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(FlowableFluid.class) +public class FlowableFluid_liquidDamageDisabledMixin +{ + @Inject( + method = "canFill", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/block/Material;blocksMovement()Z" + ), + cancellable = true + ) + private void stopBreakingBlock(BlockView world, BlockPos pos, BlockState state, Fluid fluid, CallbackInfoReturnable cir) + { + if (CarpetSettings.liquidDamageDisabled) + { + Material material = state.getMaterial(); + cir.setReturnValue(material == Material.AIR || material.isLiquid()); + } + } +} diff --git a/src/main/resources/carpet.mixins.json b/src/main/resources/carpet.mixins.json index b1cb8d4f..a0839af2 100644 --- a/src/main/resources/carpet.mixins.json +++ b/src/main/resources/carpet.mixins.json @@ -25,6 +25,8 @@ "Structure_fillUpdatesMixin", "ServerPlayNetworkHandler_interactionUpdatesMixin", + "FlowableFluid_liquidDamageDisabledMixin", + "ServerMetadata_motdMixin", "MinecraftServer_pingPlayerSampleLimit", From 0910bc8779e9d317d44891f77e7874b08deaede7 Mon Sep 17 00:00:00 2001 From: altrisi Date: Wed, 13 Oct 2021 04:01:16 +0200 Subject: [PATCH 9/9] Add badges and icons to readme (#1128) --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index ea4d5e51..a4f14699 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ + + # Fabric Carpet +[![Development Builds](https://github.com/gnembon/fabric-carpet/workflows/Development%20Builds/badge.svg)](https://github.com/gnembon/fabric-carpet/actions?query=workflow%3A%22Development+Builds%22) +[![CurseForge downloads](http://cf.way2muchnoise.eu/full_349239_downloads.svg)](https://www.curseforge.com/minecraft/mc-mods/carpet) +[![GitHub downloads](https://img.shields.io/github/downloads/gnembon/fabric-carpet/total?label=Github%20downloads&logo=github)](https://github.com/gnembon/fabric-carpet/releases) +[![GitHub contributors](https://img.shields.io/github/contributors/gnembon/fabric-carpet?label=Contributors&logo=github)](https://github.com/gnembon/fabric-carpet/graphs/contributors) +[![Discord](https://badgen.net/discord/online-members/gn99m4QRY4?icon=discord&label=Discord&list=what)](https://discord.gg/gn99m4QRY4) + Cause all carpets are made of fabric? This is the [Fabric](https://fabricmc.net/) version of Carpet Mod, for Minecraft 1.14.X, 1.15.X, 1.16.X and above. @@ -15,6 +23,8 @@ Carpet Mod is a mod for vanilla Minecraft that allows you to take full control o For core carpet functionality, this is the right place. Check available downloads on the [release page](https://github.com/gnembon/fabric-carpet/releases) + + ## carpet-extra Check [carpet-extra](https://github.com/gnembon/carpet-extra/) add-on mod for more whacky and crazy features, including autocrafting, block-placing dispensers, and even chicken-shearing!