3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

Better logic for item updating on item entities

Specifically created to address InteractionVisualizer updating all metadata properties when updating the nametag - this commit prevents the item from jumping on updating. It also prevents the entity from being respawned if just the stack size updated.
Dieser Commit ist enthalten in:
Camotoy 2021-07-22 09:16:19 -04:00
Ursprung c3f65b176d
Commit 11f048a065
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 7EEFB66FE798081F
2 geänderte Dateien mit 24 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -29,9 +29,11 @@ import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadat
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.data.entity.EntityEventType;
import com.nukkitx.protocol.bedrock.data.entity.EntityFlag;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.AddItemEntityPacket;
import com.nukkitx.protocol.bedrock.packet.EntityEventPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemTranslator;
@ -115,9 +117,26 @@ public class ItemEntity extends ThrowableEntity {
@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 8) {
item = ItemTranslator.translateToBedrock(session, (ItemStack) entityMetadata.getValue());
despawnEntity(session);
spawnEntity(session);
ItemData item = ItemTranslator.translateToBedrock(session, (ItemStack) entityMetadata.getValue());
if (this.item == null) {
this.item = item;
spawnEntity(session);
} else if (item.equals(this.item, false, true, true)) {
// Don't bother respawning the entity if items are equal
if (this.item.getCount() != item.getCount()) {
// Just item count updated; let's make this easy
this.item = item;
EntityEventPacket packet = new EntityEventPacket();
packet.setRuntimeEntityId(geyserId);
packet.setType(EntityEventType.UPDATE_ITEM_STACK_SIZE);
packet.setData(this.item.getCount());
session.sendUpstreamPacket(packet);
}
} else {
this.item = item;
despawnEntity(session);
spawnEntity(session);
}
}
super.updateBedrockMetadata(entityMetadata, session);

Datei anzeigen

@ -44,6 +44,7 @@ import org.geysermc.connector.registry.type.ItemMappings;
import org.geysermc.connector.utils.FileUtils;
import org.geysermc.connector.utils.LocaleUtils;
import javax.annotation.Nonnull;
import java.util.*;
import java.util.stream.Collectors;
@ -125,6 +126,7 @@ public abstract class ItemTranslator {
return itemStack;
}
@Nonnull
public static ItemData translateToBedrock(GeyserSession session, ItemStack stack) {
if (stack == null) {
return ItemData.AIR;