Skip to content

Commit

Permalink
Fix item spawning up (GeyserMC#2278)
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 authored Jun 16, 2021
1 parent 569c366 commit 3c9f628
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
import com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.data.inventory.ItemData;
import com.nukkitx.protocol.bedrock.packet.AddItemEntityPacket;
import org.geysermc.connector.entity.type.EntityType;
import org.geysermc.connector.network.session.GeyserSession;
import org.geysermc.connector.network.translators.item.ItemTranslator;

public class ItemEntity extends Entity {

protected ItemData item;

public ItemEntity(long entityId, long geyserId, EntityType entityType, Vector3f position, Vector3f motion, Vector3f rotation) {
super(entityId, geyserId, entityType, position.add(0d, entityType.getOffset(), 0d), motion, rotation);
}
Expand All @@ -52,18 +55,28 @@ public void moveAbsolute(GeyserSession session, Vector3f position, Vector3f rota
super.moveAbsolute(session, position.add(0d, this.entityType.getOffset(), 0d), rotation, isOnGround, teleported);
}

@Override
public void spawnEntity(GeyserSession session) {
if (item == null) {
return;
}
valid = true;
AddItemEntityPacket itemPacket = new AddItemEntityPacket();
itemPacket.setRuntimeEntityId(geyserId);
itemPacket.setPosition(position.add(0d, this.entityType.getOffset(), 0d));
itemPacket.setMotion(motion);
itemPacket.setUniqueEntityId(geyserId);
itemPacket.setFromFishing(false);
itemPacket.setItemInHand(item);
session.sendUpstreamPacket(itemPacket);
}

@Override
public void updateBedrockMetadata(EntityMetadata entityMetadata, GeyserSession session) {
if (entityMetadata.getId() == 8) {
AddItemEntityPacket itemPacket = new AddItemEntityPacket();
itemPacket.setRuntimeEntityId(geyserId);
itemPacket.setPosition(position.add(0d, this.entityType.getOffset(), 0d));
itemPacket.setMotion(motion);
itemPacket.setUniqueEntityId(geyserId);
itemPacket.setFromFishing(false);
itemPacket.getMetadata().putAll(metadata);
itemPacket.setItemInHand(ItemTranslator.translateToBedrock(session, (ItemStack) entityMetadata.getValue()));
session.sendUpstreamPacket(itemPacket);
item = ItemTranslator.translateToBedrock(session, (ItemStack) entityMetadata.getValue());
despawnEntity(session);
spawnEntity(session);
}

super.updateBedrockMetadata(entityMetadata, session);
Expand Down

0 comments on commit 3c9f628

Please sign in to comment.