mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Added CompassMeta & WIP CrossbowMeta
This commit is contained in:
parent
af14d2d324
commit
fe73c43eef
@ -5,10 +5,7 @@ import net.minestom.server.chat.ColoredText;
|
||||
import net.minestom.server.data.Data;
|
||||
import net.minestom.server.data.DataContainer;
|
||||
import net.minestom.server.item.attribute.ItemAttribute;
|
||||
import net.minestom.server.item.metadata.EnchantedBookMeta;
|
||||
import net.minestom.server.item.metadata.ItemMeta;
|
||||
import net.minestom.server.item.metadata.MapMeta;
|
||||
import net.minestom.server.item.metadata.PotionMeta;
|
||||
import net.minestom.server.item.metadata.*;
|
||||
import net.minestom.server.item.rule.VanillaStackingRule;
|
||||
import net.minestom.server.registry.Registries;
|
||||
import net.minestom.server.utils.NBTUtils;
|
||||
@ -580,10 +577,16 @@ public class ItemStack implements DataContainer {
|
||||
|
||||
if (material == Material.FILLED_MAP)
|
||||
return new MapMeta();
|
||||
|
||||
|
||||
if (material == Material.COMPASS)
|
||||
return new CompassMeta();
|
||||
|
||||
if (material == Material.ENCHANTED_BOOK)
|
||||
return new EnchantedBookMeta();
|
||||
|
||||
if (material == Material.CROSSBOW)
|
||||
return new CrossbowMeta();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
108
src/main/java/net/minestom/server/item/metadata/CompassMeta.java
Normal file
108
src/main/java/net/minestom/server/item/metadata/CompassMeta.java
Normal file
@ -0,0 +1,108 @@
|
||||
package net.minestom.server.item.metadata;
|
||||
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
public class CompassMeta implements ItemMeta {
|
||||
|
||||
private boolean lodestoneTracked;
|
||||
private String lodestoneDimension;
|
||||
private int x, y, z;
|
||||
|
||||
public boolean isLodestoneTracked() {
|
||||
return lodestoneTracked;
|
||||
}
|
||||
|
||||
public void setLodestoneTracked(boolean lodestoneTracked) {
|
||||
this.lodestoneTracked = lodestoneTracked;
|
||||
}
|
||||
|
||||
public String getLodestoneDimension() {
|
||||
return lodestoneDimension;
|
||||
}
|
||||
|
||||
public void setLodestoneDimension(String lodestoneDimension) {
|
||||
this.lodestoneDimension = lodestoneDimension;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(int z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbt() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSimilar(ItemMeta itemMeta) {
|
||||
if (!(itemMeta instanceof CompassMeta))
|
||||
return false;
|
||||
CompassMeta compassMeta = (CompassMeta) itemMeta;
|
||||
return (compassMeta.lodestoneTracked == lodestoneTracked) &&
|
||||
(compassMeta.lodestoneDimension.equals(lodestoneDimension)) &&
|
||||
(compassMeta.x == x && compassMeta.y == y && compassMeta.z == z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NBTCompound compound) {
|
||||
if (compound.containsKey("LodestoneTracked")) {
|
||||
this.lodestoneTracked = compound.getByte("LodestoneTracked") == 1;
|
||||
// TODO get boolean
|
||||
}
|
||||
if (compound.containsKey("LodestoneDimension")) {
|
||||
this.lodestoneDimension = compound.getString("LodestoneDimension");
|
||||
}
|
||||
if (compound.containsKey("LodestonePos")) {
|
||||
final NBTCompound posCompound = compound.getCompound("LodestonePos");
|
||||
this.x = posCompound.getInt("X");
|
||||
this.y = posCompound.getInt("Y");
|
||||
this.z = posCompound.getInt("Z");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(NBTCompound compound) {
|
||||
compound.setByte("LodestoneTracked", (byte) (lodestoneTracked ? 1 : 0));
|
||||
compound.setString("LodestoneDimension", lodestoneDimension);
|
||||
|
||||
{
|
||||
NBTCompound posCompound = new NBTCompound();
|
||||
posCompound.setInt("X", x);
|
||||
posCompound.setInt("Y", y);
|
||||
posCompound.setInt("Z", z);
|
||||
compound.set("LodestonePos", posCompound);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMeta clone() {
|
||||
CompassMeta compassMeta = new CompassMeta();
|
||||
compassMeta.lodestoneTracked = lodestoneTracked;
|
||||
compassMeta.lodestoneDimension = lodestoneDimension;
|
||||
compassMeta.x = x;
|
||||
compassMeta.y = y;
|
||||
compassMeta.z = z;
|
||||
|
||||
return compassMeta;
|
||||
}
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package net.minestom.server.item.metadata;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.item.ItemStackUtils;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
// TODO complete https://minecraft.gamepedia.com/Player.dat_format#Crossbows
|
||||
public class CrossbowMeta implements ItemMeta {
|
||||
|
||||
private boolean triple;
|
||||
private ItemStack projectile1, projectile2, projectile3;
|
||||
|
||||
private boolean charged;
|
||||
|
||||
public void setProjectile(ItemStack projectile) {
|
||||
this.projectile1 = projectile1;
|
||||
this.triple = false;
|
||||
}
|
||||
|
||||
public void setProjectiles(ItemStack projectile1, ItemStack projectile2, ItemStack projectile3) {
|
||||
this.projectile1 = projectile1;
|
||||
this.projectile2 = projectile2;
|
||||
this.projectile3 = projectile3;
|
||||
this.triple = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNbt() {
|
||||
return ItemStackUtils.isVisible(projectile1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSimilar(ItemMeta itemMeta) {
|
||||
if (!(itemMeta instanceof CrossbowMeta))
|
||||
return false;
|
||||
|
||||
final CrossbowMeta crossbowMeta = (CrossbowMeta) itemMeta;
|
||||
final boolean checkCount = triple && crossbowMeta.triple;
|
||||
if (!checkCount)
|
||||
return false;
|
||||
|
||||
if (triple && (projectile1.isSimilar(crossbowMeta.projectile1)) &&
|
||||
(projectile2.isSimilar(crossbowMeta.projectile2)) &&
|
||||
(projectile3.isSimilar(crossbowMeta.projectile3))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return !triple && (projectile1.isSimilar(crossbowMeta.projectile1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(NBTCompound compound) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(NBTCompound compound) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemMeta clone() {
|
||||
CrossbowMeta crossbowMeta = new CrossbowMeta();
|
||||
crossbowMeta.triple = triple;
|
||||
crossbowMeta.projectile1 = projectile1 == null ? null : projectile1.clone();
|
||||
crossbowMeta.projectile2 = projectile2 == null ? null : projectile2.clone();
|
||||
crossbowMeta.projectile3 = projectile3 == null ? null : projectile3.clone();
|
||||
|
||||
crossbowMeta.charged = charged;
|
||||
|
||||
return crossbowMeta;
|
||||
}
|
||||
}
|
@ -15,4 +15,14 @@ public class ItemStackUtils {
|
||||
return itemStack == null ? ItemStack.getAirItem() : itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to check if the item stack is a visible item (not null and not air)
|
||||
*
|
||||
* @param itemStack the item to check
|
||||
* @return true if the item is visible, false otherwise
|
||||
*/
|
||||
public static boolean isVisible(ItemStack itemStack) {
|
||||
return itemStack == null || itemStack.isAir();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user