mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-12-22 16:57:40 +01:00
Things
This commit is contained in:
parent
1b54d10d91
commit
fa4cfeb7e9
@ -32,7 +32,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
|
public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
|
||||||
|
|
||||||
public BukkitPlugin() {
|
public BukkitPlugin() {
|
||||||
// MappingDataLoader caching is enabled in ViaVersion on versions that construct the plugin on load
|
// This is the only place we can enable this before ViaVersion is loaded and registers protocols
|
||||||
MappingDataLoader.enableMappingsCache();
|
MappingDataLoader.enableMappingsCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ import com.google.common.base.Preconditions;
|
|||||||
import com.viaversion.viabackwards.api.ViaBackwardsConfig;
|
import com.viaversion.viabackwards.api.ViaBackwardsConfig;
|
||||||
import com.viaversion.viabackwards.api.ViaBackwardsPlatform;
|
import com.viaversion.viabackwards.api.ViaBackwardsPlatform;
|
||||||
|
|
||||||
public class ViaBackwards {
|
public final class ViaBackwards {
|
||||||
|
|
||||||
private static ViaBackwardsPlatform platform;
|
private static ViaBackwardsPlatform platform;
|
||||||
private static ViaBackwardsConfig config;
|
private static ViaBackwardsConfig config;
|
||||||
|
@ -82,6 +82,7 @@ public interface ViaBackwardsPlatform {
|
|||||||
getLogger().info("Loading translations...");
|
getLogger().info("Loading translations...");
|
||||||
TranslatableRewriter.loadTranslatables();
|
TranslatableRewriter.loadTranslatables();
|
||||||
|
|
||||||
|
getLogger().info("Registering protocols...");
|
||||||
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
|
final ProtocolManager protocolManager = Via.getManager().getProtocolManager();
|
||||||
protocolManager.registerProtocol(new Protocol1_9_4To1_10(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_10);
|
protocolManager.registerProtocol(new Protocol1_9_4To1_10(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_10);
|
||||||
|
|
||||||
|
@ -29,11 +29,12 @@ import com.viaversion.viaversion.libs.gson.JsonObject;
|
|||||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class TranslatableRewriter<C extends ClientboundPacketType> extends ComponentRewriter<C> {
|
public class TranslatableRewriter<C extends ClientboundPacketType> extends ComponentRewriter<C> {
|
||||||
|
|
||||||
private static final Map<String, Map<String, String>> TRANSLATABLES = new HashMap<>();
|
private static final Map<String, Map<String, String>> TRANSLATABLES = new HashMap<>();
|
||||||
protected final Map<String, String> newTranslatables;
|
private final Map<String, String> newTranslatables;
|
||||||
|
|
||||||
public static void loadTranslatables() {
|
public static void loadTranslatables() {
|
||||||
JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("translation-mappings.json");
|
JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("translation-mappings.json");
|
||||||
@ -111,9 +112,13 @@ public class TranslatableRewriter<C extends ClientboundPacketType> extends Compo
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleTranslate(JsonObject root, String translate) {
|
protected void handleTranslate(JsonObject root, String translate) {
|
||||||
String newTranslate = newTranslatables.get(translate);
|
String newTranslate = mappedTranslationKey(translate);
|
||||||
if (newTranslate != null) {
|
if (newTranslate != null) {
|
||||||
root.addProperty("translate", newTranslate);
|
root.addProperty("translate", newTranslate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable String mappedTranslationKey(final String translationKey) {
|
||||||
|
return newTranslatables.get(translationKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class Protocol1_12_2To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
|||||||
TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<ClientboundPackets1_13>(this) {
|
TranslatableRewriter<ClientboundPackets1_13> translatableRewriter = new TranslatableRewriter<ClientboundPackets1_13>(this) {
|
||||||
@Override
|
@Override
|
||||||
protected void handleTranslate(JsonObject root, String translate) {
|
protected void handleTranslate(JsonObject root, String translate) {
|
||||||
String newTranslate = newTranslatables.get(translate);
|
String newTranslate = mappedTranslationKey(translate);
|
||||||
if (newTranslate != null || (newTranslate = getMappingData().getTranslateMappings().get(translate)) != null) {
|
if (newTranslate != null || (newTranslate = getMappingData().getTranslateMappings().get(translate)) != null) {
|
||||||
root.addProperty("translate", newTranslate);
|
root.addProperty("translate", newTranslate);
|
||||||
}
|
}
|
||||||
|
@ -130,6 +130,11 @@ public final class EntityPackets1_19_4 extends EntityRewriter<ClientboundPackets
|
|||||||
});
|
});
|
||||||
registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, Types1_19_3.META_TYPES.particleType, Types1_19_3.META_TYPES.optionalComponentType);
|
registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, Types1_19_3.META_TYPES.particleType, Types1_19_3.META_TYPES.optionalComponentType);
|
||||||
|
|
||||||
|
filter().filterFamily(Entity1_19_4Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> {
|
||||||
|
final int blockState = meta.value();
|
||||||
|
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockState));
|
||||||
|
});
|
||||||
|
|
||||||
filter().type(Entity1_19_4Types.TEXT_DISPLAY).index(22).handler(((event, meta) -> {
|
filter().type(Entity1_19_4Types.TEXT_DISPLAY).index(22).handler(((event, meta) -> {
|
||||||
// Send as custom display name
|
// Send as custom display name
|
||||||
event.setIndex(2);
|
event.setIndex(2);
|
||||||
|
Loading…
Reference in New Issue
Block a user