Remove a few magic metadata indexes

This commit is contained in:
TheMode 2021-06-14 21:49:16 +02:00
parent 80d0b8def6
commit 27f30fa394
2 changed files with 13 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package net.minestom.server.entity; package net.minestom.server.entity;
import net.minestom.server.entity.metadata.item.ItemEntityMeta;
import net.minestom.server.event.EventDispatcher; import net.minestom.server.event.EventDispatcher;
import net.minestom.server.event.entity.EntityItemMergeEvent; import net.minestom.server.event.entity.EntityItemMergeEvent;
import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Chunk;
@ -18,7 +19,7 @@ import java.util.Set;
/** /**
* Represents an item on the ground. * Represents an item on the ground.
*/ */
public class ItemEntity extends ObjectEntity { public class ItemEntity extends Entity {
/** /**
* Used to slow down the merge check delay * Used to slow down the merge check delay
@ -129,8 +130,8 @@ public class ItemEntity extends ObjectEntity {
} }
@Override @Override
public int getObjectData() { public @NotNull ItemEntityMeta getEntityMeta() {
return 1; return (ItemEntityMeta) super.getEntityMeta();
} }
/** /**
@ -150,7 +151,7 @@ public class ItemEntity extends ObjectEntity {
*/ */
public void setItemStack(@NotNull ItemStack itemStack) { public void setItemStack(@NotNull ItemStack itemStack) {
this.itemStack = itemStack; this.itemStack = itemStack;
this.metadata.setIndex((byte) 7, Metadata.Slot(itemStack)); getEntityMeta().setItem(itemStack);
} }
/** /**

View File

@ -29,6 +29,7 @@ import net.minestom.server.command.CommandSender;
import net.minestom.server.effects.Effects; import net.minestom.server.effects.Effects;
import net.minestom.server.entity.damage.DamageType; import net.minestom.server.entity.damage.DamageType;
import net.minestom.server.entity.fakeplayer.FakePlayer; import net.minestom.server.entity.fakeplayer.FakePlayer;
import net.minestom.server.entity.metadata.PlayerMeta;
import net.minestom.server.entity.vehicle.PlayerVehicleInformation; import net.minestom.server.entity.vehicle.PlayerVehicleInformation;
import net.minestom.server.event.EventDispatcher; import net.minestom.server.event.EventDispatcher;
import net.minestom.server.event.inventory.InventoryOpenEvent; import net.minestom.server.event.inventory.InventoryOpenEvent;
@ -1037,13 +1038,18 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
sendUpdateHealthPacket(); sendUpdateHealthPacket();
} }
@Override
public @NotNull PlayerMeta getEntityMeta() {
return (PlayerMeta) super.getEntityMeta();
}
/** /**
* Gets the player additional hearts. * Gets the player additional hearts.
* *
* @return the player additional hearts * @return the player additional hearts
*/ */
public float getAdditionalHearts() { public float getAdditionalHearts() {
return metadata.getIndex((byte) 14, 0f); return getEntityMeta().getAdditionalHearts();
} }
/** /**
@ -1052,7 +1058,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
* @param additionalHearts the count of additional hearts * @param additionalHearts the count of additional hearts
*/ */
public void setAdditionalHearts(float additionalHearts) { public void setAdditionalHearts(float additionalHearts) {
this.metadata.setIndex((byte) 14, Metadata.Float(additionalHearts)); getEntityMeta().setAdditionalHearts(additionalHearts);
} }
/** /**