Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Fix up block state handling, add PotDecorations wrapper
Dieser Commit ist enthalten in:
Ursprung
57a589924d
Commit
4255876c22
@ -40,6 +40,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion;
|
|||||||
import com.viaversion.viaversion.api.minecraft.item.data.Fireworks;
|
import com.viaversion.viaversion.api.minecraft.item.data.Fireworks;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.Instrument;
|
import com.viaversion.viaversion.api.minecraft.item.data.Instrument;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker;
|
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.PotDecorations;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.PotionContents;
|
import com.viaversion.viaversion.api.minecraft.item.data.PotionContents;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.SuspiciousStewEffect;
|
import com.viaversion.viaversion.api.minecraft.item.data.SuspiciousStewEffect;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.Unbreakable;
|
import com.viaversion.viaversion.api.minecraft.item.data.Unbreakable;
|
||||||
@ -91,7 +92,7 @@ public final class StructuredDataKey<T> {
|
|||||||
public static final StructuredDataKey<String> NOTE_BLOCK_SOUND = new StructuredDataKey<>("note_block_sound", Type.STRING);
|
public static final StructuredDataKey<String> NOTE_BLOCK_SOUND = new StructuredDataKey<>("note_block_sound", Type.STRING);
|
||||||
public static final StructuredDataKey<BannerPatternLayer[]> BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPatternLayer.ARRAY_TYPE);
|
public static final StructuredDataKey<BannerPatternLayer[]> BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPatternLayer.ARRAY_TYPE);
|
||||||
public static final StructuredDataKey<Integer> BASE_COLOR = new StructuredDataKey<>("base_color", Type.VAR_INT);
|
public static final StructuredDataKey<Integer> BASE_COLOR = new StructuredDataKey<>("base_color", Type.VAR_INT);
|
||||||
public static final StructuredDataKey<int[]> POT_DECORATIONS = new StructuredDataKey<>("pot_decorations", Type.VAR_INT_ARRAY_PRIMITIVE);
|
public static final StructuredDataKey<PotDecorations> POT_DECORATIONS = new StructuredDataKey<>("pot_decorations", PotDecorations.TYPE);
|
||||||
public static final StructuredDataKey<Item[]> CONTAINER = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY);
|
public static final StructuredDataKey<Item[]> CONTAINER = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY);
|
||||||
public static final StructuredDataKey<BlockStateProperties> BLOCK_STATE = new StructuredDataKey<>("block_state", BlockStateProperties.TYPE);
|
public static final StructuredDataKey<BlockStateProperties> BLOCK_STATE = new StructuredDataKey<>("block_state", BlockStateProperties.TYPE);
|
||||||
public static final StructuredDataKey<Bee[]> BEES = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE);
|
public static final StructuredDataKey<Bee[]> BEES = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE);
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||||
|
* Copyright (C) 2016-2024 ViaVersion and contributors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
*/
|
||||||
|
package com.viaversion.viaversion.api.minecraft.item.data;
|
||||||
|
|
||||||
|
import com.viaversion.viaversion.api.type.Type;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public final class PotDecorations {
|
||||||
|
|
||||||
|
public static final Type<PotDecorations> TYPE = new Type<PotDecorations>(PotDecorations.class) {
|
||||||
|
@Override
|
||||||
|
public PotDecorations read(final ByteBuf buffer) throws Exception {
|
||||||
|
return new PotDecorations(Type.VAR_INT_ARRAY_PRIMITIVE.read(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(final ByteBuf buffer, final PotDecorations value) throws Exception {
|
||||||
|
Type.VAR_INT_ARRAY_PRIMITIVE.write(buffer, value.itemIds());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private final int[] itemIds;
|
||||||
|
|
||||||
|
public PotDecorations(final int[] itemIds) {
|
||||||
|
this.itemIds = itemIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PotDecorations(final int backItem, final int leftItem, final int rightItem, final int frontItem) {
|
||||||
|
this.itemIds = new int[]{backItem, leftItem, rightItem, frontItem};
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] itemIds() {
|
||||||
|
return itemIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int backItem() {
|
||||||
|
return item(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int leftItem() {
|
||||||
|
return item(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int rightItem() {
|
||||||
|
return item(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int frontItem() {
|
||||||
|
return item(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int item(final int index) {
|
||||||
|
return index < 0 || index >= itemIds.length ? -1 : itemIds[index];
|
||||||
|
}
|
||||||
|
}
|
@ -56,6 +56,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion;
|
|||||||
import com.viaversion.viaversion.api.minecraft.item.data.Fireworks;
|
import com.viaversion.viaversion.api.minecraft.item.data.Fireworks;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker;
|
import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.ModifierData;
|
import com.viaversion.viaversion.api.minecraft.item.data.ModifierData;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.item.data.PotDecorations;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.PotionContents;
|
import com.viaversion.viaversion.api.minecraft.item.data.PotionContents;
|
||||||
import com.viaversion.viaversion.api.minecraft.item.data.PotionEffect;
|
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.PotionEffectData;
|
||||||
@ -90,6 +91,8 @@ import com.viaversion.viaversion.util.Either;
|
|||||||
import com.viaversion.viaversion.util.Key;
|
import com.viaversion.viaversion.util.Key;
|
||||||
import com.viaversion.viaversion.util.UUIDUtil;
|
import com.viaversion.viaversion.util.UUIDUtil;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -97,8 +100,6 @@ import java.util.Map;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPacket1_20_3, ServerboundPacket1_20_5, Protocol1_20_5To1_20_3> {
|
public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<ClientboundPacket1_20_3, ServerboundPacket1_20_5, Protocol1_20_5To1_20_3> {
|
||||||
@ -683,12 +684,11 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
private void updateBlockState(final StructuredDataContainer data, final CompoundTag blockState) {
|
private void updateBlockState(final StructuredDataContainer data, final CompoundTag blockState) {
|
||||||
final Map<String, String> properties = new HashMap<>();
|
final Map<String, String> properties = new HashMap<>();
|
||||||
for (final Map.Entry<String, Tag> entry : blockState.entrySet()) {
|
for (final Map.Entry<String, Tag> entry : blockState.entrySet()) {
|
||||||
// It's all strings now because ???
|
// Only String and IntTags are valid
|
||||||
final Tag value = entry.getValue();
|
final Tag value = entry.getValue();
|
||||||
if (value instanceof StringTag) {
|
if (value instanceof StringTag) {
|
||||||
properties.put(entry.getKey(), ((StringTag) value).getValue());
|
properties.put(entry.getKey(), ((StringTag) value).getValue());
|
||||||
} else if (value instanceof NumberTag) {
|
} else if (value instanceof IntTag) {
|
||||||
// TODO Boolean values
|
|
||||||
properties.put(entry.getKey(), Integer.toString(((NumberTag) value).asInt()));
|
properties.put(entry.getKey(), Integer.toString(((NumberTag) value).asInt()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -989,12 +989,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
|||||||
|
|
||||||
final ListTag<StringTag> sherdsTag = tag.getListTag("sherds", StringTag.class);
|
final ListTag<StringTag> sherdsTag = tag.getListTag("sherds", StringTag.class);
|
||||||
if (sherdsTag != null && sherdsTag.size() == 4) {
|
if (sherdsTag != null && sherdsTag.size() == 4) {
|
||||||
final String sherd1 = sherdsTag.get(0).getValue();
|
final String backSherd = sherdsTag.get(0).getValue();
|
||||||
final String sherd2 = sherdsTag.get(1).getValue();
|
final String leftSherd = sherdsTag.get(1).getValue();
|
||||||
final String sherd3 = sherdsTag.get(2).getValue();
|
final String rightSherd = sherdsTag.get(2).getValue();
|
||||||
final String sherd4 = sherdsTag.get(3).getValue();
|
final String frontSherd = sherdsTag.get(3).getValue();
|
||||||
|
|
||||||
data.set(StructuredDataKey.POT_DECORATIONS, new int[]{toItemId(sherd1), toItemId(sherd2), toItemId(sherd3), toItemId(sherd4)});
|
data.set(StructuredDataKey.POT_DECORATIONS, new PotDecorations(toItemId(backSherd), toItemId(leftSherd), toItemId(rightSherd), toItemId(frontSherd)));
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringTag noteBlockSoundTag = tag.getStringTag("note_block_sound");
|
final StringTag noteBlockSoundTag = tag.getStringTag("note_block_sound");
|
||||||
|
@ -23,6 +23,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
|||||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
import com.viaversion.viaversion.api.minecraft.GameProfile;
|
||||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||||
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
import com.viaversion.viaversion.api.minecraft.data.StructuredData;
|
||||||
@ -253,7 +254,7 @@ final class StructuredDataConverter {
|
|||||||
register(StructuredDataKey.NOTE_BLOCK_SOUND, (data, tag) -> getBlockEntityTag(tag).putString("note_block_sound", data));
|
register(StructuredDataKey.NOTE_BLOCK_SOUND, (data, tag) -> getBlockEntityTag(tag).putString("note_block_sound", data));
|
||||||
register(StructuredDataKey.POT_DECORATIONS, (data, tag) -> {
|
register(StructuredDataKey.POT_DECORATIONS, (data, tag) -> {
|
||||||
final ListTag<StringTag> sherds = new ListTag<>(StringTag.class);
|
final ListTag<StringTag> sherds = new ListTag<>(StringTag.class);
|
||||||
for (final int id : data) {
|
for (final int id : data.itemIds()) {
|
||||||
final int oldId = Protocol1_20_5To1_20_3.MAPPINGS.getOldItemId(id);
|
final int oldId = Protocol1_20_5To1_20_3.MAPPINGS.getOldItemId(id);
|
||||||
sherds.add(new StringTag(Protocol1_20_5To1_20_3.MAPPINGS.itemName(oldId)));
|
sherds.add(new StringTag(Protocol1_20_5To1_20_3.MAPPINGS.itemName(oldId)));
|
||||||
}
|
}
|
||||||
@ -403,10 +404,16 @@ final class StructuredDataConverter {
|
|||||||
putHideFlag(tag, HIDE_ARMOR_TRIM);
|
putHideFlag(tag, HIDE_ARMOR_TRIM);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
register(StructuredDataKey.BLOCK_STATE, ((data, tag) -> {
|
||||||
//TODO
|
final CompoundTag blockStateTag = new CompoundTag();
|
||||||
// StructuredDataKey<BlockStateProperties> BLOCK_STATE
|
tag.put("BlockStateTag", blockStateTag);
|
||||||
// StructuredDataKey<Unit> INTANGIBLE_PROJECTILE
|
for (final Map.Entry<String, String> entry : data.properties().entrySet()) {
|
||||||
|
blockStateTag.putString(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
register(StructuredDataKey.INTANGIBLE_PROJECTILE, (data, tag) -> {
|
||||||
|
// Nothing
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toItemName(final int id) {
|
private static String toItemName(final int id) {
|
||||||
@ -535,10 +542,9 @@ final class StructuredDataConverter {
|
|||||||
|
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
final DataConverter<T> converter = (DataConverter<T>) REWRITERS.get(data.key());
|
final DataConverter<T> converter = (DataConverter<T>) REWRITERS.get(data.key());
|
||||||
if (converter != null) {
|
Preconditions.checkNotNull(converter, "No converter for %s found", data.key());
|
||||||
converter.convert(data.value(), tag);
|
converter.convert(data.value(), tag);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static <T> void register(final StructuredDataKey<T> key, final DataConverter<T> converter) {
|
private static <T> void register(final StructuredDataKey<T> key, final DataConverter<T> converter) {
|
||||||
REWRITERS.put(key, converter);
|
REWRITERS.put(key, converter);
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren