Handle mob spawner changes

This commit is contained in:
Matsv 2019-01-20 20:23:40 +01:00
parent 520eb15ce9
commit 03768d7124
5 changed files with 100 additions and 24 deletions

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.EntityNameRewrites;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers.BackwardsBlockEntityProvider;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
public class SpawnerHandler implements BackwardsBlockEntityProvider.BackwardsBlockEntityHandler {
@Override
public CompoundTag transform(UserConnection user, int blockId, 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(EntityNameRewrites.rewrite(s.getValue()));
}
}
return tag;
}
}

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2016 Matsv
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class EntityNameRewrites {
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:" + future, "minecraft:" + past);
}
public static String rewrite(String entName) {
String entityName = entityNames.get(entName);
if (entityName != null) {
return entityName;
}
entityName = entityNames.get("minecraft:" + entName);
if (entityName != null) {
return entityName;
} else
return entName;
}
}

View File

@ -72,21 +72,17 @@ public class BlockItemPackets1_13 extends Rewriter<Protocol1_12_2To1_13> {
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class); BackwardsBlockEntityProvider provider = Via.getManager().getProviders().get(BackwardsBlockEntityProvider.class);
switch (wrapper.get(Type.UNSIGNED_BYTE, 0)) { // TODO conduit handling
case 4: if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 5) {
case 6: wrapper.cancel();
case 11:
wrapper.set(Type.NBT, 0,
provider.transform(
wrapper.user(),
wrapper.get(Type.POSITION, 0),
wrapper.get(Type.NBT, 0)
));
break;
default:
wrapper.cancel(); // TODO CONFIRM EVERYTHING WORKING BEFORE REMOVING THIS
break;
} }
wrapper.set(Type.NBT, 0,
provider.transform(
wrapper.user(),
wrapper.get(Type.POSITION, 0),
wrapper.get(Type.NBT, 0)
));
} }
}); });
} }

View File

@ -10,10 +10,7 @@
package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers; package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.providers;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BannerHandler; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.*;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.BedHandler;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.SkullHandler;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.storage.BackwardsBlockStorage;
import us.myles.ViaVersion.api.Via; import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection; import us.myles.ViaVersion.api.data.UserConnection;
@ -32,7 +29,7 @@ public class BackwardsBlockEntityProvider 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", ); handlers.put("minecraft:mob_spawner", new SpawnerHandler());
} }
/** /**

View File

@ -35,11 +35,9 @@ public class BackwardsBlockStorage extends StoredObject {
// Add the banners // Add the banners
for (int i = 6854; i <= 7173; i++) for (int i = 6854; i <= 7173; i++)
whitelist.add(i); whitelist.add(i);
//
// Add the white wall banners // Spawner
// for (int i = 0; i < 4; i++) { whitelist.add(1647);
// whitelist.add(7110 + i);
// }
// Skulls // Skulls
for (int i = 5447; i <= 5566; i++) for (int i = 5447; i <= 5566; i++)