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;
}
}
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;
}
}
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);
}
}
}
}
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);
}
});
}
}
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();
}
Aggregations