Posted April 4, 201411 yr Hey everyone, I created a block which can modify items. I have one input, one output an 4 modifier slots. When all the conditions are given I delete all slots and set the output slot to my output item with my modified values. The modified values are read correct(I send them to chat for debug) but the item doesnt get the values. I think the problem is in the onCreated method of my item. It is created before the NBT values are set. My Files: EditedFrame: package de.gero.skybees.items; import java.util.List; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.EnumRarity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import de.gero.skybees.api.IEditableHiveFrame; import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeGenome; import forestry.api.apiculture.IBeeHousing; import forestry.api.apiculture.IHiveFrame; public class EditedHiveFrame extends Item implements IHiveFrame, IEditableHiveFrame { private float floweringModifer; private float lifespanModifer; private float mutationModifier; private float territoryModifer; private float productionModifer; public EditedHiveFrame(int id) { super(id); setMaxStackSize(1); setMaxDamage(500); } @Override public String getItemDisplayName(ItemStack stack) { return "Custom Hive Frame"; } @Override public String getUnlocalizedName() { return "item.skyCustomFrame.name"; } @Override public void onCreated(ItemStack itemStack, World world, EntityPlayer player) { NBTTagCompound tag = itemStack.getTagCompound(); this.floweringModifer = tag.getFloat("floweringModifer"); this.lifespanModifer = tag.getFloat("lifespanModifer"); this.mutationModifier = tag.getFloat("mutationModifier"); this.territoryModifer = tag.getFloat("territoryModifer"); this.productionModifer = tag.getFloat("productionModifer"); } @Override public float getFloweringModifier(IBeeGenome beeGenome, float currentModifier) { return this.floweringModifer; } @Override public float getGeneticDecay(IBeeGenome beeGenome, float currentModifier) { return 1.0F; } @Override public float getLifespanModifier(IBeeGenome beeGenome1, IBeeGenome beeGenome2, float currentModifier) { return this.lifespanModifer; } @Override public float getMutationModifier(IBeeGenome beeGenome1, IBeeGenome beeGenome2, float currentModifier) { return this.mutationModifier; } @Override public float getProductionModifier(IBeeGenome beeGenome, float currentModifier) { return currentModifier < 16.0F ? this.productionModifer : 1.0F; } @Override public float getTerritoryModifier(IBeeGenome beeGenome, float currentModifier) { return this.territoryModifer; } @Override public boolean isHellish() { return false; } @Override public boolean isSealed() { return false; } @Override public boolean isSelfLighted() { return false; } @Override public boolean isSunlightSimulated() { return false; } @Override public ItemStack frameUsed(IBeeHousing housing, ItemStack frame, IBee queen, int wear) { frame.setItemDamage(frame.getItemDamage() + wear); if(frame.getItemDamage() >= frame.getMaxDamage()) { return null; } return frame; } @Override @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { this.itemIcon = iconRegister.registerIcon("skybees:textures/item/frameCustom.png"); } @Override @SideOnly(Side.CLIENT) public EnumRarity getRarity(ItemStack par1ItemStack){ return EnumRarity.uncommon; } @Override public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4) { par3List.add("M: " + this.mutationModifier + " F: " + this.floweringModifer); par3List.add("P: " + this.productionModifer + " T: " + this.territoryModifer); par3List.add("L: " + this.lifespanModifer); } } The craft() method of my tilentity public void craft(){ float flowering = 0; float lifespan = 0; float mutation = 0; float production = 0; float territory = 0; for(int i = 0; i < 4; i++){ if(items[i] != null){ if(items[i].getDisplayName().contains("Flowering")){ for(int y = 0; y < items[i].stackSize; y++){ flowering++; } } else if(items[i].getDisplayName().contains("Lifespan")){ for(int y = 0; y < items[i].stackSize; y++){ lifespan++; } } else if(items[i].getDisplayName().contains("Mutation")){ for(int y = 0; y < items[i].stackSize; y++){ mutation++; } } else if(items[i].getDisplayName().contains("Production")){ for(int y = 0; y < items[i].stackSize; y++){ production++; } } else if(items[i].getDisplayName().contains("Territory")){ for(int y = 0; y < items[i].stackSize; y++){ territory++; } } } } //All values got detected correctly here MinecraftServer.getServer().getConfigurationManager().sendChatMsg(ChatMessageComponent.createFromText("" + flowering + lifespan + mutation + production + territory)); ItemStack output = new ItemStack(Skybees.editedFrame); NBTTagCompound tag = output.getTagCompound(); if (tag == null) { tag = new NBTTagCompound(); output.setTagCompound(tag); } tag.setFloat("floweringModifer", flowering); tag.setFloat("lifespanModifer", lifespan); tag.setFloat("mutationModifier", mutation); tag.setFloat("territoryModifer", production); tag.setFloat("productionModifer", territory); setInventorySlotContents(5, output); mod = 0; setInventorySlotContents(0, null); } Thank you for helping an have a nice day!
April 4, 201411 yr Author Thanks for your fast reply! How would I pass on the values to my item when I spawn it in? This method I am using worked till now... Thanks and have nice day!
April 4, 201411 yr Author Isnt that what I did here? ItemStack output = new ItemStack(Skybees.editedFrame); NBTTagCompound tag = output.getTagCompound(); if (tag == null) { tag = new NBTTagCompound(); output.setTagCompound(tag); } tag.setFloat("floweringModifer", flowering); tag.setFloat("lifespanModifer", lifespan); tag.setFloat("mutationModifier", mutation); tag.setFloat("territoryModifer", production); tag.setFloat("productionModifer", territory);
April 4, 201411 yr You really are using superfluous loops for no good reason here. for(int y = 0; y < items[ i ].stackSize; y++){ flowering++; } flowering += items[ i ].stackSize; does the same thing with one instruction. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
April 4, 201411 yr Author @diesieben07 When i Spawn in my Item it does not have the upgrades. Now I am searching for a way to set the values which are passed via the NBT-Data I hope this was understandable Have a nice day!
April 4, 201411 yr Author My machine can customize Hive Frames... Depending on which Modifier I put in the Modifier slots it sets the value for production to the number of modifiers. In that "craft" process all slots in the inventory get wiped and I create a new Item (dfferent from the ones I deleted) and try to set the values I got via nbt, so that that Item is now in the output slots with the values set (visible via tooltip). My problem is that the Item I create (by doing ItemStack output = new ItemStack(Skybees.editedFrame) does not take the nbt data I pass and does not show them in the tooltip.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.