Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 00:00:33 +01:00
Make items in 1.20.5+ non null
Dieser Commit ist enthalten in:
Ursprung
f86fdd1eb4
Commit
2f5fbd93ea
@ -17,6 +17,10 @@
|
||||
*/
|
||||
package com.viaversion.viabackwards.api.rewriters;
|
||||
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viabackwards.api.BackwardsProtocol;
|
||||
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
|
||||
import com.viaversion.viabackwards.api.data.MappedItem;
|
||||
@ -28,10 +32,6 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.nbt.tag.CompoundTag;
|
||||
import com.viaversion.nbt.tag.IntTag;
|
||||
import com.viaversion.nbt.tag.NumberTag;
|
||||
import com.viaversion.nbt.tag.Tag;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
|
||||
@ -48,12 +48,12 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
public Item handleItemToClient(final UserConnection connection, final Item item) {
|
||||
if (item.isEmpty()) {
|
||||
return item;
|
||||
}
|
||||
|
||||
final StructuredDataContainer data = item.structuredData();
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
data.setIdLookup(protocol, true);
|
||||
|
||||
if (protocol.getMappingData().getEnchantmentMappings() != null) {
|
||||
@ -108,9 +108,9 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
return null;
|
||||
public Item handleItemToServer(final UserConnection connection, final Item item) {
|
||||
if (item.isEmpty()) {
|
||||
return item;
|
||||
}
|
||||
|
||||
final BackwardsMappingData mappingData = protocol.getMappingData();
|
||||
@ -118,7 +118,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
item.setIdentifier(mappingData.getOldItemId(item.identifier()));
|
||||
}
|
||||
|
||||
final StructuredDataContainer data = item.structuredData();
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
data.setIdLookup(protocol, false);
|
||||
|
||||
if (protocol.getMappingData().getEnchantmentMappings() != null) {
|
||||
@ -138,12 +138,12 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
}
|
||||
|
||||
protected @Nullable CompoundTag customTag(final Item item) {
|
||||
final StructuredData<CompoundTag> customData = item.structuredData().getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
final StructuredData<CompoundTag> customData = item.dataContainer().getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
return customData != null ? customData.value() : null;
|
||||
}
|
||||
|
||||
protected CompoundTag createCustomTag(final Item item) {
|
||||
final StructuredDataContainer data = item.structuredData();
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
final StructuredData<CompoundTag> customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
if (customData != null) {
|
||||
return customData.value();
|
||||
@ -156,7 +156,7 @@ public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S
|
||||
|
||||
@Override
|
||||
protected void restoreDisplayTag(final Item item) {
|
||||
final StructuredDataContainer data = item.structuredData();
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
final StructuredData<CompoundTag> customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
if (customData == null) {
|
||||
return;
|
||||
|
@ -47,13 +47,13 @@ public class StructuredEnchantmentRewriter {
|
||||
}
|
||||
|
||||
public void handleToClient(final Item item) {
|
||||
final StructuredDataContainer data = item.structuredData();
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.ENCHANTMENTS, false);
|
||||
rewriteEnchantmentsToClient(data, StructuredDataKey.STORED_ENCHANTMENTS, true);
|
||||
}
|
||||
|
||||
public void handleToServer(final Item item) {
|
||||
final StructuredDataContainer data = item.structuredData();
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
final StructuredData<CompoundTag> customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA);
|
||||
if (customData == null) {
|
||||
return;
|
||||
|
@ -30,6 +30,7 @@ import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer;
|
||||
import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.item.StructuredItem;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.Fireworks;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
@ -162,8 +163,11 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
final Item result = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.ITEM));
|
||||
wrapper.write(Types.ITEM1_20_2, result);
|
||||
|
||||
final Item secondInput = handleItemToClient(wrapper.user(), wrapper.read(Types1_20_5.OPTIONAL_ITEM_COST));
|
||||
Item secondInput = wrapper.read(Types1_20_5.OPTIONAL_ITEM_COST);
|
||||
if (secondInput != null) {
|
||||
secondInput = handleItemToClient(wrapper.user(), secondInput);
|
||||
cleanInput(secondInput);
|
||||
}
|
||||
wrapper.write(Types.ITEM1_20_2, secondInput);
|
||||
|
||||
wrapper.passthrough(Types.BOOLEAN); // Out of stock
|
||||
@ -319,13 +323,16 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) return null;
|
||||
public @Nullable Item handleItemToClient(final UserConnection connection, final Item item) {
|
||||
if (item.isEmpty()) {
|
||||
// Back to null for the older protocols
|
||||
return null;
|
||||
}
|
||||
|
||||
super.handleItemToClient(connection, item);
|
||||
|
||||
// In 1.20.6, some items have default values which are not written into the components
|
||||
final StructuredDataContainer data = item.structuredData();
|
||||
final StructuredDataContainer data = item.dataContainer();
|
||||
if (item.identifier() == 1105 && !data.contains(StructuredDataKey.FIREWORKS)) {
|
||||
data.set(StructuredDataKey.FIREWORKS, new Fireworks(1, new FireworkExplosion[0]));
|
||||
}
|
||||
@ -339,8 +346,11 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) return null;
|
||||
public Item handleItemToServer(final UserConnection connection, @Nullable final Item item) {
|
||||
if (item == null) {
|
||||
// Unify as empty going forward
|
||||
return StructuredItem.empty();
|
||||
}
|
||||
|
||||
// Convert to structured item first
|
||||
final Item structuredItem = vvProtocol.getItemRewriter().toStructuredItem(connection, item);
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren