Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 09:00:09 +01:00
Finish 20w49a
Dieser Commit ist enthalten in:
Ursprung
8a11b577eb
Commit
ff91dd7082
@ -5,5 +5,6 @@ public enum RegistryType {
|
|||||||
BLOCK,
|
BLOCK,
|
||||||
ITEM,
|
ITEM,
|
||||||
FLUID,
|
FLUID,
|
||||||
ENTITY
|
ENTITY,
|
||||||
|
GAME_EVENT
|
||||||
}
|
}
|
||||||
|
@ -7,20 +7,20 @@ import us.myles.ViaVersion.api.PacketWrapper;
|
|||||||
import us.myles.ViaVersion.api.data.MappingData;
|
import us.myles.ViaVersion.api.data.MappingData;
|
||||||
import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
|
import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
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.remapper.PacketRemapper;
|
||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class TagRewriter {
|
public class TagRewriter {
|
||||||
private static final int[] EMPTY_ARRAY = {};
|
private static final int[] EMPTY_ARRAY = {};
|
||||||
private final Protocol protocol;
|
private final Protocol protocol;
|
||||||
private final IdRewriteFunction entityRewriter;
|
private final IdRewriteFunction entityRewriter;
|
||||||
private final List<TagData> newBlockTags = new ArrayList<>();
|
private final Map<RegistryType, List<TagData>> newTags = new EnumMap<>(RegistryType.class);
|
||||||
private final List<TagData> newItemTags = new ArrayList<>();
|
|
||||||
private final List<TagData> newEntityTags = new ArrayList<>();
|
|
||||||
// add fluid tag list if needed at some point
|
|
||||||
|
|
||||||
public TagRewriter(Protocol protocol, @Nullable IdRewriteFunction entityRewriter) {
|
public TagRewriter(Protocol protocol, @Nullable IdRewriteFunction entityRewriter) {
|
||||||
this.protocol = protocol;
|
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.)
|
* Adds an empty tag (since the client crashes if a checked tag is not registered.)
|
||||||
*/
|
*/
|
||||||
public void addEmptyTag(RegistryType tagType, String id) {
|
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) {
|
public void addEmptyTags(RegistryType tagType, String... ids) {
|
||||||
List<TagData> tagList = getNewTags(tagType);
|
List<TagData> tagList = getOrComputeNewTags(tagType);
|
||||||
for (String id : ids) {
|
for (String id : ids) {
|
||||||
tagList.add(new TagData(id, EMPTY_ARRAY));
|
tagList.add(new TagData(id, EMPTY_ARRAY));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTag(RegistryType tagType, String id, int... oldIds) {
|
public void addTag(RegistryType tagType, String id, int... oldIds) {
|
||||||
List<TagData> newTags = getNewTags(tagType);
|
List<TagData> newTags = getOrComputeNewTags(tagType);
|
||||||
IdRewriteFunction rewriteFunction = getRewriter(tagType);
|
IdRewriteFunction rewriteFunction = getRewriter(tagType);
|
||||||
for (int i = 0; i < oldIds.length; i++) {
|
for (int i = 0; i < oldIds.length; i++) {
|
||||||
int oldId = oldIds[i];
|
int oldId = oldIds[i];
|
||||||
@ -52,29 +52,32 @@ public class TagRewriter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void register(ClientboundPacketType packetType) {
|
public void register(ClientboundPacketType packetType) {
|
||||||
|
register(packetType, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void register(ClientboundPacketType packetType, boolean hasGameEvents) {
|
||||||
protocol.registerOutgoing(packetType, new PacketRemapper() {
|
protocol.registerOutgoing(packetType, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
public void registerMap() {
|
public void registerMap() {
|
||||||
handler(wrapper -> {
|
handler(getHandler(hasGameEvents));
|
||||||
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);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
int tagsSize = wrapper.read(Type.VAR_INT);
|
||||||
wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count
|
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) {
|
private List<TagData> getNewTags(RegistryType tagType) {
|
||||||
switch (tagType) {
|
return newTags.get(tagType);
|
||||||
case BLOCK:
|
}
|
||||||
return newBlockTags;
|
|
||||||
case ITEM:
|
private List<TagData> getOrComputeNewTags(RegistryType tagType) {
|
||||||
return newItemTags;
|
return newTags.computeIfAbsent(tagType, type -> new ArrayList<>());
|
||||||
case ENTITY:
|
|
||||||
return newEntityTags;
|
|
||||||
case FLUID:
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -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 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);
|
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;
|
private TagRewriter tagRewriter;
|
||||||
|
|
||||||
public Protocol1_17To1_16_4() {
|
public Protocol1_17To1_16_4() {
|
||||||
@ -37,7 +38,20 @@ public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, Cli
|
|||||||
WorldPackets.register(this);
|
WorldPackets.register(this);
|
||||||
|
|
||||||
tagRewriter = new TagRewriter(this, null);
|
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);
|
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() {
|
protected void onMappingDataLoaded() {
|
||||||
tagRewriter.addEmptyTags(RegistryType.ITEM, "minecraft:candles", "minecraft:ignored_by_piglin_babies", "minecraft:piglin_food", "minecraft:freeze_immune_wearables");
|
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",
|
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:snow_step_sound_blocks", "minecraft:inside_step_sound_blocks", "minecraft:occludes_vibration_signals", "minecraft:dripstone_replaceable_blocks");
|
||||||
"minecraft:dripstone_replaceable_blocks", "minecraft:ignore_vibrations_stepping_carefully");
|
|
||||||
tagRewriter.addEmptyTag(RegistryType.ENTITY, "minecraft:powder_snow_walkable_mobs");
|
tagRewriter.addEmptyTag(RegistryType.ENTITY, "minecraft:powder_snow_walkable_mobs");
|
||||||
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:cauldrons", 261);
|
tagRewriter.addTag(RegistryType.BLOCK, "minecraft:cauldrons", 261);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren