Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/main/java/cn/nukkit/item/ItemFireworkStar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package cn.nukkit.item;

import cn.nukkit.Server;
import cn.nukkit.nbt.tag.CompoundTag;
import cn.nukkit.utils.BlockColor;
import cn.nukkit.utils.DyeColor;

/**
* @author PetteriM1
*/
Expand All @@ -15,5 +20,41 @@ public ItemFireworkStar(Integer meta) {

public ItemFireworkStar(Integer meta, int count) {
super(FIREWORKSCHARGE, meta, count, "Firework Star");

if (!hasCompoundTag() || !this.getNamedTag().contains("customColor")) {
setColor(DyeColor.getByDyeData(meta).getColor());
}
}

public void setColor(BlockColor color) {
setColor(color.getRed(), color.getGreen(), color.getBlue());
}

public void setColor(int r, int g, int b) {
int color = ~(~(r << 16 | g << 8 | b) & 0xffffff);
CompoundTag tag;
if (!this.hasCompoundTag()) {
tag = new CompoundTag();
} else {
tag = this.getNamedTag();
}
if (color == -15132391) {
Server.getInstance().getLogger().info("黑色的 firework star");
return;
} else {
Server.getInstance().getLogger().info("其它颜色的 firework star, rgb: "+r+" "+g+" "+b);
Server.getInstance().getLogger().info("color: "+color);
}
tag.putInt("customColor", color);
this.setNamedTag(tag);
}

public BlockColor getColor() {
if (!this.hasCompoundTag()) return null;
CompoundTag tag = this.getNamedTag();
if (!tag.exist("customColor")) return null;
int rgb = tag.getInt("customColor");
return new BlockColor(rgb);
}

}