Handle empty items in some thrown projectiles

Fixes #3909, #3910
This commit is contained in:
Nassim Jahnke 2024-06-07 12:24:02 +02:00
parent d43ad37663
commit 5053d739c0
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
3 changed files with 16 additions and 3 deletions

View File

@ -82,7 +82,7 @@ public class ItemType1_20_5 extends Type<Item> {
@Override
public void write(final ByteBuf buffer, @Nullable final Item object) {
if (object == null || object.identifier() == 0 || object.amount() <= 0) {
if (object == null || object.isEmpty()) {
Types.VAR_INT.writePrimitive(buffer, 0);
return;
}

View File

@ -28,8 +28,8 @@ import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
@ -46,6 +46,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundCon
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.AcknowledgedMessagesStorage;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.rewriter.entitydata.EntityDataHandler;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.TagUtil;
import it.unimi.dsi.fastutil.ints.IntArraySet;
@ -481,6 +482,18 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
meta.setValue(withAlpha(color));
}
});
final EntityDataHandler emptyItemHandler = (event, data) -> {
final Item item = data.value();
if (item == null || item.isEmpty()) {
// The item is used for particles or projectile display and can no longer be empty
event.cancel();
}
};
filter().type(EntityTypes1_20_5.EGG).index(8).handler(emptyItemHandler);
filter().type(EntityTypes1_20_5.SNOWBALL).index(8).handler(emptyItemHandler);
filter().type(EntityTypes1_20_5.ENDER_PEARL).index(8).handler(emptyItemHandler);
filter().type(EntityTypes1_20_5.EXPERIENCE_BOTTLE).index(8).handler(emptyItemHandler);
}
private void addColor(@Nullable final EntityData particleMeta, final int color) {

View File

@ -513,7 +513,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
final Map<String, DimensionData> dimensionDataMap = new HashMap<>(entries.length);
for (int i = 0; i < entries.length; i++) {
final RegistryEntry entry = entries[i];
dimensionDataMap.put(entry.key(), new DimensionDataImpl(i, (CompoundTag) entry.tag()));
dimensionDataMap.put(Key.stripMinecraftNamespace(entry.key()), new DimensionDataImpl(i, (CompoundTag) entry.tag()));
}
tracker(wrapper.user()).setDimensions(dimensionDataMap);
}