Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.dpohvar.varscript.utils.minecraft;
- import net.minecraft.server.NBTTagCompound;
- import org.bukkit.craftbukkit.inventory.CraftItemStack;
- import org.bukkit.inventory.ItemStack;
- import java.nio.ByteBuffer;
- /**
- * Created by IntelliJ IDEA.
- * User: DPOH-VAR
- * Date: 10.08.12
- * Time: 22:35
- * To change this template use File | Settings | File Templates.
- */
- public class ColorEdit{
- public final ItemStack item;
- private NBTTagCompound tagData;
- public ColorEdit(ItemStack s){
- this.item = s;
- net.minecraft.server.ItemStack i = ((CraftItemStack) s).getHandle();
- if (i.tag == null) {
- tagData = new NBTTagCompound();
- i.tag = tagData;
- } else {
- tagData = i.tag;
- }
- }
- public int getColor(){
- if (!tagData.hasKey("display")) {
- return -1;
- }
- NBTTagCompound t = tagData.getCompound("display");
- if (!t.hasKey("color")) {
- return -1;
- }
- return tagData.getCompound("display").getInt("color");
- }
- public ColorEdit setColor(int color){
- if(color==-1){
- removeColor();
- return this;
- }
- if(tagData.hasKey("display")){
- NBTTagCompound d = tagData.getCompound("display");
- d.setInt("color", color);
- } else {
- NBTTagCompound d = new NBTTagCompound();
- d.setInt("color", color);
- tagData.setCompound("display",d);
- }
- return this;
- }
- public void removeColor(){
- tagData.getCompound("display").remove("color");
- }
- private byte[] getColors(){
- int color = getColor();
- if (color==-1) return new byte[4];
- return ByteBuffer.allocate(4).putInt(color).array();
- }
- private ColorEdit setColors(byte[] colors){
- setColor(ByteBuffer.wrap(colors).getInt());
- return this;
- }
- private ColorEdit setColorById(byte value,int id){
- byte[] colors = getColors();
- colors[id]=value;
- setColors(colors);
- return this;
- }
- private int getColorById(int id){
- int color = getColor();
- if(color==-1) return -1;
- return ByteBuffer.allocate(4).putInt(color).array()[id];
- }
- private ColorEdit setRGB(byte red,byte green,byte blue){
- byte[] colors = getColors();
- colors[1]=red;
- colors[2]=green;
- colors[3]=blue;
- setColors(colors);
- return this;
- }
- public ColorEdit setRed(byte red){return setColorById(red,1);}
- public ColorEdit setGreen(byte green){return setColorById(green,2);}
- public ColorEdit setBlue(byte blue){return setColorById(blue,3);}
- @Deprecated public ColorEdit setAlpha(byte alpha){return setColorById(alpha,0);}
- public int getRed(){return getColorById(1);}
- public int getGreen(){return getColorById(2);}
- public int getBlue(){return getColorById(3);}
- @Deprecated public int getAlpha(){return getColorById(0);}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement