Search in sources :

Example 1 with NBTPrimitive

use of net.minecraft.nbt.NBTPrimitive in project Charset by CharsetMC.

the class FluidDyedWater method getDyeColor.

public int getDyeColor(FluidStack stack) {
    NBTTagCompound tag = stack.tag;
    if (tag == null || !tag.hasKey("dyes", Constants.NBT.TAG_LIST)) {
        return -1;
    } else {
        NBTTagList dyes = ((NBTTagList) stack.tag.getTag("dyes"));
        int[] color = new int[3];
        int scale = 0;
        int count = dyes.tagCount();
        if (dyes.tagCount() == 0) {
            return -1;
        }
        for (int i = 0; i < count; i++) {
            float[] colF = EnumDyeColor.byMetadata(((NBTPrimitive) dyes.get(i)).getByte()).getColorComponentValues();
            int[] col = new int[] { (int) (colF[0] * 255.0F), (int) (colF[1] * 255.0F), (int) (colF[2] * 255.0F) };
            scale += Math.max(col[0], Math.max(col[1], col[2]));
            color[0] += col[0];
            color[1] += col[1];
            color[2] += col[2];
        }
        int i1 = color[0] / count;
        int j1 = color[1] / count;
        int k1 = color[2] / count;
        float f3 = (float) scale / (float) count;
        float f4 = (float) Math.max(i1, Math.max(j1, k1));
        i1 = (int) (i1 * f3 / f4);
        j1 = (int) (j1 * f3 / f4);
        k1 = (int) (k1 * f3 / f4);
        return (i1 << 16) + (j1 << 8) + k1;
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTPrimitive(net.minecraft.nbt.NBTPrimitive) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with NBTPrimitive

use of net.minecraft.nbt.NBTPrimitive in project BetterQuesting by Funwayguy.

the class ScrollingJsonEntry method setupEntry.

public void setupEntry(int px, int width) {
    btnList.clear();
    int margin = px + (width / 3);
    int ctrlSpace = MathHelper.ceil((width / 3F) * 2F);
    int n = 0;
    if (allowEdit && je != null) {
        n = 20;
        btnDel = new GuiButtonThemed(3, px + width - n, 0, 20, 20, "x");
        btnDel.packedFGColour = Color.RED.getRGB();
        btnList.add(btnDel);
    }
    if (allowEdit) {
        n = 40;
        btnAdd = new GuiButtonThemed(2, px + width - n, 0, 20, 20, "+");
        btnAdd.packedFGColour = Color.GREEN.getRGB();
        btnList.add(btnAdd);
    }
    if (je == null) {
        return;
    } else if (je.getId() == 9) {
        btnMain = new GuiButtonJson<NBTTagList>(0, margin, 0, ctrlSpace - n, 20, (NBTTagList) je, false);
        btnList.add(btnMain);
    } else if (je.getId() == 10) {
        NBTTagCompound jo = (NBTTagCompound) je;
        if (JsonHelper.isItem(jo) || JsonHelper.isFluid(jo) || JsonHelper.isEntity(jo)) {
            n += 20;
            btnAdv = new GuiButtonThemed(1, px + width - n, 0, 20, 20, "...");
            btnList.add(btnAdv);
        }
        btnMain = new GuiButtonJson<NBTTagCompound>(0, margin, 0, ctrlSpace - n, 20, jo, false);
        btnList.add(btnMain);
    } else if (je instanceof NBTPrimitive) {
        NBTPrimitive jp = (NBTPrimitive) je;
        /*if(jp.isBoolean())
			{
				btnMain = new GuiButtonJson<JsonPrimitive>(0, margin, 0, ctrlSpace - n, 20, jp, false);
				btnList.add(btnMain);
			} else if(jp.isNumber())*/
        {
            GuiNumberField num = new GuiNumberField(mc.fontRenderer, margin + 1, 0, ctrlSpace - n - 2, 18);
            num.setMaxStringLength(Integer.MAX_VALUE);
            num.setText("" + jp.getDouble());
            txtMain = num;
        }
    // else
    } else if (je.getId() == 8) {
        NBTTagString jp = (NBTTagString) je;
        GuiBigTextField txt = new GuiBigTextField(mc.fontRenderer, margin + 1, 1, ctrlSpace - n - 2, 18);
        txt.setMaxStringLength(Integer.MAX_VALUE);
        txt.setText(jp.getString());
        if (json.getId() == 10) {
            txt.enableBigEdit(new TextCallbackJsonObject((NBTTagCompound) json, key));
        } else if (json.getId() == 9) {
            txt.enableBigEdit(new TextCallbackJsonArray((NBTTagList) json, idx));
        }
        txtMain = txt;
    }
}
Also used : NBTPrimitive(net.minecraft.nbt.NBTPrimitive) GuiButtonJson(betterquesting.api.client.gui.controls.GuiButtonJson) TextCallbackJsonArray(betterquesting.client.gui.editors.json.TextCallbackJsonArray) GuiNumberField(betterquesting.api.client.gui.controls.GuiNumberField) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) GuiBigTextField(betterquesting.api.client.gui.controls.GuiBigTextField) GuiButtonThemed(betterquesting.api.client.gui.controls.GuiButtonThemed) NBTTagString(net.minecraft.nbt.NBTTagString) TextCallbackJsonObject(betterquesting.client.gui.editors.json.TextCallbackJsonObject)

Example 3 with NBTPrimitive

use of net.minecraft.nbt.NBTPrimitive in project BuildCraft by BuildCraft.

the class TileFloodGate method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    NBTBase open = nbt.getTag("openSides");
    if (open instanceof NBTPrimitive) {
        byte sides = ((NBTPrimitive) open).getByte();
        for (EnumFacing face : EnumFacing.VALUES) {
            if (((sides >> face.getIndex()) & 1) == 1) {
                openSides.add(face);
            } else {
                openSides.remove(face);
            }
        }
    } else if (open instanceof NBTTagByteArray) {
        // Legacy: 7.99.7 and before
        byte[] bytes = ((NBTTagByteArray) open).getByteArray();
        BitSet bitSet = BitSet.valueOf(bytes);
        for (EnumFacing face : EnumFacing.VALUES) {
            if (bitSet.get(face.getIndex())) {
                openSides.add(face);
            } else {
                openSides.remove(face);
            }
        }
    }
}
Also used : NBTPrimitive(net.minecraft.nbt.NBTPrimitive) NBTBase(net.minecraft.nbt.NBTBase) EnumFacing(net.minecraft.util.EnumFacing) BitSet(java.util.BitSet) NBTTagByteArray(net.minecraft.nbt.NBTTagByteArray)

