OnCreated non appelé
-
Salut !
public class ItemSatelliteIdentifier extends Item implements IMedia { public void onCreated(ItemStack stack, World world, EntityPlayer player) { System.out.println("onCreated"); stack.stackTagCompound = new NBTTagCompound(); stack.stackTagCompound.setBoolean("hasSatellite", false); stack.stackTagCompound.setBoolean("hasLabel", false); } @SuppressWarnings({ "unchecked", "rawtypes" }) public void addInformation(ItemStack stack, EntityPlayer player, List info, boolean par4) { if (stack.stackTagCompound != null) { if (stack.stackTagCompound.getBoolean("hasLabel")) { info.add(EnumChatFormatting.WHITE + stack.stackTagCompound.getString("label")); } if (stack.stackTagCompound.getBoolean("hasSatellite")) { info.add(EnumChatFormatting.DARK_GRAY + stack.stackTagCompound.getString("satellite")); } } } @Override public String getLabel(ItemStack stack) { if (stack.stackTagCompound != null) if (stack.stackTagCompound.getBoolean("hasLabel")) return stack.stackTagCompound.getString("label"); return null; } @Override public boolean setLabel(ItemStack stack, String label) { if (stack.stackTagCompound != null && label != null) { if (label == "") { stack.stackTagCompound.setBoolean("hasLabel", false); return true; } if (!stack.stackTagCompound.getBoolean("hasLabel")) stack.stackTagCompound.setBoolean("hasLabel", true); stack.stackTagCompound.setString("label", label); return true; } return false; } @Override public String getAudioTitle(ItemStack stack) { return null; } @Override public String getAudioRecordName(ItemStack stack) { return null; } @Override public IMount createDataMount(ItemStack stack, World world) { return null; } }Cependant, lorsque je sors mon item du créatif, onCreated n’est pas appelé (inutile d’expliquer les crashs que ça provoque).
Comment puis-je faire que ça marche, qu’ai-je fait de mal ?
Merci d’avance !
-
onCreated est appelé uniquement lors du craft de l’item, c’est voulu.
Ce qui faut faire, c’est regardé si stack.getTagCompound() est null, si non tu fais ton action, si oui tu mets la valeur par défaut. -
Ok c’est bon, merci. J’ai mis un check de stack.stackTagCompound dans onUpdate.
Bonjour ! Vous semblez intéressé par cette conversation, mais vous n’avez pas encore de compte.
Marre de refaire défiler les mêmes messages ? Créez un compte pour retrouver votre position, recevoir des notifications des nouvelles réponses, sauvegarder vos favoris et voter pour les messages que vous appréciez.
Grâce à votre participation, ce message peut devenir encore meilleur 💗
S'inscrire Se connecter