3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00

Add support for setting a custom world name (#2672)

Dieser Commit ist enthalten in:
Levertion 2021-09-15 09:52:11 +01:00 committet von GitHub
Ursprung c264e639d6
Commit d67269c9fe
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
5 geänderte Dateien mit 76 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.configuration;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
public interface ViaVersionConfig { public interface ViaVersionConfig {
@ -429,4 +430,13 @@ public interface ViaVersionConfig {
* @return cached serialized component * @return cached serialized component
*/ */
JsonElement get1_17ResourcePackPrompt(); JsonElement get1_17ResourcePackPrompt();
/***
* Get the world names which should be returned for each vanilla dimension
*
* @return the global map from vanilla dimensions to world name
* Note that this can be overriden per-user by using {@link com.viaversion.viaversion.api.connection.UserConnection#put} with
* a custom instance of {@link WorldIdentifiers} for the user's {@link UserConnection}
*/
WorldIdentifiers get1_16WorldNamesMap();
} }

Datei anzeigen

@ -0,0 +1,35 @@
package com.viaversion.viaversion.api.minecraft;
import com.viaversion.viaversion.api.connection.StorableObject;
public class WorldIdentifiers implements StorableObject {
public static final String OVERWORLD_DEFAULT = "minecraft:overworld";
public static final String NETHER_DEFAULT = "minecraft:the_nether";
public static final String END_DEFAULT = "minecraft:the_end";
private final String overworld;
private final String nether;
private final String end;
public WorldIdentifiers(String overworld) {
this(overworld, NETHER_DEFAULT, END_DEFAULT);
}
public WorldIdentifiers(String overworld, String nether, String end) {
this.overworld = overworld;
this.nether = nether;
this.end = end;
}
public String overworld() {
return this.overworld;
}
public String nether() {
return this.nether;
}
public String end() {
return this.end;
}
}

Datei anzeigen

@ -18,12 +18,16 @@
package com.viaversion.viaversion.configuration; package com.viaversion.viaversion.configuration;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.viaversion.viaversion.api.configuration.ViaVersionConfig; import com.viaversion.viaversion.api.configuration.ViaVersionConfig;
import com.viaversion.viaversion.util.Config; import com.viaversion.viaversion.util.Config;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet; import it.unimi.dsi.fastutil.ints.IntSet;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.Map;
public abstract class AbstractViaConfig extends Config implements ViaVersionConfig { public abstract class AbstractViaConfig extends Config implements ViaVersionConfig {
@ -78,6 +82,7 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
private boolean ignoreLongChannelNames; private boolean ignoreLongChannelNames;
private boolean forcedUse1_17ResourcePack; private boolean forcedUse1_17ResourcePack;
private JsonElement resourcePack1_17PromptMessage; private JsonElement resourcePack1_17PromptMessage;
private WorldIdentifiers map1_16WorldNames;
protected AbstractViaConfig(File configFile) { protected AbstractViaConfig(File configFile) {
super(configFile); super(configFile);
@ -141,6 +146,10 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
ignoreLongChannelNames = getBoolean("ignore-long-1_16-channel-names", true); ignoreLongChannelNames = getBoolean("ignore-long-1_16-channel-names", true);
forcedUse1_17ResourcePack = getBoolean("forced-use-1_17-resource-pack", false); forcedUse1_17ResourcePack = getBoolean("forced-use-1_17-resource-pack", false);
resourcePack1_17PromptMessage = getSerializedComponent("resource-pack-1_17-prompt"); resourcePack1_17PromptMessage = getSerializedComponent("resource-pack-1_17-prompt");
Map<String, String> worlds = get("map-1_16-world-names", Map.class, new HashMap<String, String>());
map1_16WorldNames = new WorldIdentifiers(worlds.getOrDefault("overworld", WorldIdentifiers.OVERWORLD_DEFAULT),
worlds.getOrDefault("nether", WorldIdentifiers.NETHER_DEFAULT),
worlds.getOrDefault("end", WorldIdentifiers.END_DEFAULT));
} }
@Override @Override
@ -429,4 +438,9 @@ public abstract class AbstractViaConfig extends Config implements ViaVersionConf
public JsonElement get1_17ResourcePackPrompt() { public JsonElement get1_17ResourcePackPrompt() {
return resourcePack1_17PromptMessage; return resourcePack1_17PromptMessage;
} }
@Override
public WorldIdentifiers get1_16WorldNamesMap() {
return map1_16WorldNames;
};
} }

Datei anzeigen

@ -25,6 +25,7 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag; import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag; import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.minecraft.WorldIdentifiers;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types; import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
@ -42,25 +43,35 @@ import java.util.UUID;
public class EntityPackets { public class EntityPackets {
private static final PacketHandler DIMENSION_HANDLER = wrapper -> { private static final PacketHandler DIMENSION_HANDLER = wrapper -> {
WorldIdentifiers map = Via.getConfig().get1_16WorldNamesMap();
WorldIdentifiers userMap = wrapper.user().get(WorldIdentifiers.class);
if (userMap!=null){
map = userMap;
}
int dimension = wrapper.read(Type.INT); int dimension = wrapper.read(Type.INT);
String dimensionName; String dimensionName;
String outputName;
switch (dimension) { switch (dimension) {
case -1: case -1:
dimensionName = "minecraft:the_nether"; dimensionName = "minecraft:the_nether";
outputName = map.nether();
break; break;
case 0: case 0:
dimensionName = "minecraft:overworld"; dimensionName = "minecraft:overworld";
outputName = map.overworld();
break; break;
case 1: case 1:
dimensionName = "minecraft:the_end"; dimensionName = "minecraft:the_end";
outputName = map.end();
break; break;
default: default:
Via.getPlatform().getLogger().warning("Invalid dimension id: " + dimension); Via.getPlatform().getLogger().warning("Invalid dimension id: " + dimension);
dimensionName = "minecraft:overworld"; dimensionName = "minecraft:overworld";
outputName = map.overworld();
} }
wrapper.write(Type.STRING, dimensionName); // dimension wrapper.write(Type.STRING, dimensionName); // dimension
wrapper.write(Type.STRING, dimensionName); // world wrapper.write(Type.STRING, outputName); // world
}; };
public static final CompoundTag DIMENSIONS_TAG = new CompoundTag(); public static final CompoundTag DIMENSIONS_TAG = new CompoundTag();
private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"}; private static final String[] WORLD_NAMES = {"minecraft:overworld", "minecraft:the_nether", "minecraft:the_end"};

Datei anzeigen

@ -205,3 +205,8 @@ force-json-transform: false
minimize-cooldown: true minimize-cooldown: true
# Allows 1.9+ left-handedness (main hand) on 1.8 servers # Allows 1.9+ left-handedness (main hand) on 1.8 servers
left-handed-handling: true left-handed-handling: true
# Get the world names which should be returned for each vanilla dimension
map-1_16-world-names:
overworld: "minecraft:overworld"
nether: "minecraft:the_nether"
end: "minecraft:the_end"