WorldProperties: Use NamespacedKey instead of ResourceLocation

Dieser Commit ist enthalten in:
Moulberry 2023-11-16 17:36:13 +08:00
Ursprung 5b61aebd32
Commit 8c6fd853ab
3 geänderte Dateien mit 14 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -7,6 +7,7 @@ import com.moulberry.axiom.world_properties.server.ServerWorldProperty;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Unit; import net.minecraft.util.Unit;
import org.bukkit.NamespacedKey;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -21,28 +22,28 @@ public class WorldPropertiesExample implements Listener {
World world = event.getWorld(); World world = event.getWorld();
ServerWorldProperty<Boolean> checkbox = new ServerWorldProperty<>(new ResourceLocation("axiom:checkbox"), ServerWorldProperty<Boolean> checkbox = new ServerWorldProperty<>(new NamespacedKey("axiom", "checkbox"),
"Checkbox", "Checkbox",
false, WorldPropertyWidgetType.CHECKBOX, false, bool -> { false, WorldPropertyWidgetType.CHECKBOX, false, bool -> {
world.sendMessage(Component.text("Checkbox: " + bool)); // Do something with input world.sendMessage(Component.text("Checkbox: " + bool)); // Do something with input
return true; // true to sync with client return true; // true to sync with client
}); });
ServerWorldProperty<Integer> slider = new ServerWorldProperty<>(new ResourceLocation("axiom:slider"), ServerWorldProperty<Integer> slider = new ServerWorldProperty<>(new NamespacedKey("axiom", "slider"),
"Slider", "Slider",
false, new WorldPropertyWidgetType.Slider(0, 8), 4, integer -> { false, new WorldPropertyWidgetType.Slider(0, 8), 4, integer -> {
world.sendMessage(Component.text("Slider: " + integer)); // Do something with input world.sendMessage(Component.text("Slider: " + integer)); // Do something with input
return true; // true to sync with client return true; // true to sync with client
}); });
ServerWorldProperty<String> textbox = new ServerWorldProperty<>(new ResourceLocation("axiom:textbox"), ServerWorldProperty<String> textbox = new ServerWorldProperty<>(new NamespacedKey("axiom", "textbox"),
"Textbox", "Textbox",
false, WorldPropertyWidgetType.TEXTBOX, "Hello", string -> { false, WorldPropertyWidgetType.TEXTBOX, "Hello", string -> {
world.sendMessage(Component.text("Textbox: " + string)); // Do something with input world.sendMessage(Component.text("Textbox: " + string)); // Do something with input
return true; // true to sync with client return true; // true to sync with client
}); });
ServerWorldProperty<Unit> button = new ServerWorldProperty<>(new ResourceLocation("axiom:button"), ServerWorldProperty<Unit> button = new ServerWorldProperty<>(new NamespacedKey("axiom", "button"),
"Button", "Button",
false, WorldPropertyWidgetType.BUTTON, Unit.INSTANCE, unit -> { false, WorldPropertyWidgetType.BUTTON, Unit.INSTANCE, unit -> {
world.sendMessage(Component.text("Button pressed")); // Do something with input world.sendMessage(Component.text("Button pressed")); // Do something with input

Datei anzeigen

@ -8,6 +8,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.GameRules; import net.minecraft.world.level.GameRules;
import org.bukkit.GameRule; import org.bukkit.GameRule;
import org.bukkit.NamespacedKey;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -64,7 +65,7 @@ public class ServerWorldPropertiesRegistry {
// Time // Time
WorldPropertyCategory timeCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.time", true); WorldPropertyCategory timeCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.time", true);
ServerWorldProperty<Integer> time = new ServerWorldProperty<>(new ResourceLocation("axiom:time"), ServerWorldProperty<Integer> time = new ServerWorldProperty<>(new NamespacedKey("axiom", "time"),
"axiom.editorui.window.world_properties.time", "axiom.editorui.window.world_properties.time",
true, WorldPropertyWidgetType.TIME, 0, integer -> false true, WorldPropertyWidgetType.TIME, 0, integer -> false
); );
@ -75,14 +76,14 @@ public class ServerWorldPropertiesRegistry {
WorldPropertyCategory weatherCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.weather", WorldPropertyCategory weatherCategory = new WorldPropertyCategory("axiom.editorui.window.world_properties.weather",
true); true);
ServerWorldProperty<Boolean> pauseWeather = new ServerWorldProperty<>(new ResourceLocation("axiom:pause_weather"), ServerWorldProperty<Boolean> pauseWeather = new ServerWorldProperty<>(new NamespacedKey("axiom", "pause_weather"),
"axiom.editorui.window.world_properties.pause_weather", "axiom.editorui.window.world_properties.pause_weather",
true, WorldPropertyWidgetType.CHECKBOX, !world.getGameRuleValue(GameRule.DO_WEATHER_CYCLE), bool -> { true, WorldPropertyWidgetType.CHECKBOX, !world.getGameRuleValue(GameRule.DO_WEATHER_CYCLE), bool -> {
world.setGameRule(GameRule.DO_WEATHER_CYCLE, !bool); world.setGameRule(GameRule.DO_WEATHER_CYCLE, !bool);
return false; return false;
}); });
ServerWorldProperty<Integer> weatherType = new ServerWorldProperty<>(new ResourceLocation("axiom:weather_type"), ServerWorldProperty<Integer> weatherType = new ServerWorldProperty<>(new NamespacedKey("axiom", "weather_type"),
"axiom.editorui.window.world_properties.clear_weather", "axiom.editorui.window.world_properties.clear_weather",
true, new WorldPropertyWidgetType.ButtonArray( true, new WorldPropertyWidgetType.ButtonArray(
List.of("axiom.editorui.window.world_properties.rain_weather", "axiom.editorui.window.world_properties.thunder_weather") List.of("axiom.editorui.window.world_properties.rain_weather", "axiom.editorui.window.world_properties.thunder_weather")

Datei anzeigen

@ -6,7 +6,9 @@ import com.moulberry.axiom.world_properties.WorldPropertyWidgetType;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import org.bukkit.NamespacedKey;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -20,9 +22,9 @@ public class ServerWorldProperty<T> {
private T value; private T value;
private Predicate<T> handler; private Predicate<T> handler;
public ServerWorldProperty(ResourceLocation id, String name, boolean localizeName, WorldPropertyWidgetType<T> widget, public ServerWorldProperty(NamespacedKey id, String name, boolean localizeName, WorldPropertyWidgetType<T> widget,
T value, Predicate<T> handler) { T value, Predicate<T> handler) {
this.id = id; this.id = CraftNamespacedKey.toMinecraft(id);
this.name = name; this.name = name;
this.localizeName = localizeName; this.localizeName = localizeName;
this.widget = widget; this.widget = widget;