(Custom) enchant remap fixes, non full block light fix (#124)

* Fix 1.13 enchant conversion + custom enchants

* Remove redundant check

* More enchant remap fixes, add config option for custom enchant display

* Fix non full blocks "saving" block light
This commit is contained in:
Nassim 2019-09-09 15:23:09 +02:00 committed by Myles
parent e6059845aa
commit fdcab0d5a8
13 changed files with 193 additions and 85 deletions

View File

@ -16,7 +16,7 @@ import org.bukkit.plugin.java.JavaPlugin;
public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
@Override
public void onEnable() {
this.init();
this.init(getDataFolder());
}
@Override

View File

@ -17,7 +17,7 @@ public class BungeePlugin extends Plugin implements ViaBackwardsPlatform {
@Override
public void onEnable() {
this.init();
this.init(getDataFolder());
}
// Why is this not a thing in Bungee? O_o

View File

@ -11,17 +11,26 @@
package nl.matsv.viabackwards;
import com.google.common.base.Preconditions;
import lombok.Getter;
import nl.matsv.viabackwards.api.ViaBackwardsConfig;
import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
public class ViaBackwards {
@Getter
private static ViaBackwardsPlatform platform;
public static void init(ViaBackwardsPlatform platform) {
private static ViaBackwardsPlatform platform;
private static ViaBackwardsConfig config;
public static void init(ViaBackwardsPlatform platform, ViaBackwardsConfig config) {
Preconditions.checkArgument(platform != null, "ViaBackwards is already initialized");
ViaBackwards.platform = platform;
ViaBackwards.config = config;
}
public static ViaBackwardsPlatform getPlatform() {
return platform;
}
public static ViaBackwardsConfig getConfig() {
return config;
}
}

View File

@ -0,0 +1,35 @@
package nl.matsv.viabackwards;
import us.myles.ViaVersion.util.Config;
import java.io.File;
import java.net.URL;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public final class ViaBackwardsConfig extends Config implements nl.matsv.viabackwards.api.ViaBackwardsConfig {
public ViaBackwardsConfig(File configFile) {
super(configFile);
}
@Override
public boolean addCustomEnchantsToLore() {
return getBoolean("add-custom-enchants-into-lore", true);
}
@Override
public URL getDefaultConfigURL() {
return getClass().getClassLoader().getResource("assets/viabackwards/config.yml");
}
@Override
protected void handleConfig(Map<String, Object> map) {
}
@Override
public List<String> getUnsupportedOptions() {
return Collections.emptyList();
}
}

View File

@ -0,0 +1,11 @@
package nl.matsv.viabackwards.api;
public interface ViaBackwardsConfig {
/**
* Mimics name and level of a custom enchant through the item's lore.
*
* @return true if enabled
*/
boolean addCustomEnchantsToLore();
}

View File

@ -11,6 +11,7 @@
package nl.matsv.viabackwards.api;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.ViaBackwardsConfig;
import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11;
import nl.matsv.viabackwards.protocol.protocol1_11_1to1_12.Protocol1_11_1To1_12;
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
@ -29,17 +30,23 @@ import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.update.Version;
import java.io.File;
import java.util.Collections;
import java.util.logging.Logger;
public interface ViaBackwardsPlatform {
/**
* Initialize ViaBackwards
*/
default void init() {
ViaBackwards.init(this);
default void init(File dataFolder) {
ViaBackwardsConfig config = new ViaBackwardsConfig(new File(dataFolder, "config.yml"));
config.reloadConfig();
ViaBackwards.init(this, config);
if (isOutdated()) return;
if (!isOutdated()) {
ProtocolRegistry.registerProtocol(new Protocol1_9_4To1_10(), Collections.singletonList(ProtocolVersion.v1_9_3.getId()), ProtocolVersion.v1_10.getId());
ProtocolRegistry.registerProtocol(new Protocol1_10To1_11(), Collections.singletonList(ProtocolVersion.v1_10.getId()), ProtocolVersion.v1_11.getId());
ProtocolRegistry.registerProtocol(new Protocol1_11To1_11_1(), Collections.singletonList(ProtocolVersion.v1_11.getId()), ProtocolVersion.v1_11_1.getId());
@ -55,7 +62,6 @@ public interface ViaBackwardsPlatform {
ProtocolRegistry.registerProtocol(new Protocol1_14_2To1_14_3(), Collections.singletonList(ProtocolVersion.v1_14_2.getId()), ProtocolVersion.v1_14_3.getId());
ProtocolRegistry.registerProtocol(new Protocol1_14_3To1_14_4(), Collections.singletonList(ProtocolVersion.v1_14_3.getId()), ProtocolVersion.v1_14_4.getId());
}
}
/**
* Logger provided by the platform

View File

@ -605,10 +605,10 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
rewrite(205).repItem(new Item((short) 90, (byte) 1, (short) -1, getNamedTag("1.13 Mushroom Stem")));
enchantmentMappings.put("minecraft:loyalty", "§7Loyalty");
enchantmentMappings.put("minecraft:impaling", "§7Impaling");
enchantmentMappings.put("minecraft:riptide", "§7Riptide");
enchantmentMappings.put("minecraft:channeling", "§7Channeling");
enchantmentMappings.put("minecraft:loyalty", "§7Loyalty");
enchantmentMappings.put("minecraft:impaling", "§7Impaling");
enchantmentMappings.put("minecraft:riptide", "§7Riptide");
enchantmentMappings.put("minecraft:channeling", "§7Channeling");
}
@Override
@ -798,9 +798,30 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
noMapped.add(enchantmentEntry);
} else if (!newId.isEmpty()) {
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
if (oldId == null && newId.startsWith("viaversion:legacy/")) {
if (oldId == null) {
if (!newId.startsWith("viaversion:legacy/")) {
// Custom enchant (?)
noMapped.add(enchantmentEntry);
// Some custom-enchant plugins write it into the lore manually, which would double its entry
if (ViaBackwards.getConfig().addCustomEnchantsToLore()) {
String name = newId;
if (name.contains(":"))
name = name.split(":")[1];
name = "§7" + Character.toUpperCase(name.charAt(0)) + name.substring(1).toLowerCase(Locale.ENGLISH);
lore.add(new StringTag("", name + " "
+ getRomanNumber((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())));
}
if (Via.getManager().isDebug())
ViaBackwards.getPlatform().getLogger().warning("Found unknown enchant: " + newId);
continue;
} else {
oldId = Short.valueOf(newId.substring(18));
}
}
Short level = (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue();
if (level != 0)
hasValidEnchants = true;
@ -815,6 +836,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
IntTag hideFlags = tag.get("HideFlags");
if (hideFlags == null) {
hideFlags = new IntTag("HideFlags");
tag.put(new ByteTag(NBT_TAG_NAME + "|DummyEnchant"));
} else {
tag.put(new IntTag(NBT_TAG_NAME + "|OldHideFlags", hideFlags.getValue()));
}
@ -831,27 +853,32 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
tag.put(hideFlags);
}
if (!lore.isEmpty()) {
if (noMapped.size() != 0) {
tag.put(noMapped);
if (!lore.isEmpty()) {
CompoundTag display = tag.get("display");
if (display == null) {
tag.put(display = new CompoundTag("display"));
}
ListTag loreTag = display.get("Lore");
if (loreTag == null) {
display.put(loreTag = new ListTag("Lore", StringTag.class));
}
tag.put(new ByteTag(NBT_TAG_NAME + "|DummyLore"));
} else if (loreTag.size() != 0) {
ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class);
for (Tag value : lore) {
for (Tag value : loreTag) {
oldLore.add(value.clone());
}
display.put(oldLore);
tag.put(oldLore);
lore.addAll(loreTag.getValue());
}
loreTag.setValue(lore);
}
}
tag.remove("Enchantments");
tag.put(newEnchantments);
@ -898,35 +925,20 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
}
}
// Display Name now uses JSON
if (tag.get("display") instanceof CompoundTag) {
CompoundTag display = tag.get("display");
if (tag.get(NBT_TAG_NAME + "|noDisplay") instanceof ByteTag) {
tag.remove("display");
tag.remove(NBT_TAG_NAME + "|noDisplay");
} else {
if (display.get("Name") instanceof StringTag) {
StringTag name = display.get("Name");
display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue()));
Tag display = tag.get("display");
if (display instanceof CompoundTag) {
CompoundTag displayTag = (CompoundTag) display;
StringTag name = displayTag.get("Name");
if (name instanceof StringTag) {
displayTag.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue()));
name.setValue(
ChatRewriter.legacyTextToJson(
name.getValue()
)
);
}
if (display.get(NBT_TAG_NAME + "|OldLore") instanceof ListTag) {
ListTag loreTag = new ListTag("Lore", StringTag.class);
ListTag oldLore = display.get(NBT_TAG_NAME + "|OldLore");
Iterator<Tag> iterator = oldLore.iterator();
}
while (iterator.hasNext()) {
loreTag.add(iterator.next());
}
display.remove("Lore");
display.put(loreTag);
display.remove(NBT_TAG_NAME + "|OldLore");
}
}
}
// ench is now Enchantments and now uses identifiers
if (tag.get("ench") instanceof ListTag) {
rewriteEnchantmentsToServer(tag, false);
@ -1002,18 +1014,22 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
boolean dummyEnchant = false;
if (!storedEnch) {
IntTag hideFlags = tag.get(NBT_TAG_NAME + "|OldHideFlags");
dummyEnchant = hideFlags != null;
if (dummyEnchant) {
if (hideFlags != null) {
tag.put(new IntTag("HideFlags", hideFlags.getValue()));
} else {
dummyEnchant = true;
tag.remove(NBT_TAG_NAME + "|OldHideFlags");
} else if (tag.contains(NBT_TAG_NAME + "|DummyEnchant")) {
tag.remove("HideFlags");
dummyEnchant = true;
tag.remove(NBT_TAG_NAME + "|DummyEnchant");
}
}
for (Tag enchEntry : enchantments) {
CompoundTag enchantmentEntry = new CompoundTag("");
short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue();
if (dummyEnchant && oldId == 0) {
short level = ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue();
if (dummyEnchant && oldId == 0 && level == 0) {
continue; //Skip dummy enchatment
}
String newId = MappingData.oldEnchantmentsIds.get(oldId);
@ -1021,9 +1037,11 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
newId = "viaversion:legacy/" + oldId;
}
enchantmentEntry.put(new StringTag("id", newId));
enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue()));
enchantmentEntry.put(new ShortTag("lvl", level));
newEnchantments.add(enchantmentEntry);
}
ListTag noMapped = tag.get(NBT_TAG_NAME + "|Enchantments");
if (noMapped != null) {
for (Tag value : noMapped) {
@ -1045,10 +1063,11 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
}
lore.setValue(oldLore.getValue());
tag.remove(NBT_TAG_NAME + "|OldLore");
} else {
tag.remove("Lore");
} else if (tag.contains(NBT_TAG_NAME + "|DummyLore")) {
display.remove("Lore");
if (display.isEmpty())
tag.remove("display");
tag.remove(NBT_TAG_NAME + "|DummyLore");
}
if (!storedEnch)

View File

@ -537,6 +537,19 @@ public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14
}
}
if (section.getNonAirBlocksCount() != 0 && section.hasBlockLight()) {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int id = section.getFlatBlock(x, y, z);
if (MappingData.nonFullBlocks.contains(id)) {
section.getBlockLightNibbleArray().set(x, y, z, 0);
}
}
}
}
}
for (int j = 0; j < section.getPaletteSize(); j++) {
int old = section.getPaletteEntry(j);
int newId = Protocol1_13_2To1_14.getNewBlockStateId(old);

View File

@ -0,0 +1,5 @@
# If you need help, you can join our Discord - https://viaversion.com/discord
#
# Writes name and level of custom enchantments into the item's lore.
# Set this to false if you see the entries doubled/if the custom-enchant plugin already writes these into the lore manually.
add-custom-enchants-into-lore: true

View File

@ -20,11 +20,11 @@ import java.util.logging.Logger;
public class ViaFabricAddon implements ViaBackwardsPlatform, Runnable {
@Getter
private final Logger logger = new LoggerWrapper(LogManager.getLogger("ViaRewind"));
private final Logger logger = new LoggerWrapper(LogManager.getLogger("ViaBackwards"));
@Override
public void run() {
this.init();
this.init(FabricLoader.getInstance().getConfigDirectory().toPath().resolve("ViaBackwards").resolve("config.yml").toFile());
}
@Override

View File

@ -61,7 +61,7 @@
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion</artifactId>
<version>2.1.3</version>
<version>2.1.4-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>

View File

@ -14,6 +14,7 @@ import com.google.inject.Inject;
import lombok.Getter;
import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.sponge.VersionInfo;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
@ -21,6 +22,7 @@ import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.nio.file.Path;
import java.util.logging.Logger;
@Plugin(id = "viabackwards",
@ -35,13 +37,16 @@ public class SpongePlugin implements ViaBackwardsPlatform {
private Logger logger;
@Inject
private org.slf4j.Logger loggerSlf4j;
@Inject
@ConfigDir(sharedRoot = false)
private Path configPath;
@Listener(order = Order.LATE)
public void onGameStart(GameInitializationEvent e) {
// Setup Logger
this.logger = new LoggerWrapper(loggerSlf4j);
// Init!
this.init();
this.init(configPath.resolve("config.yml").toFile());
}
@Override

View File

@ -16,11 +16,13 @@ import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.Dependency;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import lombok.Getter;
import nl.matsv.viabackwards.api.ViaBackwardsPlatform;
import nl.matsv.viabackwards.velocity.VersionInfo;
import us.myles.ViaVersion.sponge.util.LoggerWrapper;
import java.nio.file.Path;
import java.util.logging.Logger;
@Plugin(id = "viabackwards",
@ -35,13 +37,16 @@ public class VelocityPlugin implements ViaBackwardsPlatform {
private Logger logger;
@Inject
private org.slf4j.Logger loggerSlf4j;
@Inject
@DataDirectory
private Path configPath;
@Subscribe(order = PostOrder.LATE)
public void onProxyStart(ProxyInitializeEvent e) {
// Setup Logger
this.logger = new LoggerWrapper(loggerSlf4j);
// Init!
this.init();
this.init(configPath.resolve("config.yml").toFile());
}
@Override