Skip to content

Commit

Permalink
Fix Skull Meta
Browse files Browse the repository at this point in the history
  • Loading branch information
Ste3et committed Sep 17, 2024
1 parent e706b3d commit 30c98c3
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.Ste3et_C0st.FurnitureLib.Utilitis;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Objects;
import java.util.UUID;

Expand Down Expand Up @@ -52,16 +53,21 @@ public static ItemStack patch(ItemStack stack, NBTTagCompound compound) {
NBTTagCompound texturestring = textureCompound.get(0);
String base64String = texturestring.getString("Value");
WrappedGameProfile gameProfile = makeProfile(base64String);

try {
Field profileField = headMeta.getClass().getDeclaredField("profile");
profileField.setAccessible(true);
profileField.set(headMeta, gameProfile.getHandle());
} catch (NoSuchFieldException | SecurityException e) {
if(Class.forName("net.minecraft.world.item.component.ResolvableProfile") == null) {
Field profileField = headMeta.getClass().getDeclaredField("profile"); //1.21.1 -> ResolvableProfile | com.mojang.authlib.GameProfile
profileField.setAccessible(true);
profileField.set(headMeta, gameProfile.getHandle());
}else {
Object object = Class.forName("net.minecraft.world.item.component.ResolvableProfile").getConstructor(gameProfile.getHandleType()).newInstance(gameProfile.getHandle());
Method method = headMeta.getClass().getDeclaredMethod("setProfile", object.getClass());
method.setAccessible(true);
method.invoke(headMeta, object);
}

} catch (Exception e) {
e.printStackTrace();
} catch (IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
} finally {
} finally {
stack.setItemMeta(headMeta);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.entity.FallingBlock;
import org.bukkit.persistence.PersistentDataContainer;

import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
Expand Down Expand Up @@ -56,4 +57,9 @@ protected void readAdditionalSaveData(NBTTagCompound paramCompoundTag) {
protected void writeAdditionalSaveData() {
if(!this.blockDefaultKey.isDefault()) setMetadata("block_state", this.blockDefaultKey.getOrDefault().getAsString());
}

@Override
protected PacketContainer additionalData() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package de.Ste3et_C0st.FurnitureLib.main.entity;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.Vector3F;
import com.comphenix.protocol.wrappers.WrappedAttribute;
import com.comphenix.protocol.wrappers.WrappedAttributeModifier;
import com.comphenix.protocol.wrappers.WrappedAttributeModifier.Operation;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import com.google.common.collect.Lists;

import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound;
import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagList;
Expand All @@ -19,26 +26,27 @@
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Objects;
import java.util.Optional;

public class fArmorStand extends fContainerEntity implements SizeableEntity, Interactable{

public static EntityType type = EntityType.ARMOR_STAND;
private int armorstandID;

private DefaultKey<Boolean> arms = new DefaultKey<Boolean>(false), small = new DefaultKey<Boolean>(false), marker = new DefaultKey<Boolean>(true), basePlate = new DefaultKey<Boolean>(true);

private final PacketContainer attribute = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
private HashMap<BodyPart, DefaultKey<EulerAngle>> angle = new HashMap<Type.BodyPart, DefaultKey<EulerAngle>>();
private final DefaultKey<EntitySize> entitySize = new DefaultKey<EntitySize>(new EntitySize(0.5, 1.975));
protected WrappedAttribute.Builder scaleAttribute = WrappedAttribute.newBuilder().attributeKey("generic.scale").baseValue(0D);

@SuppressWarnings("deprecation")
public fArmorStand(Location loc, ObjectID obj) {
super(loc, type, FurnitureLib.isNewVersion() ? 1 : type.getTypeId(), obj);
this.attribute.getIntegers().write(0, this.getEntityID());
angle.put(BodyPart.BODY, new DefaultKey<EulerAngle>(BodyPart.BODY.getDefAngle()));
angle.put(BodyPart.HEAD, new DefaultKey<EulerAngle>(BodyPart.HEAD.getDefAngle()));
angle.put(BodyPart.LEFT_ARM, new DefaultKey<EulerAngle>(BodyPart.LEFT_ARM.getDefAngle()));
Expand Down Expand Up @@ -197,7 +205,9 @@ protected void writeAdditionalSaveData() {
if(!this.gravity.isDefault()) setMetadata("Gravity", this.hasGravity());
if(this.marker.isDefault()) setMetadata("Marker", this.marker.getOrDefault());
if(!this.small.isDefault()) setMetadata("Small", this.isSmall());

if(this.scaleAttribute.build().getBaseValue() != this.scaleAttribute.build().getFinalValue()) {
setMetadata("generic_aScale", this.scaleAttribute.build().getFinalValue());
}
NBTTagCompound eulerAngle = new NBTTagCompound();
this.angle.entrySet().stream().filter(entry -> !entry.getValue().isDefault()).forEach(entry -> {
EulerAngle angle = entry.getValue().getValue();
Expand All @@ -215,6 +225,7 @@ protected void writeAdditionalSaveData() {
@Override
protected void readAdditionalSaveData(NBTTagCompound metadata) {
super.readInventorySaveData(metadata);
this.setScale(metadata.getDouble("generic_aScale", 1d));
if(metadata.hasKeyOfType("EulerAngle", 10)) {
NBTTagCompound euler = metadata.getCompound("EulerAngle");
euler.c().stream().forEach(entry -> {
Expand Down Expand Up @@ -292,6 +303,8 @@ public boolean canInteractWith() {
return this.isMarker();
}

private void sendMetadata(Player player) {}

// public Optional<BoundingBox> getTipLocation(BodyPart bodyPart) {
// final Location entityLocation = this.getLocation().clone();
// entityLocation.setYaw(this.getLocation().getYaw() + 90);
Expand Down Expand Up @@ -345,4 +358,25 @@ public boolean canInteractWith() {
// y = v.getX() * sin + v.getY() * cos;
// return v.setX(x).setY(y);
// }


public void setScale(double scale) {
if(MinecraftVersion.getCurrentVersion().isAtLeast(new MinecraftVersion("1.19.5"))) {
scaleAttribute.modifiers(Arrays.asList(WrappedAttributeModifier.newBuilder().operation(Operation.ADD_NUMBER).amount(scale).build()));
}
}

public double getAttributeScale() {
return this.scaleAttribute.build().getFinalValue();
}

@Override
protected PacketContainer additionalData() {
if(getAttributeScale() != 0D) {
this.attribute.getAttributeCollectionModifier().write(0, Arrays.asList(this.scaleAttribute.build()));
}else {
this.attribute.getAttributeCollectionModifier().write(0, Lists.newArrayList());
}
return this.attribute;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.Ste3et_C0st.FurnitureLib.main.entity;

import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound;
Expand Down Expand Up @@ -64,4 +65,9 @@ public fCreeper copyEntity(Entity entity) {
}
return this;
}

@Override
protected PacketContainer additionalData() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.joml.Quaternionf;
import org.joml.Vector3f;

import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.utility.MinecraftVersion;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
Expand Down Expand Up @@ -370,4 +371,7 @@ public BoundingBox getBoundingBox() {
final Vector3f scale = this.getScale();
return BoundingBox.of(new Vector(0 , 0, 0), new Vector(scale.x, scale.y, scale.z));
}

@Override
protected PacketContainer additionalData() {return null;}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public abstract class fEntity extends fSerializer implements Cloneable{
private final UUID entityUUID = UUID.randomUUID();
private final PacketContainer mountPacketContainer = new PacketContainer(PacketType.Play.Server.MOUNT);
private final PacketContainer destroy = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
private final PacketContainer attribute = new PacketContainer(PacketType.Play.Server.UPDATE_ATTRIBUTES);
private static final BiFunction<PacketContainer, List<WrappedWatchableObject>, Void> metadataFunction;

@Deprecated
Expand All @@ -61,7 +60,6 @@ public abstract class fEntity extends fSerializer implements Cloneable{
private Location location;
private DefaultKey<String> customName = new DefaultKey<String>("");
private NBTTagCompound customNBT = new NBTTagCompound();
protected WrappedAttribute.Builder scaleAttribute = WrappedAttribute.newBuilder().attributeKey("generic.scale").baseValue(1D);
protected DefaultKey<Boolean> fire = new DefaultKey<Boolean>(false), nameVisible = new DefaultKey<Boolean>(false), isPlayed = new DefaultKey<Boolean>(false);
protected DefaultKey<Boolean> glowing = new DefaultKey<Boolean>(false), invisible = new DefaultKey<Boolean>(false), gravity = new DefaultKey<Boolean>(false);
//protected DefaultKey<BoundingBox> boundingBox = new DefaultKey<BoundingBox>(new BoundingBox(0, 0, 0, 0, 0, 0));
Expand Down Expand Up @@ -96,8 +94,6 @@ public fEntity(Location loc, EntityType type, int entityID, ObjectID id) {
if(FurnitureLib.getVersionInt() > 18) getHandle().getEntityTypeModifier().writeSafely(0, type);
getHandle().getUUIDs().write(0, this.entityUUID);
this.mountPacketContainer.getIntegers().write(0, this.entityID);
this.attribute.getIntegers().write(0, this.entityID);
this.attribute.getIntegers().write(1, 1);
setLocation(loc);
}

Expand Down Expand Up @@ -360,18 +356,20 @@ public void send(Player player) {
getManager().sendServerPacket(player, getHandle());
this.sendMetadata(player);
if(getPassenger().isEmpty() == false) getManager().sendServerPacket(player, this.mountPacketContainer);
getManager().sendServerPacket(player, this.attribute);
} catch (Exception e) {
e.printStackTrace();
}
}


protected abstract PacketContainer additionalData();

private void sendMetadata(Player player) {
PacketContainer update = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
update.getIntegers().write(0, getEntityID());
metadataFunction.apply(update, getWatcher().getWatchableObjects());
try {
getManager().sendServerPacket(player, update);
if(additionalData() != null) getManager().sendServerPacket(player, additionalData());
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -490,8 +488,7 @@ public void loadMetadata(NBTTagCompound metadata) {
this.setFire((metadata.getInt("Fire") == 1)); //Present in monjang
this.setGlowing((metadata.getInt("Glowing") == 1)); //Present in monjang
this.setInvisible((metadata.getInt("Invisible") == 1)); //Present in monjang
this.setScale(metadata.getDouble("generic_aScale", 1d));


metadata.getCompound("Rotation", NBTTagList.class, list -> {
Location location = getLocation();
location.setYaw(list.getFloat(0, location.getYaw()));
Expand All @@ -514,9 +511,6 @@ public NBTTagCompound getMetaData() {
if(!this.glowing.isDefault()) setMetadata("Glowing", this.isGlowing());
if(!this.invisible.isDefault()) setMetadata("Invisible", this.isInvisible());
if(!this.getCustomNBT().isEmpty()) setMetadata("customnbt", getCustomNBT());
if(this.scaleAttribute.build().getBaseValue() != this.scaleAttribute.build().getFinalValue()) {
setMetadata("generic_aScale", this.scaleAttribute.build().getFinalValue());
}
setMetadata(this.getLocation());
writeAdditionalSaveData();
return this.getNBTField();
Expand Down Expand Up @@ -548,15 +542,4 @@ public void copyMetadata(fEntity toCopy) {
public NBTTagCompound getCustomNBT() {
return customNBT;
}

public void setScale(double scale) {
if(MinecraftVersion.getCurrentVersion().isAtLeast(new MinecraftVersion("1.19.5"))) {
scaleAttribute.modifiers(Arrays.asList(WrappedAttributeModifier.newBuilder().operation(Operation.ADD_NUMBER).amount(scale).build()));
this.attribute.getAttributeCollectionModifier().write(0, Arrays.asList(this.scaleAttribute.build()));
}
}

public double getAttributeScale() {
return this.scaleAttribute.build().getFinalValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ protected void readAdditionalSaveData(NBTTagCompound paramCompoundTag) {}

@Override
protected void writeAdditionalSaveData() {}

@Override
protected PacketContainer additionalData() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.bukkit.entity.Interaction;
import org.bukkit.util.Vector;

import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound;
Expand Down Expand Up @@ -86,4 +87,9 @@ public BoundingBox getBoundingBox() {
final double width = getWidth() / 2;
return BoundingBox.of(new Vector(-width, 0,-width), new Vector(width, getHeight(), width));
}

@Override
protected PacketContainer additionalData() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.Ste3et_C0st.FurnitureLib.main.entity;

import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
import de.Ste3et_C0st.FurnitureLib.NBT.NBTTagCompound;
Expand Down Expand Up @@ -52,4 +53,9 @@ protected void readAdditionalSaveData(NBTTagCompound paramCompoundTag) {
protected void writeAdditionalSaveData() {
setMetadata("Saddle", saddle);
}

@Override
protected PacketContainer additionalData() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bukkit.entity.TextDisplay;
import org.bukkit.entity.TextDisplay.TextAlignment;

import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
rootProject.name = 'FurnitureLib'
include(':FurnitureLib-Core', ':FurnitureLib-Paper', ':FurnitureLib-Folia')

gradle.ext.furnitureLibVersion = '3.2.2'
gradle.ext.furnitureLibVersion = '3.2.3'
gradle.ext.minecraftVersion = '1.20.6-R0.1-SNAPSHOT'

0 comments on commit 30c98c3

Please sign in to comment.