3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-09 01:30:13 +01:00

shield, damageable, map item rewriting

Dieser Commit ist enthalten in:
creeper123123321 2018-03-20 14:21:37 -03:00
Ursprung 9fe187c049
Commit c102ca7f15

Datei anzeigen

@ -200,6 +200,11 @@ public class InventoryPackets {
if (item == null) return; if (item == null) return;
int rawId = (item.getId() << 16 | item.getData() & 0xFFFF); int rawId = (item.getId() << 16 | item.getData() & 0xFFFF);
int originalId = rawId; int originalId = rawId;
// Save original id
CompoundTag tag = item.getTag();
if (tag == null) {
item.setTag(tag = new CompoundTag("tag"));
}
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;
@ -208,40 +213,90 @@ public class InventoryPackets {
rawId = 16; // Stone rawId = 16; // Stone
} }
} }
if (isDamageable(item.getId())) {
tag.put(new IntTag("Damage", item.getData()));
}
if (item.getId() == 358) { // map
tag.put(new IntTag("map", item.getData()));
}
if (item.getId() == 442) { // shield
if (tag.get("BlockEntityTag") instanceof CompoundTag) {
CompoundTag blockEntityTag = tag.get("BlockEntityTag");
if (blockEntityTag.get("Base") instanceof IntTag) {
IntTag base = blockEntityTag.get("Base");
base.setValue(15 - base.getValue());
}
}
}
item.setId(MappingData.oldToNewItems.get(rawId).shortValue()); item.setId(MappingData.oldToNewItems.get(rawId).shortValue());
item.setData((short) 0); item.setData((short) 0);
// Save original id
if (item.getTag() == null) {
item.setTag(new CompoundTag("tag"));
}
item.getTag().put(new IntTag(NBT_TAG_NAME, originalId)); item.getTag().put(new IntTag(NBT_TAG_NAME, originalId));
} }
public static void toServer(Item item) { public static void toServer(Item item) {
if (item == null) return; if (item == null) return;
if (item.getTag() != null) { Integer rawId = null;
CompoundTag tag = item.getTag(); boolean gotRawIdFromTag = false;
CompoundTag tag = item.getTag();
if (tag != null) {
// Check for valid tag // Check for valid tag
if (tag.contains(NBT_TAG_NAME)) { if (tag.contains(NBT_TAG_NAME)) {
if (tag.get(NBT_TAG_NAME) instanceof IntTag) { if (tag.get(NBT_TAG_NAME) instanceof IntTag) {
int rawId = (int) tag.get(NBT_TAG_NAME).getValue(); rawId = (Integer) tag.get(NBT_TAG_NAME).getValue();
// Remove the tag // Remove the tag
tag.remove(NBT_TAG_NAME); tag.remove(NBT_TAG_NAME);
item.setId((short) (rawId >> 16)); gotRawIdFromTag = true;
item.setData((short) (rawId & 0xFFFF));
return;
} }
} }
} }
int itemID = item.getId(); if (rawId == null) {
for (Map.Entry<Integer,Integer> entry : MappingData.oldToNewItems.entrySet()){ for (Map.Entry<Integer, Integer> entry : MappingData.oldToNewItems.entrySet()) {
if (entry.getValue() == itemID){ if (entry.getValue() == item.getId()) {
int rawId = entry.getKey(); int oldId = entry.getKey();
item.setId((short) (rawId >> 4)); rawId = oldId >> 4 << 16 | oldId & 0xF;
item.setData((short) (rawId & 0xF)); }
return;
} }
} }
System.out.println("FAILED TO GET 1.12 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T if (rawId != null) {
item.setId((short) (rawId >> 16));
item.setData((short) (rawId & 0xFFFF));
if (!gotRawIdFromTag) {
if (isDamageable(item.getId())) {
if (tag != null && tag.get("Damage") instanceof IntTag) {
item.setData((short) (int) tag.get("Damage").getValue());
}
}
if (item.getId() == 358) { // map
if (tag != null && tag.get("map") instanceof IntTag) {
item.setData((short) (int) tag.get("map").getValue());
}
}
}
if (item.getId() == 442) { // shield
if (tag != null && tag.get("BlockEntityTag") instanceof CompoundTag) {
CompoundTag blockEntityTag = tag.get("BlockEntityTag");
if (blockEntityTag.get("Base") instanceof IntTag) {
IntTag base = blockEntityTag.get("Base");
base.setValue(15 - base.getValue());
}
}
}
} else {
System.out.println("FAILED TO GET 1.12 ITEM FOR " + item.getId()); // TODO: Make this nicer etc, perhaps fix issues with mapping :T
}
}
public static boolean isDamageable(int id) {
return id >= 256 && id <= 259 // iron shovel, pickaxe, axe, flint and steel
|| id == 261 // bow
|| id >= 267 && id <= 279 // iron sword, wooden+stone+diamond swords, shovels, pickaxes, axes
|| id >= 283 && id <= 286 // gold sword, shovel, pickaxe, axe
|| id >= 290 && id <= 294 // hoes
|| id >= 298 && id <= 317 // armors
|| id == 346 // fishing rod
|| id == 359 // shears
|| id == 398 // carrot on a stick
|| id == 442 // shield
|| id == 443; // elytra
} }
} }