Créer un onglet créatif
-
voila mon code
package com.google.natchesprout.BetterCoalFactory.common; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; @Mod(modid = "bettercoalfactory" , name ="Better Coal Factory", version = "0.0.1 Alpha" ) public class BetterCoalFactory { @Instance("bettercoalfactory") public static BetterCoalFactory instance; @SidedProxy(clientSide = "com.google.natchesprout.BetterCoalFactory.client.ClientProxy", serverSide = "com.google.natchesprout.BetterCoalFactory.common.CommonProxy") public static CommonProxy proxy; public static Block SuperCoalOre; public static CreativeTabs BetterCoalFactoryTab = new CreativeTabs("Better_Coal_Factory") { @Override public Item getTabIconItem() { return Item.getItemFromBlock(BetterCoalFactory.SuperCoalOre); } @SideOnly(Side.CLIENT) public int func_151243_f() { return 0; } }; @EventHandler public void preInit(FMLPreInitializationEvent event) { SuperCoalOre = new SuperCoalOre(Material.rock).setBlockName("SuperCoalOre").setBlockTextureName("bettercoalfactory:block_supercoalore").setCreativeTab(BetterCoalFactory.BetterCoalFactoryTab); GameRegistry.registerBlock(SuperCoalOre, "block_supercoalore"); } private void getTabIconItem() { // TODO Auto-generated method stub } @EventHandler public void init(FMLInitializationEvent event) { proxy.registerRender(); } @EventHandler public void postInit(FMLPostInitializationEvent event) { } }
-
Version de Forge ? Tu n’as répondu à cette question.
Sur le code complet je ne vois pas de problème, hormis la convention Java qui n’est pas respecté mais ça n’a pas d’impact sur le fonctionnement du code. -
dsl version forge-1.7.10-10.13.2.1291
-
qu’elle est la convention java par ailleurs?
-
@‘natchesprout’:
qu’elle est la convention java par ailleurs?
Voici une page qui explique parfaitement ce qu’est la convention Java et comment s’en servir =D
http://openclassrooms.com/forum/sujet/conventions-de-codage-en-java-64171 -
Je viens de regarder le changlog de forge, il n’y a qui parle des onglets créatifs. Je ne vois pas où est le problème, envoie-moi un .zip de ton dossier src.
-
voila mon .zip de mon src
-
J’ai pourtant juste copié les sources.
J’utilise Forge 10.13.2.1291 -
comment mettre l’oeuf d’un monstre que l’on a creer dans la creative tab svp ?
-
public void displayAllReleventItems(List list) { super.displayAllReleventItems(list); list.add(new ItemStack(Items.spawn_egg, 1, /** id du mob ici**/)); }
Le problème c’est juste l’id. Il faudrait placer ça dans la classe de la table créatif.
-
sa a lair de marcher sauf que sa met un oueuf aleatoire si il y a dautres mods d’instaler car l’oeuf a un id de 3 par defaut et on ne peut pas le changer enfait si il y a dautres mods qui en rajouute les ids de tout les oeufs sont aleatoire ce qui fait donc que un oeuf au hasard est dans la table
j’ai deja esayer de changer lid du monstre mais sa laisse toujours 3.
avec f3 + h on le vois et c’est le metadata 383/3 on peut pas le changer c’est gerer par le jeu -
Faudrait regarder comment FML gère les entités des mods.
-
j’ai trouver cette classe mais je n’ai pas trouver l’option qui correspond
cpw.mods.fml.common.registry.entityregistryClasse Entity Registry
/* * Forge Mod Loader * Copyright © 2012-2013 cpw. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v2.1 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * cpw - implementation */ package cpw.mods.fml.common.registry; import java.util.BitSet; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.logging.log4j.Level; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityTracker; import net.minecraft.entity.EnumCreatureType; import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.BiomeGenBase.SpawnListEntry; import com.google.common.base.Function; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Maps; import com.google.common.primitives.UnsignedBytes; import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLLog; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.network.internal.FMLMessage.EntitySpawnMessage; import net.minecraft.world.biome.BiomeGenBase.SpawnListEntry; public class EntityRegistry { public class EntityRegistration { private Class entityClass; private ModContainer container; private String entityName; private int modId; private int trackingRange; private int updateFrequency; private boolean sendsVelocityUpdates; private Function <entityspawnmessage, entity="">customSpawnCallback; private boolean usesVanillaSpawning; public EntityRegistration(ModContainer mc, Class entityClass, String entityName, int id, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates) { this.container = mc; this.entityClass = entityClass; this.entityName = entityName; this.modId = id; this.trackingRange = trackingRange; this.updateFrequency = updateFrequency; this.sendsVelocityUpdates = sendsVelocityUpdates; } public Class getEntityClass() { return entityClass; } public ModContainer getContainer() { return container; } public String getEntityName() { return entityName; } public int getModEntityId() { return modId; } public int getTrackingRange() { return trackingRange; } public int getUpdateFrequency() { return updateFrequency; } public boolean sendsVelocityUpdates() { return sendsVelocityUpdates; } public boolean usesVanillaSpawning() { return usesVanillaSpawning; } public boolean hasCustomSpawning() { return customSpawnCallback != null; } public Entity doCustomSpawning(EntitySpawnMessage spawnMsg) throws Exception { return customSpawnCallback.apply(spawnMsg); } public void setCustomSpawning(Function <entityspawnmessage, entity="">callable, boolean usesVanillaSpawning) { this.customSpawnCallback = callable; this.usesVanillaSpawning = usesVanillaSpawning; } } private static final EntityRegistry INSTANCE = new EntityRegistry(); private BitSet availableIndicies; private ListMultimap <modcontainer, entityregistration="">entityRegistrations = ArrayListMultimap.create(); private Map <string,modcontainer>entityNames = Maps.newHashMap(); private BiMap<class<? extends="" entity="">, EntityRegistration> entityClassRegistrations = HashBiMap.create(); public static EntityRegistry instance() { return INSTANCE; } private EntityRegistry() { availableIndicies = new BitSet(256); availableIndicies.set(1,255); for (Object id : EntityList.IDtoClassMapping.keySet()) { availableIndicies.clear((Integer)id); } } /** * Register the mod entity type with FML * @param entityClass The entity class * @param entityName A unique name for the entity * @param id A mod specific ID for the entity * @param mod The mod * @param trackingRange The range at which MC will send tracking updates * @param updateFrequency The frequency of tracking updates * @param sendsVelocityUpdates Whether to send velocity information packets as well */ public static void registerModEntity(Class entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates) { instance().doModEntityRegistration(entityClass, entityName, id, mod, trackingRange, updateFrequency, sendsVelocityUpdates); } @SuppressWarnings("unchecked") private void doModEntityRegistration(Class entityClass, String entityName, int id, Object mod, int trackingRange, int updateFrequency, boolean sendsVelocityUpdates) { ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod); EntityRegistration er = new EntityRegistration(mc, entityClass, entityName, id, trackingRange, updateFrequency, sendsVelocityUpdates); try { entityClassRegistrations.put(entityClass, er); entityNames.put(entityName, mc); if (!EntityList.classToStringMapping.containsKey(entityClass)) { String entityModName = String.format("%s.%s", mc.getModId(), entityName); EntityList.classToStringMapping.put(entityClass, entityModName); EntityList.stringToClassMapping.put(entityModName, entityClass); FMLLog.finer("Automatically registered mod %s entity %s as %s", mc.getModId(), entityName, entityModName); } else { FMLLog.fine("Skipping automatic mod %s entity registration for already registered class %s", mc.getModId(), entityClass.getName()); } } catch (IllegalArgumentException e) { FMLLog.log(Level.WARN, e, "The mod %s tried to register the entity (name,class) (%s,%s) one or both of which are already registered", mc.getModId(), entityName, entityClass.getName()); return; } entityRegistrations.put(mc, er); } public static void registerGlobalEntityID(Class entityClass, String entityName, int id) { if (EntityList.classToStringMapping.containsKey(entityClass)) { ModContainer activeModContainer = Loader.instance().activeModContainer(); String modId = "unknown"; if (activeModContainer != null) { modId = activeModContainer.getModId(); } else { FMLLog.severe("There is a rogue mod failing to register entities from outside the context of mod loading. This is incredibly dangerous and should be stopped."); } FMLLog.warning("The mod %s tried to register the entity class %s which was already registered - if you wish to override default naming for FML mod entities, register it here first", modId, entityClass); return; } id = instance().validateAndClaimId(id); EntityList.addMapping(entityClass, entityName, id); } private int validateAndClaimId(int id) { // workaround for broken ML int realId = id; if (id < Byte.MIN_VALUE) { FMLLog.warning("Compensating for modloader out of range compensation by mod : entityId %d for mod %s is now %d", id, Loader.instance().activeModContainer().getModId(), realId); realId += 3000; } if (realId < 0) { realId += Byte.MAX_VALUE; } try { UnsignedBytes.checkedCast(realId); } catch (IllegalArgumentException e) { FMLLog.log(Level.ERROR, "The entity ID %d for mod %s is not an unsigned byte and may not work", id, Loader.instance().activeModContainer().getModId()); } if (!availableIndicies.get(realId)) { FMLLog.severe("The mod %s has attempted to register an entity ID %d which is already reserved. This could cause severe problems", Loader.instance().activeModContainer().getModId(), id); } availableIndicies.clear(realId); return realId; } public static void registerGlobalEntityID(Class entityClass, String entityName, int id, int backgroundEggColour, int foregroundEggColour) { if (EntityList.classToStringMapping.containsKey(entityClass)) { ModContainer activeModContainer = Loader.instance().activeModContainer(); String modId = "unknown"; if (activeModContainer != null) { modId = activeModContainer.getModId(); } else { FMLLog.severe("There is a rogue mod failing to register entities from outside the context of mod loading. This is incredibly dangerous and should be stopped."); } FMLLog.warning("The mod %s tried to register the entity class %s which was already registered - if you wish to override default naming for FML mod entities, register it here first", modId, entityClass); return; } instance().validateAndClaimId(id); EntityList.addMapping(entityClass, entityName, id, backgroundEggColour, foregroundEggColour); } public static void addSpawn(Class entityClass, int weightedProb, int min, int max, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) { for (BiomeGenBase biome : biomes) { @SuppressWarnings("unchecked") List <spawnlistentry>spawns = biome.getSpawnableList(typeOfCreature); for (SpawnListEntry entry : spawns) { //Adjusting an existing spawn entry if (entry.entityClass == entityClass) { entry.itemWeight = weightedProb; entry.minGroupCount = min; entry.maxGroupCount = max; break; } } spawns.add(new SpawnListEntry(entityClass, weightedProb, min, max)); } } @SuppressWarnings("unchecked") public static void addSpawn(String entityName, int weightedProb, int min, int max, EnumCreatureType spawnList, BiomeGenBase... biomes) { Class entityClazz = (Class) EntityList.stringToClassMapping.get(entityName); if (EntityLiving.class.isAssignableFrom(entityClazz)) { addSpawn((Class ) entityClazz, weightedProb, min, max, spawnList, biomes); } } public static void removeSpawn(Class entityClass, EnumCreatureType typeOfCreature, BiomeGenBase... biomes) { for (BiomeGenBase biome : biomes) { @SuppressWarnings("unchecked") Iterator <spawnlistentry>spawns = biome.getSpawnableList(typeOfCreature).iterator(); while (spawns.hasNext()) { SpawnListEntry entry = spawns.next(); if (entry.entityClass == entityClass) { spawns.remove(); } } } } @SuppressWarnings("unchecked") public static void removeSpawn(String entityName, EnumCreatureType spawnList, BiomeGenBase... biomes) { Class entityClazz = (Class) EntityList.stringToClassMapping.get(entityName); if (EntityLiving.class.isAssignableFrom(entityClazz)) { removeSpawn((Class ) entityClazz, spawnList, biomes); } } public static int findGlobalUniqueEntityId() { int res = instance().availableIndicies.nextSetBit(0); if (res < 0) { throw new RuntimeException("No more entity indicies left"); } return res; } public EntityRegistration lookupModSpawn(Class clazz, boolean keepLooking) { Class localClazz = clazz; do { EntityRegistration er = entityClassRegistrations.get(localClazz); if (er != null) { return er; } localClazz = localClazz.getSuperclass(); keepLooking = (!Object.class.equals(localClazz)); } while (keepLooking); return null; } public EntityRegistration lookupModSpawn(ModContainer mc, int modEntityId) { for (EntityRegistration er : entityRegistrations.get(mc)) { if (er.getModEntityId() == modEntityId) { return er; } } return null; } public boolean tryTrackingEntity(EntityTracker entityTracker, Entity entity) { EntityRegistration er = lookupModSpawn(entity.getClass(), true); if (er != null) { entityTracker.addEntityToTracker(entity, er.getTrackingRange(), er.getUpdateFrequency(), er.sendsVelocityUpdates()); return true; } return false; } }
-
Alors, je suis peut-être un gros bourrin qui comprend rien mais…
Je fais ça direct dans ma classe principale comme ça:
public static CreativeTabs tabPg3 = new CreativeTabs(CreativeTabs.getNextID(), "J'fais pas d'pub") { @SideOnly(Side.CLIENT) public String getTranslatedTabLabel() { return "J'fais pas d'pub"; } @SideOnly(Side.CLIENT) public Item getTabIconItem() { return Modpg.headHaloDarkR3; } };
Pim pam poum, aucun problème. Est-ce que c’est grave docteur?
-
Oui on peut aussi faire comme ça.
-
j’ai un problème de texture voici se que je vois quand je vais sur mon nouvel onglet.
-
Le chemin que tu as mis pour la texture de fond ne semble pas valide.
-
Ce message a été supprimé ! -
@robin4002 la texture de fond elle est bien décrite par: this.setBackgroundImageName);
c’est quoi le chemin d’accès de la texture de fond des onglets de base de Minecraft? -
la texture de fond elle est bien décrite par: this.setBackgroundImageName;
c’est quoi le chemin d’accès de la texture de fond des onglets de base de minecraft?