Skip to content

Commit

Permalink
Add FS_ItemDisplay
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Aug 3, 2024
1 parent 9d0817f commit a8fb6e3
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package de.oliver.fancysitula.api.entities;

import de.oliver.fancysitula.api.packets.FS_ClientboundSetEntityDataPacket;
import de.oliver.fancysitula.api.utils.entityData.FS_ItemDisplayData;
import org.bukkit.entity.EntityType;

import java.util.List;

public class FS_ItemDisplay extends FS_Display {

protected FS_ClientboundSetEntityDataPacket.EntityData itemData = new FS_ClientboundSetEntityDataPacket.EntityData(FS_ItemDisplayData.ITEM, null);

public FS_ItemDisplay() {
super(EntityType.ITEM_DISPLAY);
}

public org.bukkit.inventory.ItemStack getItem() {
return (org.bukkit.inventory.ItemStack) this.itemData.getValue();
}

public void setItem(org.bukkit.inventory.ItemStack item) {
this.itemData.setValue(item);
}

@Override
public List<FS_ClientboundSetEntityDataPacket.EntityData> getEntityData() {
List<FS_ClientboundSetEntityDataPacket.EntityData> entityData = super.getEntityData();
entityData.add(this.itemData);
return entityData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package de.oliver.fancysitula.api.utils.entityData;

import de.oliver.fancysitula.api.packets.FS_ClientboundSetEntityDataPacket;

public class FS_ItemDisplayData {

/**
* Use {@link org.bukkit.inventory.ItemStack} as value
*/
public static final FS_ClientboundSetEntityDataPacket.EntityDataAccessor ITEM = new FS_ClientboundSetEntityDataPacket.EntityDataAccessor("net.minecraft.world.entity.Display$ItemDisplay", "DATA_ITEM_STACK_ID");

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.server.level.ServerPlayer;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -37,6 +38,10 @@ public Object createPacket() {
vanillaValue = PaperAdventure.asVanilla(c);
}

if (data.getValue() instanceof ItemStack i) {
vanillaValue = net.minecraft.world.item.ItemStack.fromBukkitCopy(i);
}

dataValues.add(SynchedEntityData.DataValue.create(accessor, vanillaValue));
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.oliver.fancysitula.commands;

import de.oliver.fancysitula.api.entities.FS_ItemDisplay;
import de.oliver.fancysitula.api.entities.FS_RealPlayer;
import de.oliver.fancysitula.api.entities.FS_TextDisplay;
import de.oliver.fancysitula.api.packets.FS_ClientboundPlayerInfoUpdatePacket;
import de.oliver.fancysitula.api.utils.FS_GameProfile;
import de.oliver.fancysitula.api.utils.FS_GameType;
Expand Down Expand Up @@ -33,14 +33,20 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String s, @NotNul
// Wrap the real player into an FS_Player instance
FS_RealPlayer fsPlayer = new FS_RealPlayer(p);

FS_TextDisplay fakeTextDisplay = new FS_TextDisplay();
fakeTextDisplay.setBillboardRenderConstraints((byte) 3);
fakeTextDisplay.setScale(new Vector3f(5f));
fakeTextDisplay.setLocation(p.getLocation());
fakeTextDisplay.setText(Component.text("Hello, World!"));
fakeTextDisplay.setBackground(0xFF00C8FF);
// FS_TextDisplay fakeTextDisplay = new FS_TextDisplay();
// fakeTextDisplay.setBillboardRenderConstraints((byte) 3);
// fakeTextDisplay.setScale(new Vector3f(5f));
// fakeTextDisplay.setLocation(p.getLocation());
// fakeTextDisplay.setText(Component.text("Hello, World!"));
// fakeTextDisplay.setBackground(0xFF00C8FF);
// FancySitula.ENTITY_FACTORY.spawnEntityFor(fsPlayer, fakeTextDisplay);

FancySitula.ENTITY_FACTORY.spawnEntityFor(fsPlayer, fakeTextDisplay);
FS_ItemDisplay fakeItemDisplay = new FS_ItemDisplay();
fakeItemDisplay.setBillboardRenderConstraints((byte) 3);
fakeItemDisplay.setScale(new Vector3f(5f));
fakeItemDisplay.setLocation(p.getLocation());
fakeItemDisplay.setItem(p.getInventory().getItemInMainHand());
FancySitula.ENTITY_FACTORY.spawnEntityFor(fsPlayer, fakeItemDisplay);

return true;
}
Expand Down

0 comments on commit a8fb6e3

Please sign in to comment.