Skip to content

Commit 28b4998

Browse files
authored
Use gray color for elytra & brown color for shield in 1.9->1.8 (#688)
1 parent f9b0fd5 commit 28b4998

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

common/src/main/java/com/viaversion/viarewind/protocol/v1_9to1_8/rewriter/BlockItemPacketRewriter1_9.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.viaversion.nbt.tag.ByteTag;
2121
import com.viaversion.nbt.tag.CompoundTag;
22+
import com.viaversion.nbt.tag.IntTag;
2223
import com.viaversion.nbt.tag.ListTag;
2324
import com.viaversion.nbt.tag.StringTag;
2425
import com.viaversion.nbt.tag.Tag;
@@ -194,6 +195,7 @@ protected void registerRewrites() {
194195
@Override
195196
public Item handleItemToClient(UserConnection connection, Item item) {
196197
if (item == null) return null;
198+
final int originalId = item.identifier();
197199
super.handleItemToClient(connection, item);
198200

199201
CompoundTag tag = item.tag();
@@ -280,6 +282,32 @@ public Item handleItemToClient(UserConnection connection, Item item) {
280282
});
281283
}
282284

285+
// Colors the fake leather armor for an elytra gray
286+
if (originalId == 443) {
287+
if (tag == null) {
288+
item.setTag(tag = new CompoundTag());
289+
}
290+
CompoundTag display = tag.getCompoundTag("display");
291+
if (display == null) {
292+
tag.put("display", display = new CompoundTag());
293+
}
294+
display.put("color", new IntTag(0x737373)); // Gray
295+
tag.put(nbtTagName() + "|elytra_color", new ByteTag(true));
296+
}
297+
298+
// Makes the fake banner for a shield brown if it has no banner patterns
299+
if (originalId == 442) {
300+
final CompoundTag blockEntityTag = tag == null ? null : tag.getCompoundTag("BlockEntityTag");
301+
final ListTag<CompoundTag> patterns = blockEntityTag == null ? null : blockEntityTag.getListTag("Patterns", CompoundTag.class);
302+
if (patterns == null || patterns.isEmpty()) {
303+
item.setData((short) 3); // Brown
304+
if (tag == null) {
305+
item.setTag(tag = new CompoundTag());
306+
}
307+
tag.put(nbtTagName() + "|shield_color", new ByteTag(true));
308+
}
309+
}
310+
283311
return item;
284312
}
285313

@@ -290,6 +318,19 @@ public Item handleItemToServer(UserConnection connection, Item item) {
290318

291319
CompoundTag tag = item.tag();
292320

321+
// Removes the gray color code from the fake leather armor for an elytra
322+
if (tag != null && tag.remove(nbtTagName() + "|elytra_color") != null) {
323+
final CompoundTag display = tag.getCompoundTag("display");
324+
if (display != null) {
325+
display.remove("color");
326+
}
327+
}
328+
329+
// Restores the original data of a shield whose banner color was changed to brown
330+
if (tag != null && tag.remove(nbtTagName() + "|shield_color") != null) {
331+
item.setData((short) 0);
332+
}
333+
293334
enchantmentRewriter.handleToServer(item);
294335

295336
if (item.identifier() == 383 && item.data() != 0) { // Spawn eggs

0 commit comments

Comments
 (0)