Rewrite entity names for spawners, fixes #884

This commit is contained in:
Matsv 2018-07-20 11:15:37 +02:00
parent df32569af6
commit 7a331bdb09
3 changed files with 89 additions and 9 deletions

View File

@ -0,0 +1,56 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/*
CHANGED ENTITY NAMES IN 1.13
commandblock_minecart => command_block_minecart
ender_crystal => end_crystal
evocation_fangs => evoker_fangs
evocation_illager => evoker
eye_of_ender_signal => eye_of_ender
fireworks_rocket => firework_rocket
illusion_illager => illusioner
snowman => snow_golem
villager_golem => iron_golem
vindication_illager => vindicator
xp_bottle => experience_bottle
xp_orb => experience_orb
*/
public class EntityNameRewriter {
private static Map<String, String> entityNames = new ConcurrentHashMap<>();
static {
/*
CHANGED NAMES IN 1.13
*/
reg("commandblock_minecart", "command_block_minecart");
reg("ender_crystal", "end_crystal");
reg("evocation_fangs", "evoker_fangs");
reg("evocation_illager", "evoker");
reg("eye_of_ender_signal", "eye_of_ender");
reg("fireworks_rocket", "firework_rocket");
reg("illusion_illager", "illusioner");
reg("snowman", "snow_golem");
reg("villager_golem", "iron_golem");
reg("vindication_illager", "vindicator");
reg("xp_bottle", "experience_bottle");
reg("xp_orb", "experience_orb");
}
private static void reg(String past, String future) {
entityNames.put("minecraft:" + past, "minecraft:" + future);
}
public static String rewrite(String entName) {
if (entityNames.containsKey(entName))
return entityNames.get(entName);
if (entityNames.containsKey("minecraft:" + entName))
return entityNames.get("minecraft:" + entName);
else
return entName;
}
}

View File

@ -2,15 +2,13 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.Position; import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.platform.providers.Provider; import us.myles.ViaVersion.api.platform.providers.Provider;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.BannerHandler; import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.*;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.BedHandler;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.FlowerPotHandler;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities.SkullHandler;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -23,6 +21,7 @@ public class BlockEntityProvider implements Provider {
handlers.put("minecraft:bed", new BedHandler()); handlers.put("minecraft:bed", new BedHandler());
handlers.put("minecraft:banner", new BannerHandler()); handlers.put("minecraft:banner", new BannerHandler());
handlers.put("minecraft:skull", new SkullHandler()); handlers.put("minecraft:skull", new SkullHandler());
handlers.put("minecraft:mob_spawner", new SpawnerHandler());
} }
/** /**
@ -42,7 +41,8 @@ public class BlockEntityProvider implements Provider {
String id = (String) tag.get("id").getValue(); String id = (String) tag.get("id").getValue();
if (!handlers.containsKey(id)) { if (!handlers.containsKey(id)) {
//System.out.println("Unhandled BlockEntity " + id + " full tag: " + tag); if (Via.getManager().isDebug())
System.out.println("Unhandled BlockEntity " + id + " full tag: " + tag);
return -1; return -1;
} }
@ -54,10 +54,6 @@ public class BlockEntityProvider implements Provider {
return newBlock; return newBlock;
} }
public interface BlockEntityHandler {
int transform(UserConnection user, CompoundTag tag);
}
private void sendBlockChange(UserConnection user, Position position, int blockId) throws Exception { private void sendBlockChange(UserConnection user, Position position, int blockId) throws Exception {
PacketWrapper wrapper = new PacketWrapper(0x0B, null, user); PacketWrapper wrapper = new PacketWrapper(0x0B, null, user);
wrapper.write(Type.POSITION, position); wrapper.write(Type.POSITION, position);
@ -66,5 +62,9 @@ public class BlockEntityProvider implements Provider {
wrapper.send(Protocol1_13To1_12_2.class, true, true); wrapper.send(Protocol1_13To1_12_2.class, true, true);
} }
public interface BlockEntityHandler {
int transform(UserConnection user, CompoundTag tag);
}
} }

View File

@ -0,0 +1,24 @@
package us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.blockentities;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.EntityNameRewriter;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.providers.BlockEntityProvider;
public class SpawnerHandler implements BlockEntityProvider.BlockEntityHandler {
@Override
public int transform(UserConnection user, CompoundTag tag) {
if (tag.contains("SpawnData") && tag.get("SpawnData") instanceof CompoundTag) {
CompoundTag data = tag.get("SpawnData");
if (data.contains("id") && data.get("id") instanceof StringTag) {
StringTag s = data.get("id");
s.setValue(EntityNameRewriter.rewrite(s.getValue()));
}
}
// Always return -1 because the block is still the same id
return -1;
}
}