Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 08:30:09 +01:00
Handle block ids in tool and adventure more predicate data
Dieser Commit ist enthalten in:
Ursprung
e977e8db90
Commit
cc6f789334
@ -52,6 +52,8 @@ public interface MappingData {
|
|||||||
*/
|
*/
|
||||||
int getNewBlockId(int id);
|
int getNewBlockId(int id);
|
||||||
|
|
||||||
|
int getOldBlockId(int id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the mapped item id, or -1 if unmapped.
|
* Returns the mapped item id, or -1 if unmapped.
|
||||||
*
|
*
|
||||||
|
@ -39,13 +39,13 @@ public class MappingDataBase implements MappingData {
|
|||||||
|
|
||||||
protected final String unmappedVersion;
|
protected final String unmappedVersion;
|
||||||
protected final String mappedVersion;
|
protected final String mappedVersion;
|
||||||
protected BiMappings itemMappings;
|
|
||||||
protected FullMappings argumentTypeMappings;
|
protected FullMappings argumentTypeMappings;
|
||||||
protected FullMappings entityMappings;
|
protected FullMappings entityMappings;
|
||||||
protected FullMappings recipeSerializerMappings;
|
protected FullMappings recipeSerializerMappings;
|
||||||
protected FullMappings itemDataSerializerMappings;
|
protected FullMappings itemDataSerializerMappings;
|
||||||
protected ParticleMappings particleMappings;
|
protected ParticleMappings particleMappings;
|
||||||
protected Mappings blockMappings;
|
protected BiMappings itemMappings;
|
||||||
|
protected BiMappings blockMappings;
|
||||||
protected Mappings blockStateMappings;
|
protected Mappings blockStateMappings;
|
||||||
protected Mappings blockEntityMappings;
|
protected Mappings blockEntityMappings;
|
||||||
protected Mappings soundMappings;
|
protected Mappings soundMappings;
|
||||||
@ -68,7 +68,7 @@ public class MappingDataBase implements MappingData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final CompoundTag data = readMappingsFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
|
final CompoundTag data = readMappingsFile("mappings-" + unmappedVersion + "to" + mappedVersion + ".nbt");
|
||||||
blockMappings = loadMappings(data, "blocks");
|
blockMappings = loadBiMappings(data, "blocks");
|
||||||
blockStateMappings = loadMappings(data, "blockstates");
|
blockStateMappings = loadMappings(data, "blockstates");
|
||||||
blockEntityMappings = loadMappings(data, "blockentities");
|
blockEntityMappings = loadMappings(data, "blockentities");
|
||||||
soundMappings = loadMappings(data, "sounds");
|
soundMappings = loadMappings(data, "sounds");
|
||||||
@ -178,6 +178,11 @@ public class MappingDataBase implements MappingData {
|
|||||||
return checkValidity(id, blockMappings.getNewId(id), "block");
|
return checkValidity(id, blockMappings.getNewId(id), "block");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getOldBlockId(final int id) {
|
||||||
|
return blockMappings.getNewIdOrDefault(id, 1);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNewItemId(final int id) {
|
public int getNewItemId(final int id) {
|
||||||
return checkValidity(id, itemMappings.getNewId(id), "item");
|
return checkValidity(id, itemMappings.getNewId(id), "item");
|
||||||
|
@ -99,6 +99,24 @@ public final class StructuredDataContainer {
|
|||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates and returns the structured data by id if not empty.
|
||||||
|
*
|
||||||
|
* @param key serializer id
|
||||||
|
* @param mappingFunction function to update existing data
|
||||||
|
* @param <T> data type
|
||||||
|
* @return updated structured data if not empty
|
||||||
|
*/
|
||||||
|
public <T> @Nullable StructuredData<T> updateIfPresent(final StructuredDataKey<T> key, final Function<T, T> mappingFunction) {
|
||||||
|
final StructuredData<T> data = this.getNonEmpty(key);
|
||||||
|
if (data == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.setValue(mappingFunction.apply(data.value()));
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
public <T> void set(final StructuredDataKey<T> key, final T value) {
|
public <T> void set(final StructuredDataKey<T> key, final T value) {
|
||||||
final int id = serializerId(key);
|
final int id = serializerId(key);
|
||||||
if (id != -1) {
|
if (id != -1) {
|
||||||
|
@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
|||||||
|
|
||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||||
|
|
||||||
public record AdventureModePredicate(BlockPredicate[] predicates, boolean showInTooltip) {
|
public record AdventureModePredicate(BlockPredicate[] predicates, boolean showInTooltip) {
|
||||||
|
|
||||||
@ -42,4 +43,10 @@ public record AdventureModePredicate(BlockPredicate[] predicates, boolean showIn
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public AdventureModePredicate rewrite(final Int2IntFunction blockIdRewriter) {
|
||||||
|
for (int i = 0; i < predicates.length; i++) {
|
||||||
|
predicates[i] = predicates[i].rewrite(blockIdRewriter);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ import com.viaversion.viaversion.api.type.Type;
|
|||||||
import com.viaversion.viaversion.api.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public record BlockPredicate(@Nullable HolderSet holderSet, StatePropertyMatcher @Nullable [] propertyMatchers,
|
public record BlockPredicate(@Nullable HolderSet holderSet, StatePropertyMatcher @Nullable [] propertyMatchers,
|
||||||
@ -56,4 +57,15 @@ public record BlockPredicate(@Nullable HolderSet holderSet, StatePropertyMatcher
|
|||||||
};
|
};
|
||||||
public static final Type<BlockPredicate[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
public static final Type<BlockPredicate[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
public BlockPredicate rewrite(final Int2IntFunction blockIdRewriter) {
|
||||||
|
if (holderSet == null || holderSet.hasTagKey()) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int[] ids = holderSet.ids();
|
||||||
|
for (int i = 0; i < ids.length; i++) {
|
||||||
|
ids[i] = blockIdRewriter.apply(ids[i]);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,9 @@ public final class PotDecorations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PotDecorations rewrite(final Int2IntFunction idRewriteFunction) {
|
public PotDecorations rewrite(final Int2IntFunction idRewriteFunction) {
|
||||||
final int[] newItems = new int[itemIds.length];
|
|
||||||
for (int i = 0; i < itemIds.length; i++) {
|
for (int i = 0; i < itemIds.length; i++) {
|
||||||
newItems[i] = idRewriteFunction.applyAsInt(itemIds[i]);
|
itemIds[i] = idRewriteFunction.apply(itemIds[i]);
|
||||||
}
|
}
|
||||||
return new PotDecorations(newItems);
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.minecraft.item.data;
|
|||||||
import com.viaversion.viaversion.api.type.Type;
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
import com.viaversion.viaversion.api.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||||
|
|
||||||
public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int damagePerBlock) {
|
public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int damagePerBlock) {
|
||||||
|
|
||||||
@ -45,4 +46,10 @@ public record ToolProperties(ToolRule[] rules, float defaultMiningSpeed, int dam
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public ToolProperties rewrite(final Int2IntFunction blockIdRewriter) {
|
||||||
|
for (int i = 0; i < rules.length; i++) {
|
||||||
|
rules[i] = rules[i].rewrite(blockIdRewriter);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import com.viaversion.viaversion.api.type.Type;
|
|||||||
import com.viaversion.viaversion.api.type.Types;
|
import com.viaversion.viaversion.api.type.Types;
|
||||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public record ToolRule(HolderSet blocks, @Nullable Float speed, @Nullable Boolean correctForDrops) {
|
public record ToolRule(HolderSet blocks, @Nullable Float speed, @Nullable Boolean correctForDrops) {
|
||||||
@ -49,4 +50,15 @@ public record ToolRule(HolderSet blocks, @Nullable Float speed, @Nullable Boolea
|
|||||||
};
|
};
|
||||||
public static final Type<ToolRule[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
public static final Type<ToolRule[]> ARRAY_TYPE = new ArrayType<>(TYPE);
|
||||||
|
|
||||||
|
public ToolRule rewrite(final Int2IntFunction blockIdRewriter) {
|
||||||
|
if (blocks.hasTagKey()) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
final int[] ids = blocks.ids();
|
||||||
|
for (int i = 0; i < ids.length; i++) {
|
||||||
|
ids[i] = blockIdRewriter.apply(ids[i]);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,6 @@ import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
|||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrim;
|
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.PotDecorations;
|
|
||||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||||
@ -88,7 +86,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateItemComponents(connection, dataContainer, this::handleItemToClient, mappingData != null ? mappingData::getNewItemId : null);
|
updateItemComponents(connection, dataContainer, this::handleItemToClient, mappingData != null ? mappingData::getNewItemId : null, mappingData != null ? mappingData::getNewBlockId : null);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,20 +111,25 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
|||||||
}
|
}
|
||||||
|
|
||||||
restoreTextComponents(item);
|
restoreTextComponents(item);
|
||||||
updateItemComponents(connection, dataContainer, this::handleItemToServer, mappingData != null ? mappingData::getOldItemId : null);
|
updateItemComponents(connection, dataContainer, this::handleItemToServer, mappingData != null ? mappingData::getOldItemId : null, mappingData != null ? mappingData::getOldBlockId : null);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Temporary
|
||||||
protected void updateItemComponents(UserConnection connection, StructuredDataContainer container, ItemHandler itemHandler, @Nullable Int2IntFunction idRewriter) {
|
protected void updateItemComponents(UserConnection connection, StructuredDataContainer container, ItemHandler itemHandler, @Nullable Int2IntFunction idRewriter) {
|
||||||
// Specific types that need deep handling
|
updateItemComponents(connection, container, itemHandler, idRewriter, null);
|
||||||
final StructuredData<ArmorTrim> trimData = container.getNonEmpty(StructuredDataKey.TRIM);
|
}
|
||||||
if (trimData != null && idRewriter != null) {
|
|
||||||
trimData.setValue(trimData.value().rewrite(idRewriter));
|
|
||||||
}
|
|
||||||
|
|
||||||
final StructuredData<PotDecorations> potDecorationsData = container.getNonEmpty(StructuredDataKey.POT_DECORATIONS);
|
protected void updateItemComponents(UserConnection connection, StructuredDataContainer container, ItemHandler itemHandler, @Nullable Int2IntFunction idRewriter, @Nullable Int2IntFunction blockIdRewriter) {
|
||||||
if (potDecorationsData != null && idRewriter != null) {
|
// Specific types that need deep handling
|
||||||
potDecorationsData.setValue(potDecorationsData.value().rewrite(idRewriter));
|
if (idRewriter != null) {
|
||||||
|
container.updateIfPresent(StructuredDataKey.TRIM, value -> value.rewrite(idRewriter));
|
||||||
|
container.updateIfPresent(StructuredDataKey.POT_DECORATIONS, value -> value.rewrite(idRewriter));
|
||||||
|
}
|
||||||
|
if (blockIdRewriter != null) {
|
||||||
|
container.updateIfPresent(StructuredDataKey.TOOL, value -> value.rewrite(blockIdRewriter));
|
||||||
|
container.updateIfPresent(StructuredDataKey.CAN_PLACE_ON, value -> value.rewrite(blockIdRewriter));
|
||||||
|
container.updateIfPresent(StructuredDataKey.CAN_BREAK, value -> value.rewrite(blockIdRewriter));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Look for item types
|
// Look for item types
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren