Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-26 08:10:09 +01:00
Reimplement spawnegg items
Dieser Commit ist enthalten in:
Ursprung
3176d892dd
Commit
dc758b767f
@ -0,0 +1,70 @@
|
|||||||
|
package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data;
|
||||||
|
|
||||||
|
import com.google.common.collect.BiMap;
|
||||||
|
import com.google.common.collect.HashBiMap;
|
||||||
|
|
||||||
|
public class SpawnEggRewriter {
|
||||||
|
private final static BiMap<String, Integer> spawnEggs = HashBiMap.create();
|
||||||
|
|
||||||
|
static {
|
||||||
|
// Class yz.java in 18w14b
|
||||||
|
// Register spawn eggs (generated with GT)
|
||||||
|
registerSpawnEgg("minecraft:bat");
|
||||||
|
registerSpawnEgg("minecraft:blaze");
|
||||||
|
registerSpawnEgg("minecraft:cave_spider");
|
||||||
|
registerSpawnEgg("minecraft:chicken");
|
||||||
|
registerSpawnEgg("minecraft:cow");
|
||||||
|
registerSpawnEgg("minecraft:creeper");
|
||||||
|
registerSpawnEgg("minecraft:donkey");
|
||||||
|
registerSpawnEgg("minecraft:elder_guardian");
|
||||||
|
registerSpawnEgg("minecraft:enderman");
|
||||||
|
registerSpawnEgg("minecraft:endermite");
|
||||||
|
registerSpawnEgg("minecraft:evocation_illager");
|
||||||
|
registerSpawnEgg("minecraft:ghast");
|
||||||
|
registerSpawnEgg("minecraft:guardian");
|
||||||
|
registerSpawnEgg("minecraft:horse");
|
||||||
|
registerSpawnEgg("minecraft:husk");
|
||||||
|
registerSpawnEgg("minecraft:llama");
|
||||||
|
registerSpawnEgg("minecraft:magma_cube");
|
||||||
|
registerSpawnEgg("minecraft:mooshroom");
|
||||||
|
registerSpawnEgg("minecraft:mule");
|
||||||
|
registerSpawnEgg("minecraft:ocelot");
|
||||||
|
registerSpawnEgg("minecraft:puffer_fish");
|
||||||
|
registerSpawnEgg("minecraft:parrot");
|
||||||
|
registerSpawnEgg("minecraft:pig");
|
||||||
|
registerSpawnEgg("minecraft:polar_bear");
|
||||||
|
registerSpawnEgg("minecraft:rabbit");
|
||||||
|
registerSpawnEgg("minecraft:sheep");
|
||||||
|
registerSpawnEgg("minecraft:shulker");
|
||||||
|
registerSpawnEgg("minecraft:silverfish");
|
||||||
|
registerSpawnEgg("minecraft:skeleton");
|
||||||
|
registerSpawnEgg("minecraft:skeleton_horse");
|
||||||
|
registerSpawnEgg("minecraft:slime");
|
||||||
|
registerSpawnEgg("minecraft:spider");
|
||||||
|
registerSpawnEgg("minecraft:squid");
|
||||||
|
registerSpawnEgg("minecraft:stray");
|
||||||
|
registerSpawnEgg("minecraft:turtle");
|
||||||
|
registerSpawnEgg("minecraft:vex");
|
||||||
|
registerSpawnEgg("minecraft:villager");
|
||||||
|
registerSpawnEgg("minecraft:vindication_illager");
|
||||||
|
registerSpawnEgg("minecraft:witch");
|
||||||
|
registerSpawnEgg("minecraft:wither_skeleton");
|
||||||
|
registerSpawnEgg("minecraft:wolf");
|
||||||
|
registerSpawnEgg("minecraft:zombie");
|
||||||
|
registerSpawnEgg("minecraft:zombie_horse");
|
||||||
|
registerSpawnEgg("minecraft:zombie_pigman");
|
||||||
|
registerSpawnEgg("minecraft:zombie_villager");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerSpawnEgg(String key) {
|
||||||
|
spawnEggs.put(key, spawnEggs.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make it a non existing block id
|
||||||
|
public static int getSpawnEggId(String entityIdentifier) {
|
||||||
|
// Fallback to bat
|
||||||
|
if (!spawnEggs.containsKey(entityIdentifier))
|
||||||
|
return 25100288;
|
||||||
|
return (383 << 16 | (spawnEggs.get(entityIdentifier) & 0xFFFF));
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.packets;
|
|||||||
|
|
||||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||||
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.google.common.base.Optional;
|
import com.google.common.base.Optional;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
@ -12,6 +13,7 @@ import us.myles.ViaVersion.api.type.Type;
|
|||||||
import us.myles.ViaVersion.packets.State;
|
import us.myles.ViaVersion.packets.State;
|
||||||
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.MappingData;
|
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.MappingData;
|
||||||
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.SoundSource;
|
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.SoundSource;
|
||||||
|
import us.myles.ViaVersion.protocols.protocolsnapshotto1_12_2.data.SpawnEggRewriter;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -196,6 +198,7 @@ public class InventoryPackets {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO CLEANUP / SMARTER REWRITE SYSTEM
|
||||||
public static void toClient(Item item) {
|
public static void toClient(Item item) {
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
|
|
||||||
@ -227,10 +230,25 @@ public class InventoryPackets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo spawn egg
|
|
||||||
|
|
||||||
int rawId = (item.getId() << 4 | item.getData() & 0xF);
|
int rawId = (item.getId() << 4 | item.getData() & 0xF);
|
||||||
|
|
||||||
|
// Handle SpawnEggs
|
||||||
|
if (item.getId() == 383) {
|
||||||
|
if (tag.contains("EntityTag")) {
|
||||||
|
CompoundTag entityTag = tag.get("EntityTag");
|
||||||
|
if (entityTag.contains("id") && entityTag.get("id") instanceof StringTag) {
|
||||||
|
StringTag identifier = entityTag.get("id");
|
||||||
|
rawId = SpawnEggRewriter.getSpawnEggId(identifier.getValue());
|
||||||
|
} else {
|
||||||
|
// Fallback to bat
|
||||||
|
rawId = 25100288;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback to bat
|
||||||
|
rawId = 25100288;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!MappingData.oldToNewItems.containsKey(rawId)) {
|
if (!MappingData.oldToNewItems.containsKey(rawId)) {
|
||||||
if (MappingData.oldToNewItems.containsKey(item.getId() << 4)) {
|
if (MappingData.oldToNewItems.containsKey(item.getId() << 4)) {
|
||||||
rawId = item.getId() << 4;
|
rawId = item.getId() << 4;
|
||||||
@ -244,6 +262,7 @@ public class InventoryPackets {
|
|||||||
item.setData((short) 0);
|
item.setData((short) 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO cleanup / smarter rewrite system
|
||||||
public static void toServer(Item item) {
|
public static void toServer(Item item) {
|
||||||
if (item == null) return;
|
if (item == null) return;
|
||||||
|
|
||||||
|
@ -2245,7 +2245,6 @@
|
|||||||
"6080": "minecraft:cauldron",
|
"6080": "minecraft:cauldron",
|
||||||
"6096": "minecraft:ender_eye",
|
"6096": "minecraft:ender_eye",
|
||||||
"6112": "minecraft:speckled_melon",
|
"6112": "minecraft:speckled_melon",
|
||||||
"6128": "minecraft:spawn_egg",
|
|
||||||
"6144": "minecraft:experience_bottle",
|
"6144": "minecraft:experience_bottle",
|
||||||
"6160": "minecraft:fire_charge",
|
"6160": "minecraft:fire_charge",
|
||||||
"6176": "minecraft:writable_book",
|
"6176": "minecraft:writable_book",
|
||||||
@ -2346,6 +2345,51 @@
|
|||||||
"36224": "minecraft:music_disc_strad",
|
"36224": "minecraft:music_disc_strad",
|
||||||
"36240": "minecraft:music_disc_ward",
|
"36240": "minecraft:music_disc_ward",
|
||||||
"36256": "minecraft:music_disc_11",
|
"36256": "minecraft:music_disc_11",
|
||||||
"36272": "minecraft:music_disc_wait"
|
"36272": "minecraft:music_disc_wait",
|
||||||
|
"25100288": "minecraft:bat_spawn_egg",
|
||||||
|
"25100289": "minecraft:blaze_spawn_egg",
|
||||||
|
"25100290": "minecraft:cave_spider_spawn_egg",
|
||||||
|
"25100291": "minecraft:chicken_spawn_egg",
|
||||||
|
"25100292": "minecraft:cow_spawn_egg",
|
||||||
|
"25100293": "minecraft:creeper_spawn_egg",
|
||||||
|
"25100294": "minecraft:donkey_spawn_egg",
|
||||||
|
"25100295": "minecraft:elder_guardian_spawn_egg",
|
||||||
|
"25100296": "minecraft:enderman_spawn_egg",
|
||||||
|
"25100297": "minecraft:endermite_spawn_egg",
|
||||||
|
"25100298": "minecraft:evocation_illager_spawn_egg",
|
||||||
|
"25100299": "minecraft:ghast_spawn_egg",
|
||||||
|
"25100300": "minecraft:guardian_spawn_egg",
|
||||||
|
"25100301": "minecraft:horse_spawn_egg",
|
||||||
|
"25100302": "minecraft:husk_spawn_egg",
|
||||||
|
"25100303": "minecraft:llama_spawn_egg",
|
||||||
|
"25100304": "minecraft:magma_cube_spawn_egg",
|
||||||
|
"25100305": "minecraft:mooshroom_spawn_egg",
|
||||||
|
"25100306": "minecraft:mule_spawn_egg",
|
||||||
|
"25100307": "minecraft:ocelot_spawn_egg",
|
||||||
|
"25100308": "minecraft:puffer_fish_spawn_egg",
|
||||||
|
"25100309": "minecraft:parrot_spawn_egg",
|
||||||
|
"25100310": "minecraft:pig_spawn_egg",
|
||||||
|
"25100311": "minecraft:polar_bear_spawn_egg",
|
||||||
|
"25100312": "minecraft:rabbit_spawn_egg",
|
||||||
|
"25100313": "minecraft:sheep_spawn_egg",
|
||||||
|
"25100314": "minecraft:shulker_spawn_egg",
|
||||||
|
"25100315": "minecraft:silverfish_spawn_egg",
|
||||||
|
"25100316": "minecraft:skeleton_spawn_egg",
|
||||||
|
"25100317": "minecraft:skeleton_horse_spawn_egg",
|
||||||
|
"25100318": "minecraft:slime_spawn_egg",
|
||||||
|
"25100319": "minecraft:spider_spawn_egg",
|
||||||
|
"25100320": "minecraft:squid_spawn_egg",
|
||||||
|
"25100321": "minecraft:stray_spawn_egg",
|
||||||
|
"25100322": "minecraft:turtle_spawn_egg",
|
||||||
|
"25100323": "minecraft:vex_spawn_egg",
|
||||||
|
"25100324": "minecraft:villager_spawn_egg",
|
||||||
|
"25100325": "minecraft:vindication_illager_spawn_egg",
|
||||||
|
"25100326": "minecraft:witch_spawn_egg",
|
||||||
|
"25100327": "minecraft:wither_skeleton_spawn_egg",
|
||||||
|
"25100328": "minecraft:wolf_spawn_egg",
|
||||||
|
"25100329": "minecraft:zombie_spawn_egg",
|
||||||
|
"25100330": "minecraft:zombie_horse_spawn_egg",
|
||||||
|
"25100331": "minecraft:zombie_pigman_spawn_egg",
|
||||||
|
"25100332": "minecraft:zombie_villager_spawn_egg"
|
||||||
}
|
}
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren