3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 17:10:13 +01:00

Minor cleanup to tagrewriter

Dieser Commit ist enthalten in:
KennyTV 2020-04-03 11:29:59 +02:00
Ursprung 8314f6c1db
Commit 7cdcdfa3c9
3 geänderte Dateien mit 51 neuen und 24 gelöschten Zeilen

Datei anzeigen

@ -26,28 +26,18 @@ public class TagRewriter {
this.entityRewriter = entityRewriter;
}
public void addEmptyBlockTag(String id) {
newBlockTags.add(new TagData(id, EMPTY_ARRAY));
public void addEmptyTag(TagType tagType, String id) {
getNewTags(tagType).add(new TagData(id, EMPTY_ARRAY));
}
public void addEmptyItemTag(String id) {
newItemTags.add(new TagData(id, EMPTY_ARRAY));
}
public void addBlockTag(String id, int... oldBlockIds) {
addTag(newBlockTags, blockRewriter, id, oldBlockIds);
}
public void addItemTag(String id, int... oldItemIds) {
addTag(newItemTags, itemRewriter, id, oldItemIds);
}
private void addTag(List<TagData> list, IdRewriteFunction rewriteFunction, String id, int... oldIds) {
public void addTag(TagType tagType, String id, int... oldIds) {
List<TagData> newTags = getNewTags(tagType);
IdRewriteFunction rewriteFunction = getRewriter(tagType);
for (int i = 0; i < oldIds.length; i++) {
int oldId = oldIds[i];
oldIds[i] = rewriteFunction.rewrite(oldId);
}
list.add(new TagData(id, oldIds));
newTags.add(new TagData(id, oldIds));
}
public void register(int oldId, int newId) {
@ -95,6 +85,33 @@ public class TagRewriter {
}
}
private List<TagData> getNewTags(TagType tagType) {
switch (tagType) {
case BLOCK:
return newBlockTags;
case ITEM:
return newItemTags;
case ENTITY:
case FLUID:
default:
return null;
}
}
private IdRewriteFunction getRewriter(TagType tagType) {
switch (tagType) {
case BLOCK:
return blockRewriter;
case ITEM:
return itemRewriter;
case ENTITY:
return entityRewriter;
case FLUID:
default:
return null;
}
}
private static final class TagData {
private final String identifier;
private final int[] entries;

Datei anzeigen

@ -0,0 +1,9 @@
package us.myles.ViaVersion.api.rewriters;
public enum TagType {
BLOCK,
ITEM,
FLUID,
ENTITY
}

Datei anzeigen

@ -5,6 +5,7 @@ import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.TagRewriter;
import us.myles.ViaVersion.api.rewriters.TagType;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
@ -29,15 +30,15 @@ public class Protocol1_16To1_15_2 extends Protocol {
InventoryPackets.register(this);
TagRewriter tagRewriter = new TagRewriter(this, Protocol1_16To1_15_2::getNewBlockId, InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId);
tagRewriter.addBlockTag("minecraft:beacon_base_blocks", 133, 134, 148, 265);
tagRewriter.addBlockTag("minecraft:climbable", 160, 241, 658);
tagRewriter.addTag(TagType.BLOCK, "minecraft:beacon_base_blocks", 133, 134, 148, 265);
tagRewriter.addTag(TagType.BLOCK, "minecraft:climbable", 160, 241, 658);
// The client crashes if we don't send these tags
tagRewriter.addEmptyBlockTag("minecraft:soul_speed_blocks");
tagRewriter.addEmptyBlockTag("minecraft:soul_fire_base_blocks");
tagRewriter.addEmptyBlockTag("minecraft:fire");
tagRewriter.addEmptyBlockTag("minecraft:beacon_payment_items");
tagRewriter.addEmptyBlockTag("minecraft:non_flammable_wood");
tagRewriter.addEmptyItemTag("minecraft:non_flammable_wood");
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:soul_speed_blocks");
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:soul_fire_base_blocks");
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:fire");
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:beacon_payment_items");
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:non_flammable_wood");
tagRewriter.addEmptyTag(TagType.ITEM, "minecraft:non_flammable_wood");
tagRewriter.register(0x5C, 0x5C);
// Login Success