Example 4 with NBTPrimitive

use of net.minecraft.nbt.NBTPrimitive in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class CapabilityEvents method onEntityConstructing.

@SubscribeEvent
public void onEntityConstructing(AttachCapabilitiesEvent<Entity> event) {
    if (event.getObject() instanceof EntityPlayer) {
        event.addCapability(new ResourceLocation(Reference.MODID, "IOrganizationXIII"), new ICapabilitySerializable<NBTTagCompound>() {

            OrganizationXIIICapability.IOrganizationXIII inst = ModCapabilities.ORGANIZATION_XIII.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, @Nullable EnumFacing facing) {
                return capability == ModCapabilities.ORGANIZATION_XIII;
            }

            @Override
            public <T> T getCapability(Capability<T> capability, @Nullable EnumFacing facing) {
                return capability == ModCapabilities.ORGANIZATION_XIII ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.ORGANIZATION_XIII.getStorage().writeNBT(ModCapabilities.ORGANIZATION_XIII, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.ORGANIZATION_XIII.getStorage().readNBT(ModCapabilities.ORGANIZATION_XIII, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IMunny"), new ICapabilitySerializable<NBTPrimitive>() {

            MunnyCapability.IMunny inst = ModCapabilities.MUNNY.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.MUNNY;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.MUNNY ? (T) inst : null;
            }

            @Override
            public NBTPrimitive serializeNBT() {
                return (NBTPrimitive) ModCapabilities.MUNNY.getStorage().writeNBT(ModCapabilities.MUNNY, inst, null);
            }

            @Override
            public void deserializeNBT(NBTPrimitive nbt) {
                ModCapabilities.MUNNY.getStorage().readNBT(ModCapabilities.MUNNY, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "ICheatMode"), new ICapabilitySerializable<NBTPrimitive>() {

            CheatModeCapability.ICheatMode inst = ModCapabilities.CHEAT_MODE.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.CHEAT_MODE;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.CHEAT_MODE ? (T) inst : null;
            }

            @Override
            public NBTPrimitive serializeNBT() {
                return (NBTPrimitive) ModCapabilities.CHEAT_MODE.getStorage().writeNBT(ModCapabilities.CHEAT_MODE, inst, null);
            }

            @Override
            public void deserializeNBT(NBTPrimitive nbt) {
                ModCapabilities.CHEAT_MODE.getStorage().readNBT(ModCapabilities.CHEAT_MODE, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IPlayerStats"), new ICapabilitySerializable<NBTTagCompound>() {

            PlayerStatsCapability.IPlayerStats inst = ModCapabilities.PLAYER_STATS.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.PLAYER_STATS;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.PLAYER_STATS ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.PLAYER_STATS.getStorage().writeNBT(ModCapabilities.PLAYER_STATS, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.PLAYER_STATS.getStorage().readNBT(ModCapabilities.PLAYER_STATS, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "ISummonKeyblade"), new ICapabilitySerializable<NBTTagCompound>() {

            SummonKeybladeCapability.ISummonKeyblade inst = ModCapabilities.SUMMON_KEYBLADE.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.SUMMON_KEYBLADE;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.SUMMON_KEYBLADE ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.SUMMON_KEYBLADE.getStorage().writeNBT(ModCapabilities.SUMMON_KEYBLADE, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.SUMMON_KEYBLADE.getStorage().readNBT(ModCapabilities.SUMMON_KEYBLADE, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IMagicState"), new ICapabilitySerializable<NBTTagCompound>() {

            MagicStateCapability.IMagicState inst = ModCapabilities.MAGIC_STATE.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.MAGIC_STATE;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.MAGIC_STATE ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.MAGIC_STATE.getStorage().writeNBT(ModCapabilities.MAGIC_STATE, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.MAGIC_STATE.getStorage().readNBT(ModCapabilities.MAGIC_STATE, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IDriveState"), new ICapabilitySerializable<NBTTagCompound>() {

            DriveStateCapability.IDriveState inst = ModCapabilities.DRIVE_STATE.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.DRIVE_STATE;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.DRIVE_STATE ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.DRIVE_STATE.getStorage().writeNBT(ModCapabilities.DRIVE_STATE, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.DRIVE_STATE.getStorage().readNBT(ModCapabilities.DRIVE_STATE, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "IFirstTimeJoin"), new ICapabilitySerializable<NBTTagCompound>() {

            FirstTimeJoinCapability.IFirstTimeJoin inst = ModCapabilities.FIRST_TIME_JOIN.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.FIRST_TIME_JOIN;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.FIRST_TIME_JOIN ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.FIRST_TIME_JOIN.getStorage().writeNBT(ModCapabilities.FIRST_TIME_JOIN, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.FIRST_TIME_JOIN.getStorage().readNBT(ModCapabilities.FIRST_TIME_JOIN, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "ISynthesisRecipe"), new ICapabilitySerializable<NBTTagCompound>() {

            SynthesisRecipeCapability.ISynthesisRecipe inst = ModCapabilities.SYNTHESIS_RECIPES.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.SYNTHESIS_RECIPES;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.SYNTHESIS_RECIPES ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.SYNTHESIS_RECIPES.getStorage().writeNBT(ModCapabilities.SYNTHESIS_RECIPES, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.SYNTHESIS_RECIPES.getStorage().readNBT(ModCapabilities.SYNTHESIS_RECIPES, inst, null, nbt);
            }
        });
        event.addCapability(new ResourceLocation(Reference.MODID, "ISynthesisMaterial"), new ICapabilitySerializable<NBTTagCompound>() {

            SynthesisMaterialCapability.ISynthesisMaterial inst = ModCapabilities.SYNTHESIS_MATERIALS.getDefaultInstance();

            @Override
            public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
                return capability == ModCapabilities.SYNTHESIS_MATERIALS;
            }

            @SuppressWarnings("unchecked")
            @Override
            public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
                return capability == ModCapabilities.SYNTHESIS_MATERIALS ? (T) inst : null;
            }

            @Override
            public NBTTagCompound serializeNBT() {
                return (NBTTagCompound) ModCapabilities.SYNTHESIS_MATERIALS.getStorage().writeNBT(ModCapabilities.SYNTHESIS_MATERIALS, inst, null);
            }

            @Override
            public void deserializeNBT(NBTTagCompound nbt) {
                ModCapabilities.SYNTHESIS_MATERIALS.getStorage().readNBT(ModCapabilities.SYNTHESIS_MATERIALS, inst, null, nbt);
            }
        });
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SynthesisRecipeCapability(uk.co.wehavecookies56.kk.common.capability.SynthesisRecipeCapability) ResourceLocation(net.minecraft.util.ResourceLocation) DriveStateCapability(uk.co.wehavecookies56.kk.common.capability.DriveStateCapability) MunnyCapability(uk.co.wehavecookies56.kk.common.capability.MunnyCapability) MagicStateCapability(uk.co.wehavecookies56.kk.common.capability.MagicStateCapability) OrganizationXIIICapability(uk.co.wehavecookies56.kk.common.capability.OrganizationXIIICapability) NBTPrimitive(net.minecraft.nbt.NBTPrimitive) SynthesisMaterialCapability(uk.co.wehavecookies56.kk.common.capability.SynthesisMaterialCapability) SummonKeybladeCapability(uk.co.wehavecookies56.kk.common.capability.SummonKeybladeCapability) FirstTimeJoinCapability(uk.co.wehavecookies56.kk.common.capability.FirstTimeJoinCapability) PlayerStatsCapability(uk.co.wehavecookies56.kk.common.capability.PlayerStatsCapability) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CheatModeCapability(uk.co.wehavecookies56.kk.common.capability.CheatModeCapability) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with NBTPrimitive

use of net.minecraft.nbt.NBTPrimitive in project BetterQuesting by Funwayguy.

the class QuestInstance method readFromJson_Config.

private void readFromJson_Config(NBTTagCompound jObj) {
    this.qInfo.readFromNBT(jObj.getCompoundTag("properties"), EnumSaveType.CONFIG);
    this.tasks.readFromNBT(jObj.getTagList("tasks", 10), EnumSaveType.CONFIG);
    this.rewards.readFromNBT(jObj.getTagList("rewards", 10), EnumSaveType.CONFIG);
    preRequisites.clear();
    if (// Native NBT
    jObj.getTagId("preRequisites") == 11) {
        for (int prID : jObj.getIntArray("preRequisites")) {
            if (prID < 0) {
                continue;
            }
            IQuest tmp = parentDB.getValue(prID);
            if (tmp == null) {
                tmp = parentDB.createNew();
                parentDB.add(tmp, prID);
            }
            preRequisites.add(tmp);
        }
    } else // Probably an NBTTagList
    {
        NBTTagList rList = jObj.getTagList("preRequisites", 4);
        for (int i = 0; i < rList.tagCount(); i++) {
            NBTBase pTag = rList.get(i);
            int prID = pTag instanceof NBTPrimitive ? ((NBTPrimitive) pTag).getInt() : -1;
            if (prID < 0) {
                continue;
            }
            IQuest tmp = parentDB.getValue(prID);
            if (tmp == null) {
                tmp = parentDB.createNew();
                parentDB.add(tmp, prID);
            }
            preRequisites.add(tmp);
        }
    }
    this.setupProps();
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTPrimitive(net.minecraft.nbt.NBTPrimitive) IQuest(betterquesting.api.questing.IQuest) NBTBase(net.minecraft.nbt.NBTBase)

Aggregations

NBTPrimitive (net.minecraft.nbt.NBTPrimitive)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTBase (net.minecraft.nbt.NBTBase)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 NBTTagByteArray (net.minecraft.nbt.NBTTagByteArray)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 EnumFacing (net.minecraft.util.EnumFacing)2 GuiBigTextField (betterquesting.api.client.gui.controls.GuiBigTextField)1 GuiButtonJson (betterquesting.api.client.gui.controls.GuiButtonJson)1 GuiButtonThemed (betterquesting.api.client.gui.controls.GuiButtonThemed)1 GuiNumberField (betterquesting.api.client.gui.controls.GuiNumberField)1 IQuest (betterquesting.api.questing.IQuest)1 TextCallbackJsonArray (betterquesting.client.gui.editors.json.TextCallbackJsonArray)1 TextCallbackJsonObject (betterquesting.client.gui.editors.json.TextCallbackJsonObject)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagDouble (net.minecraft.nbt.NBTTagDouble)1 NBTTagFloat (net.minecraft.nbt.NBTTagFloat)1 NBTTagIntArray (net.minecraft.nbt.NBTTagIntArray)1