Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-27 00:22:53 +01:00
Merge remote-tracking branch 'origin/master' into dev
Dieser Commit ist enthalten in:
Commit
19ec92c261
@ -50,7 +50,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
T extends BackwardsProtocol<C, ?, ?, S>> extends ItemRewriterBase<C, S, T> {
|
||||
|
||||
private static final Map<String, Int2ObjectMap<MappedLegacyBlockItem>> LEGACY_MAPPINGS = new HashMap<>();
|
||||
protected final Int2ObjectMap<MappedLegacyBlockItem> replacementData;
|
||||
protected final Int2ObjectMap<MappedLegacyBlockItem> replacementData; // Raw id -> mapped data
|
||||
|
||||
static {
|
||||
JsonObject jsonObject = VBMappingDataLoader.loadFromDataDir("legacy-mappings.json");
|
||||
@ -58,7 +58,12 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
Int2ObjectMap<MappedLegacyBlockItem> mappings = new Int2ObjectOpenHashMap<>(8);
|
||||
LEGACY_MAPPINGS.put(entry.getKey(), mappings);
|
||||
for (Map.Entry<String, JsonElement> dataEntry : entry.getValue().getAsJsonObject().entrySet()) {
|
||||
JsonObject object = dataEntry.getValue().getAsJsonObject();
|
||||
addMapping(dataEntry.getKey(), dataEntry.getValue().getAsJsonObject(), mappings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void addMapping(String key, JsonObject object, Int2ObjectMap<MappedLegacyBlockItem> mappings) {
|
||||
int id = object.getAsJsonPrimitive("id").getAsInt();
|
||||
JsonPrimitive jsonData = object.getAsJsonPrimitive("data");
|
||||
short data = jsonData != null ? jsonData.getAsShort() : 0;
|
||||
@ -66,26 +71,36 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
JsonPrimitive blockField = object.getAsJsonPrimitive("block");
|
||||
boolean block = blockField != null && blockField.getAsBoolean();
|
||||
|
||||
if (dataEntry.getKey().indexOf('-') != -1) {
|
||||
if (key.indexOf('-') == -1) {
|
||||
int unmappedId;
|
||||
int dataSeparatorIndex = key.indexOf(':');
|
||||
if (dataSeparatorIndex != -1) {
|
||||
// Include data
|
||||
short unmappedData = Short.parseShort(key.substring(dataSeparatorIndex + 1));
|
||||
unmappedId = Integer.parseInt(key.substring(0, dataSeparatorIndex));
|
||||
unmappedId = (unmappedId << 4) | (unmappedData & 15);
|
||||
} else {
|
||||
unmappedId = Integer.parseInt(key) << 4;
|
||||
}
|
||||
|
||||
mappings.put(unmappedId, new MappedLegacyBlockItem(id, data, name, block));
|
||||
return;
|
||||
}
|
||||
|
||||
// Range of ids
|
||||
String[] split = dataEntry.getKey().split("-", 2);
|
||||
String[] split = key.split("-", 2);
|
||||
int from = Integer.parseInt(split[0]);
|
||||
int to = Integer.parseInt(split[1]);
|
||||
|
||||
// Special block color handling
|
||||
if (name.contains("%color%")) {
|
||||
for (int i = from; i <= to; i++) {
|
||||
mappings.put(i, new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors.get(i - from)), block));
|
||||
mappings.put(i << 4, new MappedLegacyBlockItem(id, data, name.replace("%color%", BlockColors.get(i - from)), block));
|
||||
}
|
||||
} else {
|
||||
MappedLegacyBlockItem mappedBlockItem = new MappedLegacyBlockItem(id, data, name, block);
|
||||
for (int i = from; i <= to; i++) {
|
||||
mappings.put(i, mappedBlockItem);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mappings.put(Integer.parseInt(dataEntry.getKey()), new MappedLegacyBlockItem(id, data, name, block));
|
||||
}
|
||||
mappings.put(i << 4, mappedBlockItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -99,7 +114,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
public @Nullable Item handleItemToClient(@Nullable Item item) {
|
||||
if (item == null) return null;
|
||||
|
||||
MappedLegacyBlockItem data = replacementData.get(item.identifier());
|
||||
MappedLegacyBlockItem data = getMappedBlockItem(item.identifier(), item.data());
|
||||
if (data == null) {
|
||||
// Just rewrite the id
|
||||
return super.handleItemToClient(item);
|
||||
@ -149,7 +164,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
public @Nullable Block handleBlock(int blockId, int data) {
|
||||
MappedLegacyBlockItem settings = replacementData.get(blockId);
|
||||
MappedLegacyBlockItem settings = getMappedBlockItem(blockId, data);
|
||||
if (settings == null || !settings.isBlock()) return null;
|
||||
|
||||
Block block = settings.getBlock();
|
||||
@ -160,6 +175,16 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
return block;
|
||||
}
|
||||
|
||||
private @Nullable MappedLegacyBlockItem getMappedBlockItem(int id, int data) {
|
||||
MappedLegacyBlockItem mapping = replacementData.get((id << 4) | (data & 15));
|
||||
return mapping != null || data == 0 ? mapping : replacementData.get(id << 4);
|
||||
}
|
||||
|
||||
private @Nullable MappedLegacyBlockItem getMappedBlockItem(int rawId) {
|
||||
MappedLegacyBlockItem mapping = replacementData.get(rawId);
|
||||
return mapping != null ? mapping : replacementData.get(rawId & ~15);
|
||||
}
|
||||
|
||||
protected void handleChunk(Chunk chunk) {
|
||||
// Map Block Entities
|
||||
Map<Pos, CompoundTag> tags = new HashMap<>();
|
||||
@ -184,9 +209,8 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
if (section == null) continue;
|
||||
|
||||
int block = section.palette(PaletteType.BLOCKS).idAt(pos.getX(), pos.getY() & 0xF, pos.getZ());
|
||||
int btype = block >> 4;
|
||||
|
||||
MappedLegacyBlockItem settings = replacementData.get(btype);
|
||||
MappedLegacyBlockItem settings = getMappedBlockItem(block);
|
||||
if (settings != null && settings.hasBlockEntityHandler()) {
|
||||
settings.getBlockEntityHandler().handleOrNewCompoundTag(block, tag);
|
||||
}
|
||||
@ -215,7 +239,7 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
// We already know that is has a handler
|
||||
if (hasBlockEntityHandler) continue;
|
||||
|
||||
MappedLegacyBlockItem settings = replacementData.get(btype);
|
||||
MappedLegacyBlockItem settings = getMappedBlockItem(block);
|
||||
if (settings != null && settings.hasBlockEntityHandler()) {
|
||||
hasBlockEntityHandler = true;
|
||||
}
|
||||
@ -228,10 +252,8 @@ public abstract class LegacyBlockItemRewriter<C extends ClientboundPacketType, S
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
int block = palette.idAt(x, y, z);
|
||||
int btype = block >> 4;
|
||||
int meta = block & 15;
|
||||
|
||||
MappedLegacyBlockItem settings = replacementData.get(btype);
|
||||
MappedLegacyBlockItem settings = getMappedBlockItem(block);
|
||||
if (settings == null || !settings.hasBlockEntityHandler()) continue;
|
||||
|
||||
Pos pos = new Pos(x, (y + (i << 4)), z);
|
||||
|
@ -306,7 +306,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
|
||||
@Override
|
||||
protected void registerRewrites() {
|
||||
// Handle spawner block entity (map to itself with custom handler)
|
||||
MappedLegacyBlockItem data = replacementData.computeIfAbsent(52, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
|
||||
MappedLegacyBlockItem data = replacementData.computeIfAbsent(52 << 4, s -> new MappedLegacyBlockItem(52, (short) -1, null, false));
|
||||
data.setBlockEntityHandler((b, tag) -> {
|
||||
EntityIdRewriter.toClientSpawner(tag, true);
|
||||
return tag;
|
||||
|
@ -160,6 +160,10 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
|
||||
|
||||
CompoundTag heightMaps = chunk.getHeightMap();
|
||||
for (Tag heightMapTag : heightMaps.values()) {
|
||||
if (!(heightMapTag instanceof LongArrayTag)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LongArrayTag heightMap = (LongArrayTag) heightMapTag;
|
||||
int[] heightMapData = new int[256];
|
||||
CompactArrayUtil.iterateCompactArrayWithPadding(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v);
|
||||
|
@ -340,7 +340,7 @@ public final class Protocol1_20_2To1_20_3 extends BackwardsProtocol<ClientboundP
|
||||
|
||||
cancelClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_POP.getId());
|
||||
registerServerbound(State.CONFIGURATION, ServerboundConfigurationPackets1_20_2.RESOURCE_PACK, resourcePackStatusHandler());
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_PUSH.getId(), ServerboundConfigurationPackets1_20_2.RESOURCE_PACK.getId(), resourcePackHandler());
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.RESOURCE_PACK_PUSH.getId(), ClientboundConfigurationPackets1_20_2.RESOURCE_PACK.getId(), resourcePackHandler());
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.UPDATE_TAGS.getId(), ClientboundConfigurationPackets1_20_2.UPDATE_TAGS.getId(), tagRewriter.getGenericHandler());
|
||||
// TODO Auto map via packet types provider
|
||||
registerClientbound(State.CONFIGURATION, ClientboundConfigurationPackets1_20_3.UPDATE_ENABLED_FEATURES.getId(), ClientboundConfigurationPackets1_20_2.UPDATE_ENABLED_FEATURES.getId());
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren