3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-03 14:50:30 +01:00
Dieser Commit ist enthalten in:
KennyTV 2020-12-02 22:31:02 +01:00
Ursprung 8a11b577eb
Commit ff91dd7082
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
3 geänderte Dateien mit 50 neuen und 38 gelöschten Zeilen

Datei anzeigen

@ -5,5 +5,6 @@ public enum RegistryType {
BLOCK,
ITEM,
FLUID,
ENTITY
ENTITY,
GAME_EVENT
}

Datei anzeigen

@ -7,20 +7,20 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.MappingData;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
public class TagRewriter {
private static final int[] EMPTY_ARRAY = {};
private final Protocol protocol;
private final IdRewriteFunction entityRewriter;
private final List<TagData> newBlockTags = new ArrayList<>();
private final List<TagData> newItemTags = new ArrayList<>();
private final List<TagData> newEntityTags = new ArrayList<>();
// add fluid tag list if needed at some point
private final Map<RegistryType, List<TagData>> newTags = new EnumMap<>(RegistryType.class);
public TagRewriter(Protocol protocol, @Nullable IdRewriteFunction entityRewriter) {
this.protocol = protocol;
@ -31,18 +31,18 @@ public class TagRewriter {
* Adds an empty tag (since the client crashes if a checked tag is not registered.)
*/
public void addEmptyTag(RegistryType tagType, String id) {
getNewTags(tagType).add(new TagData(id, EMPTY_ARRAY));
getOrComputeNewTags(tagType).add(new TagData(id, EMPTY_ARRAY));
}
public void addEmptyTags(RegistryType tagType, String... ids) {
List<TagData> tagList = getNewTags(tagType);
List<TagData> tagList = getOrComputeNewTags(tagType);
for (String id : ids) {
tagList.add(new TagData(id, EMPTY_ARRAY));
}
}
public void addTag(RegistryType tagType, String id, int... oldIds) {
List<TagData> newTags = getNewTags(tagType);
List<TagData> newTags = getOrComputeNewTags(tagType);
IdRewriteFunction rewriteFunction = getRewriter(tagType);
for (int i = 0; i < oldIds.length; i++) {
int oldId = oldIds[i];
@ -52,29 +52,32 @@ public class TagRewriter {
}
public void register(ClientboundPacketType packetType) {
register(packetType, false);
}
public void register(ClientboundPacketType packetType, boolean hasGameEvents) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
MappingData mappingData = protocol.getMappingData();
handle(wrapper, id -> mappingData != null ? mappingData.getNewBlockId(id) : null, newBlockTags);
handle(wrapper, id -> mappingData != null ? mappingData.getNewItemId(id) : null, newItemTags);
if (entityRewriter == null && newEntityTags.isEmpty()) return;
int fluidTagsSize = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < fluidTagsSize; i++) {
wrapper.passthrough(Type.STRING);
wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE);
}
handle(wrapper, entityRewriter, newEntityTags);
});
handler(getHandler(hasGameEvents));
}
});
}
private void handle(PacketWrapper wrapper, IdRewriteFunction rewriteFunction, List<TagData> newTags) throws Exception {
public PacketHandler getHandler(boolean hasGameEvents) {
return wrapper -> {
MappingData mappingData = protocol.getMappingData();
handle(wrapper, id -> mappingData != null ? mappingData.getNewBlockId(id) : null, getNewTags(RegistryType.BLOCK));
handle(wrapper, id -> mappingData != null ? mappingData.getNewItemId(id) : null, getNewTags(RegistryType.ITEM));
handle(wrapper, null, getNewTags(RegistryType.FLUID));
handle(wrapper, entityRewriter, getNewTags(RegistryType.ENTITY));
if (hasGameEvents) {
handle(wrapper, null, getNewTags(RegistryType.GAME_EVENT));
}
};
}
private void handle(PacketWrapper wrapper, @Nullable IdRewriteFunction rewriteFunction, List<TagData> newTags) throws Exception {
int tagsSize = wrapper.read(Type.VAR_INT);
wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count
@ -107,18 +110,13 @@ public class TagRewriter {
}
}
@Nullable
private List<TagData> getNewTags(RegistryType tagType) {
switch (tagType) {
case BLOCK:
return newBlockTags;
case ITEM:
return newItemTags;
case ENTITY:
return newEntityTags;
case FLUID:
default:
return null;
}
return newTags.get(tagType);
}
private List<TagData> getOrComputeNewTags(RegistryType tagType) {
return newTags.computeIfAbsent(tagType, type -> new ArrayList<>());
}
@Nullable

Datei anzeigen

@ -22,6 +22,7 @@ import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.storage.EntityTracker1
public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, ClientboundPackets1_17, ServerboundPackets1_16_2, ServerboundPackets1_16_2> {
public static final MappingData MAPPINGS = new MappingData("1.16.2", "1.17", true);
private static final String[] NEW_GAME_EVENT_TAGS = {"minecraft:ignore_vibrations_stepping_carefully", "minecraft:vibrations"};
private TagRewriter tagRewriter;
public Protocol1_17To1_16_4() {
@ -37,7 +38,20 @@ public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, Cli
WorldPackets.register(this);
tagRewriter = new TagRewriter(this, null);
tagRewriter.register(ClientboundPackets1_16_2.TAGS);
registerOutgoing(ClientboundPackets1_16_2.TAGS, new PacketRemapper() {
@Override
public void registerMap() {
handler(tagRewriter.getHandler(false));
handler(wrapper -> {
// New Game Event tags type
wrapper.write(Type.VAR_INT, NEW_GAME_EVENT_TAGS.length);
for (String tag : NEW_GAME_EVENT_TAGS) {
wrapper.write(Type.STRING, tag);
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, new int[0]);
}
});
}
});
new StatisticsRewriter(this, null).register(ClientboundPackets1_16_2.STATISTICS);
@ -82,8 +96,7 @@ public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, Cli
protected void onMappingDataLoaded() {
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:candles", "minecraft:ignored_by_piglin_babies", "minecraft:piglin_food", "minecraft:freeze_immune_wearables");
tagRewriter.addEmptyTags(RegistryType.BLOCK, "minecraft:crystal_sound_blocks", "minecraft:candle_cakes", "minecraft:candles",
"minecraft:snow_step_sound_blocks", "minecraft:inside_step_sound_blocks", "minecraft:occludes_vibration_signals",
"minecraft:dripstone_replaceable_blocks", "minecraft:ignore_vibrations_stepping_carefully");
"minecraft:snow_step_sound_blocks", "minecraft:inside_step_sound_blocks", "minecraft:occludes_vibration_signals", "minecraft:dripstone_replaceable_blocks");
tagRewriter.addEmptyTag(RegistryType.ENTITY, "minecraft:powder_snow_walkable_mobs");
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:cauldrons", 261);
}