mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 08:57:39 +01:00
Rewrite block predicates the other way around as well
This commit is contained in:
parent
93f081dd84
commit
7d41706026
@ -445,9 +445,16 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
}
|
||||
|
||||
final String identifier = rawPredicate.substring(0, idLength);
|
||||
final int id = Protocol1_20_5To1_20_3.MAPPINGS.blockId(identifier);
|
||||
if (id == -1) {
|
||||
return null;
|
||||
final HolderSet holders;
|
||||
if (identifier.startsWith("#")) {
|
||||
final int id = Protocol1_20_5To1_20_3.MAPPINGS.blockId(identifier);
|
||||
if (id == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
holders = new HolderSet(new int[]{Protocol1_20_5To1_20_3.MAPPINGS.getNewBlockId(id)});
|
||||
} else {
|
||||
holders = new HolderSet(identifier);
|
||||
}
|
||||
|
||||
final int propertiesEndIndex = rawPredicate.indexOf(']');
|
||||
@ -478,7 +485,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
}
|
||||
|
||||
return new BlockPredicate(
|
||||
new HolderSet(new int[]{Protocol1_20_5To1_20_3.MAPPINGS.getNewBlockId(id)}),
|
||||
holders,
|
||||
propertyMatchers.isEmpty() ? null : propertyMatchers.toArray(EMPTY_PROPERTY_MATCHERS),
|
||||
tag
|
||||
);
|
||||
|
@ -23,18 +23,22 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.AdventureModePredicate;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifier;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Bee;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.BlockPredicate;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Enchantments;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FilterableComponent;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FilterableString;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.PotionEffect;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.PotionEffectData;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.StatePropertyMatcher;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.SuspiciousStewEffect;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_2to1_20.util.PotionEffects;
|
||||
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3;
|
||||
@ -332,17 +336,60 @@ final class StructuredDataConverter {
|
||||
patternsTag.add(patternTag);
|
||||
}
|
||||
});
|
||||
//register(StructuredDataKey., (data, tag) -> );
|
||||
register(StructuredDataKey.CAN_PLACE_ON, (data, tag) -> convertBlockPredicates(tag, data, "CanPlaceOn", HIDE_CAN_PLACE_ON));
|
||||
register(StructuredDataKey.CAN_BREAK, (data, tag) -> convertBlockPredicates(tag, data, "CanDestroy", HIDE_CAN_DESTROY));
|
||||
|
||||
//TODO
|
||||
// StructuredDataKey.CAN_PLACE_ON
|
||||
// StructuredDataKey.CAN_BREAK
|
||||
// StructuredDataKey<ArmorTrim> TRIM
|
||||
// StructuredDataKey<BlockStateProperties> BLOCK_STATE
|
||||
// StructuredDataKey<Item[]> CONTAINER
|
||||
// StructuredDataKey<Unit> INTANGIBLE_PROJECTILE
|
||||
}
|
||||
|
||||
private static void convertBlockPredicates(final CompoundTag tag, final AdventureModePredicate data, final String key, final int hideFlag) {
|
||||
final ListTag<StringTag> predicatedListTag = new ListTag<>(StringTag.class);
|
||||
for (final BlockPredicate predicate : data.predicates()) {
|
||||
final HolderSet holders = predicate.predicates();
|
||||
if (holders == null) {
|
||||
// Can't do (nicely)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (holders.isLeft()) {
|
||||
final String identifier = holders.left();
|
||||
predicatedListTag.add(serializeBlockPredicate(predicate, identifier));
|
||||
} else {
|
||||
for (final int id : holders.right()) {
|
||||
final int oldId = Protocol1_20_5To1_20_3.MAPPINGS.getOldItemId(id);
|
||||
final String identifier = Protocol1_20_5To1_20_3.MAPPINGS.itemName(oldId);
|
||||
predicatedListTag.add(serializeBlockPredicate(predicate, identifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tag.put(key, predicatedListTag);
|
||||
if (!data.showInTooltip()) {
|
||||
putHideFlag(tag, hideFlag);
|
||||
}
|
||||
}
|
||||
|
||||
private static StringTag serializeBlockPredicate(final BlockPredicate predicate, final String identifier) {
|
||||
final StringBuilder builder = new StringBuilder(identifier);
|
||||
if (predicate.propertyMatchers() != null) {
|
||||
for (final StatePropertyMatcher matcher : predicate.propertyMatchers()) {
|
||||
// I'm not sure if ranged values were possible in 1.20.4 (if so, there's no trace of how)
|
||||
if (matcher.matcher().isLeft()) {
|
||||
builder.append(matcher.name()).append('=');
|
||||
builder.append(matcher.matcher().left());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (predicate.tag() != null) {
|
||||
builder.append(predicate.tag());
|
||||
}
|
||||
return new StringTag(builder.toString());
|
||||
}
|
||||
|
||||
private static CompoundTag getBlockEntityTag(final CompoundTag tag) {
|
||||
CompoundTag subTag = tag.getCompoundTag("BlockEntityTag");
|
||||
if (subTag == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user