Adding Gamerule modification to scarpet (#610)
This commit is contained in:
1 parent
b318f1fb68
commit
49e5c012b3
3 files changed
+14
-3
No files matched your search
@@ -487,6 +487,8 @@ Available options in the scarpet app space:
|
|||||||
* `world_path` - full path to the world saves folder
|
* `world_path` - full path to the world saves folder
|
||||||
* `world_folder` - name of the direct folder in the saves that holds world files
|
* `world_folder` - name of the direct folder in the saves that holds world files
|
||||||
* `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_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 ...`.
|
||||||
|
|
||||||
|
|
||||||
Relevant gameplay related properties
|
Relevant gameplay related properties
|
||||||
* `game_difficulty` - current difficulty of the game: `'peacefu'`, `'easy'`, `'normal'`, or `'hard'`
|
* `game_difficulty` - current difficulty of the game: `'peacefu'`, `'easy'`, `'normal'`, or `'hard'`
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import carpet.script.value.ValueConversions;
|
|||||||
import carpet.utils.Messenger;
|
import carpet.utils.Messenger;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.entity.EquipmentSlot;
|
import net.minecraft.entity.EquipmentSlot;
|
||||||
@@ -50,7 +49,6 @@ import net.minecraft.network.packet.s2c.play.TitleS2CPacket;
|
|||||||
import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
|
import net.minecraft.network.packet.s2c.play.TitleS2CPacket.Action;
|
||||||
import net.minecraft.particle.ParticleEffect;
|
import net.minecraft.particle.ParticleEffect;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.command.CommandOutput;
|
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.world.ServerWorld;
|
||||||
@@ -64,7 +62,6 @@ import net.minecraft.util.InvalidIdentifierException;
|
|||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.ChunkPos;
|
import net.minecraft.util.math.ChunkPos;
|
||||||
import net.minecraft.util.math.EulerAngle;
|
import net.minecraft.util.math.EulerAngle;
|
||||||
import net.minecraft.util.math.Vec2f;
|
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import carpet.settings.ParsedRule;
|
|||||||
import carpet.settings.SettingsManager;
|
import carpet.settings.SettingsManager;
|
||||||
import com.sun.management.OperatingSystemMXBean;
|
import com.sun.management.OperatingSystemMXBean;
|
||||||
import net.minecraft.util.WorldSavePath;
|
import net.minecraft.util.WorldSavePath;
|
||||||
|
import net.minecraft.world.GameRules;
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -124,6 +125,17 @@ public class SystemInfo {
|
|||||||
});
|
});
|
||||||
return carpetRules;
|
return carpetRules;
|
||||||
});
|
});
|
||||||
|
put("world_gamerules", c->{
|
||||||
|
Map<Value, Value> rules = new HashMap<>();
|
||||||
|
final GameRules gameRules = c.s.getWorld().getGameRules();
|
||||||
|
GameRules.accept(new GameRules.Visitor() {
|
||||||
|
@Override
|
||||||
|
public <T extends GameRules.Rule<T>> void visit(GameRules.Key<T> key, GameRules.Type<T> type) {
|
||||||
|
rules.put(StringValue.of(key.getName()), StringValue.of(gameRules.get(key).toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return MapValue.wrap(rules);
|
||||||
|
});
|
||||||
put("scarpet_version", c -> StringValue.of(CarpetSettings.carpetVersion));
|
put("scarpet_version", c -> StringValue.of(CarpetSettings.carpetVersion));
|
||||||
|
|
||||||
}};
|
}};
|
||||||
|
|||||||
Reference in new issue
Block a user