mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
The leather armor pieces are now correctly colored
This commit is contained in:
parent
e3f6b73241
commit
a1ef2b21c3
@ -4,10 +4,15 @@ import net.minestom.server.chat.ChatColor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jglrxavpok.hephaistos.nbt.NBTCompound;
|
||||
|
||||
/** Represents the item meat for leather armor parts. */
|
||||
public class LeatherArmorMeta implements ItemMeta {
|
||||
|
||||
private static final int BIT_MASK = 0xFF;
|
||||
|
||||
private boolean modified;
|
||||
private byte red, green, blue;
|
||||
private byte red;
|
||||
private byte green;
|
||||
private byte blue;
|
||||
|
||||
/**
|
||||
* Sets the color of the leather armor piece.
|
||||
@ -23,8 +28,20 @@ public class LeatherArmorMeta implements ItemMeta {
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the color to the default leather one.
|
||||
* Changes the color of the leather armor piece.
|
||||
*
|
||||
* @param red The red color of the leather armor piece.
|
||||
* @param green The green color of the leather armor piece.
|
||||
* @param blue The blue color of the leather armor piece.
|
||||
*/
|
||||
public void setColor(byte red, byte green, byte blue) {
|
||||
this.red = red;
|
||||
this.green = green;
|
||||
this.blue = blue;
|
||||
this.modified = true;
|
||||
}
|
||||
|
||||
/** Resets the color to the default leather one. */
|
||||
public void reset() {
|
||||
this.red = 0;
|
||||
this.green = 0;
|
||||
@ -38,7 +55,7 @@ public class LeatherArmorMeta implements ItemMeta {
|
||||
* @return the red component
|
||||
*/
|
||||
public int getRed() {
|
||||
return red;
|
||||
return BIT_MASK & red;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +64,7 @@ public class LeatherArmorMeta implements ItemMeta {
|
||||
* @return the green component
|
||||
*/
|
||||
public int getGreen() {
|
||||
return green;
|
||||
return BIT_MASK & green;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,7 +73,7 @@ public class LeatherArmorMeta implements ItemMeta {
|
||||
* @return the blue component
|
||||
*/
|
||||
public int getBlue() {
|
||||
return blue;
|
||||
return BIT_MASK & blue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,35 +85,43 @@ public class LeatherArmorMeta implements ItemMeta {
|
||||
return modified;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean hasNbt() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public boolean isSimilar(@NotNull ItemMeta itemMeta) {
|
||||
if (!(itemMeta instanceof LeatherArmorMeta))
|
||||
return false;
|
||||
if (!(itemMeta instanceof LeatherArmorMeta)) return false;
|
||||
final LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta;
|
||||
return leatherArmorMeta.modified == modified &&
|
||||
leatherArmorMeta.red == red &&
|
||||
leatherArmorMeta.green == green &&
|
||||
leatherArmorMeta.blue == blue;
|
||||
return leatherArmorMeta.isModified() == isModified()
|
||||
&& leatherArmorMeta.getRed() == getRed()
|
||||
&& leatherArmorMeta.getGreen() == getGreen()
|
||||
&& leatherArmorMeta.getBlue() == getBlue();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void read(@NotNull NBTCompound compound) {
|
||||
if (compound.containsKey("display")) {
|
||||
final NBTCompound nbtCompound = compound.getCompound("display");
|
||||
if (nbtCompound.containsKey("color")) {
|
||||
final int color = nbtCompound.getInt("color");
|
||||
this.red = (byte) ((color >> 16) & 0x000000FF);
|
||||
this.green = (byte) ((color >> 8) & 0x000000FF);
|
||||
this.blue = (byte) ((color) & 0x000000FF);
|
||||
|
||||
// Sets the color of the leather armor piece
|
||||
// This also fixes that the armor pieces do not decolorize again when you are in creative
|
||||
// mode.
|
||||
this.setColor(
|
||||
(byte) ((color >> 16) & BIT_MASK),
|
||||
(byte) ((color >> 8) & BIT_MASK),
|
||||
(byte) ((color) & BIT_MASK));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public void write(@NotNull NBTCompound compound) {
|
||||
if (modified) {
|
||||
@ -106,19 +131,23 @@ public class LeatherArmorMeta implements ItemMeta {
|
||||
} else {
|
||||
displayCompound = compound.getCompound("display");
|
||||
}
|
||||
final int color = red << 16 + green << 8 + blue;
|
||||
final int color = this.getRed() << 16 | this.getGreen() << 8 | this.getBlue();
|
||||
|
||||
displayCompound.setInt("color", color);
|
||||
// Adds the color compound to the display compound
|
||||
compound.set("display", displayCompound);
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@NotNull
|
||||
@Override
|
||||
public ItemMeta copy() {
|
||||
LeatherArmorMeta leatherArmorMeta = new LeatherArmorMeta();
|
||||
leatherArmorMeta.modified = modified;
|
||||
leatherArmorMeta.red = red;
|
||||
leatherArmorMeta.green = green;
|
||||
leatherArmorMeta.blue = blue;
|
||||
leatherArmorMeta.modified = this.isModified();
|
||||
leatherArmorMeta.red = (byte) this.getRed();
|
||||
leatherArmorMeta.green = (byte) this.getGreen();
|
||||
leatherArmorMeta.blue = (byte) this.getBlue();
|
||||
|
||||
return leatherArmorMeta;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user