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