Résolu Créer une TNT
-
Bonjour,
Je suis actuellement en train (d’essayer :@) de créer un mod rajoutant des TNT et je n’y arrive pas ! En fait j’ai voulu créer une nouvelle base de TNT pour faciliter la création de nouvelle. Puis j’ai aussi créer une nouvelle base d’ EntityTNTPrimed pour customiser la puissance et le fuse. Ensuite j’ai créer une première TNT à laquelle j’ai doublé la puissance, un onglet et j’ai mis la texture. La texture et l’onglet marchent mais ma TNT explose comme la TNT de base(à moins que j’ai buggé la TNT de base) et lorsqu’on l’allume, elle a la texture de la TNT de base.
Avant
Après
À gauche, TNT normale; à droite TNT doublée.
Plus de screens en pièces jointes.Voici les codes :
- Classe Principale :
package fr.kitek.tntplusplus; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import fr.kitek.tntplusplus.proxy.TutoCommonProxy; 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.network.NetworkMod; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = "tntplusplus", name = "TNT++", version = "1.0.0", acceptedMinecraftVersions = "[1.6.4]") @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class TntMainClass { @SidedProxy(clientSide = "fr.kitek.tntplusplus.proxy.TutoClientProxy", serverSide = "fr.kitek.tntplusplus.proxy.TutoCommonProxy") public static TutoCommonProxy proxy; @Instance("tntplusplus") public static TntMainClass instance; public static Block CompactTNT; public static CreativeTabs TNTab = new TNTab("TNTab"); @EventHandler public void PreInit(FMLPreInitializationEvent event) { // Configuration // Blocks CompactTNT = new CompactTNT(1204).setHardness(1.0F).setResistance(5.0F).setStepSound(Block.soundStoneFootstep) .setUnlocalizedName("compactTNT"); // Items // Achievements } @EventHandler public void Init(FMLInitializationEvent event) { // Registry GameRegistry.registerBlock(CompactTNT, "CompactTNT"); // Mobs // Render proxy.registerRender(); // NetWork // Recipe } @EventHandler public void PostInit(FMLPostInitializationEvent event) { // Intégration avec les autres mods } }
- Classe de la TNT de base custom :
package fr.kitek.tntplusplus; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockTNT; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.Item; import net.minecraft.util.Icon; import net.minecraft.world.Explosion; import net.minecraft.world.World; public class TNTBaseCustom extends Block { protected Icon upside; protected Icon downside; protected float power = 4.0F; protected int delaytime = 80; protected Block hy; public TNTBaseCustom(int id) { super(id, Material.tnt); // this.delaytime = 80; // this.power = 4.0F; } /* * public TNTBaseCustom(int id, float p, int delay) { super(id, * Material.tnt); this.delaytime = delay; this.power = p; } * * public TNTBaseCustom(int id, float p) { super(id, Material.tnt); * this.power = p; this.delaytime = 80; } * * public TNTBaseCustom(int id, int delay) { super(id, Material.tnt); * this.delaytime = delay; this.power = 4.0F; } */ @SideOnly(Side.CLIENT) public Icon getIcon(int side, int metadata) { return side == 0 ? downside : side == 1 ? upside : blockIcon; } // Créer une entity extends enti…Tn.. et redéfinir la méthode explode ? public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) { this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); par1World.setBlockToAir(par2, par3, par4); } } /** * Lets the block know when one of its neighbor changes. Doesn't know which * neighbor changed (coordinates passed are their own) Args: x, y, z, * neighbor blockID */ public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { if (par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) { this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); par1World.setBlockToAir(par2, par3, par4); } } /** * Returns the quantity of items to drop on block destruction. */ public int quantityDropped(Random par1Random) { return 1; } /** * Called upon the block being destroyed by an explosion */ public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4, Explosion par5Explosion) { if (!par1World.isRemote) { EntityTNTPrimedCustom entitytntprimed = new EntityTNTPrimedCustom(par1World, (double) ((float) par2 + 0.5F), (double) ((float) par3 + 0.5F), (double) ((float) par4 + 0.5F), par5Explosion.getExplosivePlacedBy(), power, delaytime, hy); entitytntprimed.fuse = par1World.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8; par1World.spawnEntityInWorld(entitytntprimed); } } /** * Called right before the block is destroyed by a player. Args: world, x, * y, z, metaData */ public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) { this.primeTnt(par1World, par2, par3, par4, par5, (EntityLivingBase) null); } /** * spawns the primed tnt and plays the fuse sound. */ public void primeTnt(World par1World, int par2, int par3, int par4, int par5, EntityLivingBase par6EntityLivingBase) { if (!par1World.isRemote) { if ((par5 & 1) == 1) { EntityTNTPrimedCustom entitytntprimed = new EntityTNTPrimedCustom(par1World, (double) ((float) par2 + 0.5F), (double) ((float) par3 + 0.5F), (double) ((float) par4 + 0.5F), par6EntityLivingBase, power, delaytime, hy); par1World.spawnEntityInWorld(entitytntprimed); par1World.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F); } } } /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if (par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.itemID) { this.primeTnt(par1World, par2, par3, par4, 1, par5EntityPlayer); par1World.setBlockToAir(par2, par3, par4); par5EntityPlayer.getCurrentEquippedItem().damageItem(1, par5EntityPlayer); return true; } else { return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9); } } /** * Triggered whenever an entity collides with this block (enters into the * block). Args: world, x, y, z, entity */ public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) { if (par5Entity instanceof EntityArrow && !par1World.isRemote) { EntityArrow entityarrow = (EntityArrow) par5Entity; if (entityarrow.isBurning()) { this.primeTnt(par1World, par2, par3, par4, 1, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase) entityarrow.shootingEntity : null); par1World.setBlockToAir(par2, par3, par4); } } } /** * Return whether this block can drop from an explosion. */ public boolean canDropFromExplosion(Explosion par1Explosion) { return false; } }
- Classe de la TNT doublée :
package fr.kitek.tntplusplus; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; public class CompactTNT extends TNTBaseCustom { // float power = 8.0F; // Block hy = TntMainClass.CompactTNT; public CompactTNT(int id) { super(id); this.setCreativeTab(TntMainClass.TNTab); this.power = 8.0F; this.hy = TntMainClass.CompactTNT; } public void registerIcons(IconRegister iconRegister) { blockIcon = iconRegister.registerIcon("tntplusplus:CompactTNT"); upside = iconRegister.registerIcon("tntplusplus:CompactTNT_up"); downside = iconRegister.registerIcon("tntplusplus:CompactTNT_down"); } }
- Classe de la TNT Primed Custom :
package fr.kitek.tntplusplus; import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityTNTPrimed; import net.minecraft.world.World; public class EntityTNTPrimedCustom extends EntityTNTPrimed { Block type; float p; private EntityLivingBase tntPlacedBy; public EntityTNTPrimedCustom(World par1World) { super(par1World); // TODO Auto-generated constructor stub } public EntityTNTPrimedCustom(World par1World, double par2, double par4, double par6, EntityLivingBase par8EntityLivingBase, float power, int delay, Block i) { super(par1World, par2, par4, par6, par8EntityLivingBase); this.p = power; this.fuse = delay; this.type = i; // TODO Auto-generated constructor stub } private void explode() { this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, p, true); } }
- Render de la TNT Primed Custom :
package fr.kitek.tntplusplus; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) public class RenderTNTPrimedCustom extends Render { private RenderBlocks blockRenderer = new RenderBlocks(); private Block texture; public RenderTNTPrimedCustom() { this.shadowSize = 0.5F; } public void renderPrimedTNTCustom(EntityTNTPrimedCustom par1EntityTNTPrimed, double par2, double par4, double par6, float par8, float par9) { this.texture = par1EntityTNTPrimed.type; GL11.glPushMatrix(); GL11.glTranslatef((float) par2, (float) par4, (float) par6); float f2; if ((float) par1EntityTNTPrimed.fuse - par9 + 1.0F < 10.0F) { f2 = 1.0F - ((float) par1EntityTNTPrimed.fuse - par9 + 1.0F) / 10.0F; if (f2 < 0.0F) { f2 = 0.0F; } if (f2 > 1.0F) { f2 = 1.0F; } f2 *= f2; f2 *= f2; float f3 = 1.0F + f2 * 0.3F; GL11.glScalef(f3, f3, f3); } f2 = (1.0F - ((float) par1EntityTNTPrimed.fuse - par9 + 1.0F) / 100.0F) * 0.8F; this.bindEntityTexture(par1EntityTNTPrimed); this.blockRenderer.renderBlockAsItem(texture, 0, par1EntityTNTPrimed.getBrightness(par9)); if (par1EntityTNTPrimed.fuse / 5 % 2 == 0) { GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA); GL11.glColor4f(1.0F, 1.0F, 1.0F, f2); this.blockRenderer.renderBlockAsItem(texture, 0, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_TEXTURE_2D); } GL11.glPopMatrix(); } protected ResourceLocation getTNTPrimedCustomTextures(EntityTNTPrimedCustom par1EntityTNTPrimed) { return TextureMap.locationBlocksTexture; } /** * Returns the location of an entity's texture. Doesn't seem to be called * unless you call Render.bindEntityTexture. */ @Override protected ResourceLocation getEntityTexture(Entity par1Entity) { return this.getTNTPrimedCustomTextures((EntityTNTPrimedCustom) par1Entity); } /** * Actually renders the given argument. This is a synthetic bridge method, * always casting down its argument and then handing it off to a worker * function which does the actual work. In all probabilty, the class Render * is generic (Render <t extends="" entity)="" and="" this="" method="" has="" signature="" public<br="">* void doRender(T entity, double d, double d1, double d2, float f, float * f1). But JAD is pre 1.5 so doesn't do that. */ public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) { this.renderPrimedTNTCustom((EntityTNTPrimedCustom) par1Entity, par2, par4, par6, par8, par9); } } ```</t>
- ClientProxy :
package fr.kitek.tntplusplus.proxy; import cpw.mods.fml.client.registry.RenderingRegistry; import fr.kitek.tntplusplus.EntityTNTPrimedCustom; import fr.kitek.tntplusplus.RenderTNTPrimedCustom; public class TutoClientProxy extends TutoCommonProxy { public void registerRender() { // TODO Auto-generated method stub // ici mes futurs client registry RenderingRegistry.registerEntityRenderingHandler(EntityTNTPrimedCustom.class, new RenderTNTPrimedCustom()); } }
PS : Sur les screens , il n’y a qu’une couche d’herbe, c’est parce que je testais sur un ordinateur sous-performant.
Pourriez-vous m’expliquer ce que je dois faire ?:huh: Merci
Pour les commentaires, c’est parce que j’essayais des trucs et que je me rendais compte que j’avais écrit n’importe quoi. - Classe Principale :
-
protected float power = 4.0F;
En lisant ton code, tu utilise cette variable pour la puissance d’explosion (TNTBaseCustom.java) et comme 4.0 est la même valeur que la tnt par défaut, normal que ça n’explose pas plus.
-
J’ai remplacé
java protected float power = 4.0F;
par ```java
protected float power;Changements dans la classe CompactTNT : ```java package fr.kitek.tntplusplus; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; public class CompactTNT extends TNTBaseCustom { // float power = 8.0F; // Block hy = TntMainClass.CompactTNT; public CompactTNT(int id) { super(id); this.setCreativeTab(TntMainClass.TNTab); this.power = 8.0F; this.hy = TntMainClass.CompactTNT; this.delaytime = 80; } public void registerIcons(IconRegister iconRegister) { blockIcon = iconRegister.registerIcon("tntplusplus:CompactTNT"); upside = iconRegister.registerIcon("tntplusplus:CompactTNT_up"); downside = iconRegister.registerIcon("tntplusplus:CompactTNT_down"); } }
Changements pour la classe TNTBaseCustom :
package fr.kitek.tntplusplus; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockTNT; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.Item; import net.minecraft.util.Icon; import net.minecraft.world.Explosion; import net.minecraft.world.World; public class TNTBaseCustom extends Block { protected Icon upside; protected Icon downside; protected float power; protected int delaytime; protected Block hy; public TNTBaseCustom(int id) { super(id, Material.tnt); // this.delaytime = 80; // this.power = 4.0F; } /* public TNTBaseCustom(int id, float p, int delay) { super(id, Material.tnt); this.delaytime = delay; this.power = p; } public TNTBaseCustom(int id, float p) { super(id, Material.tnt); this.power = p; this.delaytime = 80; } public TNTBaseCustom(int id, int delay) { super(id, Material.tnt); this.delaytime = delay; this.power = 4.0F; } */ @SideOnly(Side.CLIENT) public Icon getIcon(int side, int metadata) { return side == 0 ? downside : side == 1 ? upside : blockIcon; } // Créer une entity extends enti…Tn.. et redéfinir la méthode explode ? public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); if(par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) { this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); par1World.setBlockToAir(par2, par3, par4); } } /** * Lets the block know when one of its neighbor changes. Doesn't know which * neighbor changed (coordinates passed are their own) Args: x, y, z, * neighbor blockID */ public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { if(par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) { this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); par1World.setBlockToAir(par2, par3, par4); } } /** * Returns the quantity of items to drop on block destruction. */ public int quantityDropped(Random par1Random) { return 1; } /** * Called upon the block being destroyed by an explosion */ public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4, Explosion par5Explosion) { if(!par1World.isRemote) { EntityTNTPrimedCustom entitytntprimed = new EntityTNTPrimedCustom(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par5Explosion.getExplosivePlacedBy(), power, delaytime, hy); entitytntprimed.fuse = par1World.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8; par1World.spawnEntityInWorld(entitytntprimed); } } /** * Called right before the block is destroyed by a player. Args: world, x, * y, z, metaData */ public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) { this.primeTnt(par1World, par2, par3, par4, par5, (EntityLivingBase)null); } /** * spawns the primed tnt and plays the fuse sound. */ public void primeTnt(World par1World, int par2, int par3, int par4, int par5, EntityLivingBase par6EntityLivingBase) { if(!par1World.isRemote) { if((par5 & 1) == 1) { EntityTNTPrimedCustom entitytntprimed = new EntityTNTPrimedCustom(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par6EntityLivingBase, power, delaytime, hy); par1World.spawnEntityInWorld(entitytntprimed); par1World.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F); } } } /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if(par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.itemID) { this.primeTnt(par1World, par2, par3, par4, 1, par5EntityPlayer); par1World.setBlockToAir(par2, par3, par4); par5EntityPlayer.getCurrentEquippedItem().damageItem(1, par5EntityPlayer); return true; } else { return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9); } } /** * Triggered whenever an entity collides with this block (enters into the * block). Args: world, x, y, z, entity */ public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) { if(par5Entity instanceof EntityArrow && !par1World.isRemote) { EntityArrow entityarrow = (EntityArrow)par5Entity; if(entityarrow.isBurning()) { this.primeTnt(par1World, par2, par3, par4, 1, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase)entityarrow.shootingEntity : null); par1World.setBlockToAir(par2, par3, par4); } } } /** * Return whether this block can drop from an explosion. */ public boolean canDropFromExplosion(Explosion par1Explosion) { return false; } }
-
en ce qui concerne la texture de la TNT fuse je pense que c’est à cause de l’extends étant donné que c’est géré par les packets en vanilla non?
-
Merci totos51. J’ai copié tout le code, enlevé l’extend et réglé les méthodes et maintenant, ma TNT explose beaucoup plus fort :
Mais bizarrement ! Et maintenant, quand je l’allume, elle est invisible ce qui prouve que tu avais raison.
Code de l’EntityTNTPrimedCustom :
package fr.kitek.tntplusplus; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class EntityTNTPrimedCustom extends Entity { Block type; float p; private EntityLivingBase tntPlacedBy1; /** How long the fuse is */ public int fuse; public EntityTNTPrimedCustom(World par1World) { super(par1World); this.preventEntitySpawning = true; this.setSize(0.98F, 0.98F); this.yOffset = this.height / 2.0F; } public EntityTNTPrimedCustom(World par1World, double par2, double par4, double par6, EntityLivingBase par8EntityLivingBase, float power, int delay, Block i) { this(par1World); this.setPosition(par2, par4, par6); float f = (float)(Math.random() * Math.PI * 2.0D); this.motionX = (double)(-((float)Math.sin((double)f)) * 0.02F); this.motionY = 0.20000000298023224D; this.motionZ = (double)(-((float)Math.cos((double)f)) * 0.02F); this.p = power; this.fuse = delay; this.type = i; this.prevPosX = par2; this.prevPosY = par4; this.prevPosZ = par6; this.tntPlacedBy1 = par8EntityLivingBase; } protected void entityInit() {} /** * returns if this entity triggers Block.onEntityWalking on the blocks they * walk on. used for spiders and wolves to prevent them from trampling crops */ protected boolean canTriggerWalking() { return false; } /** * Returns true if other Entities should be prevented from moving through * this Entity. */ public boolean canBeCollidedWith() { return !this.isDead; } /** * Called to update the entity's position/logic. */ public void onUpdate() { this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; this.motionY -= 0.03999999910593033D; this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.9800000190734863D; this.motionY *= 0.9800000190734863D; this.motionZ *= 0.9800000190734863D; if(this.onGround) { this.motionX *= 0.699999988079071D; this.motionZ *= 0.699999988079071D; this.motionY *= -0.5D; } if(this.fuse– <= 0) { this.setDead(); if(!this.worldObj.isRemote) { this.explode(); } } else { this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); } } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { par1NBTTagCompound.setByte("Fuse", (byte)this.fuse); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { this.fuse = par1NBTTagCompound.getByte("Fuse"); } @SideOnly(Side.CLIENT) public float getShadowSize() { return 0.0F; } /** * returns null or the entityliving it was placed or ignited by */ public EntityLivingBase getTntPlacedBy() { return this.tntPlacedBy1; } private void explode() { this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, p, true); } }
-
Tu n’enregistre pas tes entités. Regarde le tuto sur les bases des entités
-
j’en avais fais une en vanilla, c’était assez chiant et je me suis heurté aux même soucis, faut voir avec les packets je pense, mais d’autres ici seront meilleurs que moi pour t’aider
-
Il y avait déjà une discussion à propos du rendu de la tnt : http://www.minecraftforgefrance.fr/showthread.php?tid=394&pid=4220#pid4220
-
Désolé et merci.
J’ai rajouté les trucs pour enregistrer l’entité et ce qu’il y avait dans la discussion pour le powderbarrel mais ça crashe maintenant !:(
Code de l’Entity :package fr.kitek.tntplusplus; import com.google.common.io.*; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class EntityTNTPrimedCustom extends Entity implements IEntityAdditionalSpawnData { Block type; float p; private EntityLivingBase tntPlacedBy1; /** How long the fuse is */ public int fuse; public EntityTNTPrimedCustom(World par1World) { super(par1World); this.preventEntitySpawning = true; this.setSize(0.98F, 0.98F); this.yOffset = this.height / 2.0F; } public EntityTNTPrimedCustom(World par1World, double par2, double par4, double par6, EntityLivingBase par8EntityLivingBase, float power, int delay, Block i) { this(par1World); this.setPosition(par2, par4, par6); float f = (float)(Math.random() * Math.PI * 2.0D); this.motionX = (double)(-((float)Math.sin((double)f)) * 0.02F); this.motionY = 0.20000000298023224D; this.motionZ = (double)(-((float)Math.cos((double)f)) * 0.02F); this.p = power; this.fuse = delay; this.type = i; this.prevPosX = par2; this.prevPosY = par4; this.prevPosZ = par6; this.tntPlacedBy1 = par8EntityLivingBase; } @Override public void writeSpawnData(ByteArrayDataOutput data) { data.writeInt(this.fuse); } @Override public void readSpawnData(ByteArrayDataInput data) { this.fuse = data.readInt(); } protected void entityInit() {} /** * returns if this entity triggers Block.onEntityWalking on the blocks they * walk on. used for spiders and wolves to prevent them from trampling crops */ protected boolean canTriggerWalking() { return false; } /** * Returns true if other Entities should be prevented from moving through * this Entity. */ public boolean canBeCollidedWith() { return !this.isDead; } /** * Called to update the entity's position/logic. */ public void onUpdate() { this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; this.motionY -= 0.03999999910593033D; this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.9800000190734863D; this.motionY *= 0.9800000190734863D; this.motionZ *= 0.9800000190734863D; if(this.onGround) { this.motionX *= 0.699999988079071D; this.motionZ *= 0.699999988079071D; this.motionY *= -0.5D; } if(this.fuse– <= 0) { this.setDead(); if(!this.worldObj.isRemote) { this.explode(); } } else { this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); } } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { par1NBTTagCompound.setByte("Fuse", (byte)this.fuse); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { this.fuse = par1NBTTagCompound.getByte("Fuse"); } @SideOnly(Side.CLIENT) public float getShadowSize() { return 0.0F; } /** * returns null or the entityliving it was placed or ignited by */ public EntityLivingBase getTntPlacedBy() { return this.tntPlacedBy1; } private void explode() { this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, p, true); } }
Code de la classe principale :
package fr.kitek.tntplusplus; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import fr.kitek.tntplusplus.proxy.TutoCommonProxy; 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.network.NetworkMod; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = "tntplusplus", name = "TNT++", version = "1.0.0", acceptedMinecraftVersions = "[1.6.4]") @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class TntMainClass { @SidedProxy(clientSide = "fr.kitek.tntplusplus.proxy.TutoClientProxy", serverSide = "fr.kitek.tntplusplus.proxy.TutoCommonProxy") public static TutoCommonProxy proxy; @Instance("tntplusplus") public static TntMainClass instance; public static Block CompactTNT; public static CreativeTabs TNTab = new TNTab("TNTab"); @EventHandler public void PreInit(FMLPreInitializationEvent event) { // Configuration // Blocks CompactTNT = new CompactTNT(1204).setHardness(1.0F).setResistance(5.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("compactTNT"); // Items // Achievements } @EventHandler public void Init(FMLInitializationEvent event) { // Registry GameRegistry.registerBlock(CompactTNT, "CompactTNT"); // Mobs EntityRegistry.registerModEntity(EntityTNTPrimedCustom.class, "tntprimedcustom", 201, this.instance, 256, 1, true); // Render proxy.registerRender(); // NetWork // Recipe } @EventHandler public void PostInit(FMLPostInitializationEvent event) { // Intégration avec les autres mods } }
Voici le crash :
2014-03-23 15:42:48 [INFO] [Minecraft-Server] Stopping server 2014-03-23 15:42:48 [INFO] [Minecraft-Server] Saving players 2014-03-23 15:42:48 [INFO] [Minecraft-Server] Sayac12 left the game 2014-03-23 15:42:48 [INFO] [Minecraft-Server] Saving worlds 2014-03-23 15:42:48 [INFO] [Minecraft-Server] Saving chunks for level 'ghvcfg'/Overworld 2014-03-23 15:42:48 [INFO] [Minecraft-Server] Saving chunks for level 'ghvcfg'/Nether 2014-03-23 15:42:48 [INFO] [Minecraft-Server] Saving chunks for level 'ghvcfg'/The End 2014-03-23 15:42:48 [INFO] [ForgeModLoader] Unloading dimension 0 2014-03-23 15:42:48 [INFO] [ForgeModLoader] Unloading dimension -1 2014-03-23 15:42:48 [INFO] [ForgeModLoader] Unloading dimension 1 2014-03-23 15:42:50 [INFO] [STDERR] net.minecraft.util.ReportedException: Rendering entity in world 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.renderer.entity.RenderManager.renderEntityWithPosYaw(RenderManager.java:339) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:281) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:524) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1160) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1006) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:946) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:838) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.main.Main.main(Main.java:93) 2014-03-23 15:42:50 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2014-03-23 15:42:50 [INFO] [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDERR] at java.lang.reflect.Method.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2014-03-23 15:42:50 [INFO] [STDERR] Caused by: java.lang.NullPointerException 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.renderer.RenderBlocks.renderBlockAsItem(RenderBlocks.java:7623) 2014-03-23 15:42:50 [INFO] [STDERR] at fr.kitek.tntplusplus.RenderTNTPrimedCustom.renderPrimedTNTCustom(RenderTNTPrimedCustom.java:53) 2014-03-23 15:42:50 [INFO] [STDERR] at fr.kitek.tntplusplus.RenderTNTPrimedCustom.doRender(RenderTNTPrimedCustom.java:97) 2014-03-23 15:42:50 [INFO] [STDERR] at net.minecraft.client.renderer.entity.RenderManager.renderEntityWithPosYaw(RenderManager.java:312) 2014-03-23 15:42:50 [INFO] [STDERR] … 13 more 2014-03-23 15:42:50 [INFO] [STDOUT] –-- Minecraft Crash Report ---- 2014-03-23 15:42:50 [INFO] [STDOUT] // Shall we play a game? 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] Time: 23/03/14 15:42 2014-03-23 15:42:50 [INFO] [STDOUT] Description: Rendering entity in world 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] java.lang.NullPointerException 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.RenderBlocks.renderBlockAsItem(RenderBlocks.java:7623) 2014-03-23 15:42:50 [INFO] [STDOUT] at fr.kitek.tntplusplus.RenderTNTPrimedCustom.renderPrimedTNTCustom(RenderTNTPrimedCustom.java:53) 2014-03-23 15:42:50 [INFO] [STDOUT] at fr.kitek.tntplusplus.RenderTNTPrimedCustom.doRender(RenderTNTPrimedCustom.java:97) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.entity.RenderManager.renderEntityWithPosYaw(RenderManager.java:312) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:281) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:524) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1160) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1006) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:946) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.Minecraft.run(Minecraft.java:838) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.main.Main.main(Main.java:93) 2014-03-23 15:42:50 [INFO] [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2014-03-23 15:42:50 [INFO] [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDOUT] at java.lang.reflect.Method.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] A detailed walkthrough of the error, its code path and all known details is as follows: 2014-03-23 15:42:50 [INFO] [STDOUT] –------------------------------------------------------------------------------------- 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] – Head -- 2014-03-23 15:42:50 [INFO] [STDOUT] Stacktrace: 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.RenderBlocks.renderBlockAsItem(RenderBlocks.java:7623) 2014-03-23 15:42:50 [INFO] [STDOUT] at fr.kitek.tntplusplus.RenderTNTPrimedCustom.renderPrimedTNTCustom(RenderTNTPrimedCustom.java:53) 2014-03-23 15:42:50 [INFO] [STDOUT] at fr.kitek.tntplusplus.RenderTNTPrimedCustom.doRender(RenderTNTPrimedCustom.java:97) 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] – Entity being rendered -- 2014-03-23 15:42:50 [INFO] [STDOUT] Details: 2014-03-23 15:42:50 [INFO] [STDOUT] Entity Type: tntplusplus.tntprimedcustom (fr.kitek.tntplusplus.EntityTNTPrimedCustom) 2014-03-23 15:42:50 [INFO] [STDOUT] Entity ID: 1232 2014-03-23 15:42:50 [INFO] [STDOUT] Entity Name: entity.tntplusplus.tntprimedcustom.name 2014-03-23 15:42:50 [INFO] [STDOUT] Entity's Exact location: -326,50, 1,69, -1607,53 2014-03-23 15:42:50 [INFO] [STDOUT] Entity's Block location: World: (-327,1,-1608), Chunk: (at 9,0,8 in -21,-101; contains blocks -336,0,-1616 to -321,255,-1601), Region: (-1,-4; contains chunks -32,-128 to -1,-97, blocks -512,0,-2048 to -1,255,-1537) 2014-03-23 15:42:50 [INFO] [STDOUT] Entity's Momentum: -0,00, 0,07, -0,02 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] – Renderer details -- 2014-03-23 15:42:50 [INFO] [STDOUT] Details: 2014-03-23 15:42:50 [INFO] [STDOUT] Assigned renderer: fr.kitek.tntplusplus.RenderTNTPrimedCustom@1f5b911 2014-03-23 15:42:50 [INFO] [STDOUT] Location: -0,48,-0,66,1,82 - World: (-1,-1,1), Chunk: (at 15,-1,1 in -1,0; contains blocks -16,0,0 to -1,255,15), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511) 2014-03-23 15:42:50 [INFO] [STDOUT] Rotation: 0.0 2014-03-23 15:42:50 [INFO] [STDOUT] Delta: 0.10619569 2014-03-23 15:42:50 [INFO] [STDOUT] Stacktrace: 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.entity.RenderManager.renderEntityWithPosYaw(RenderManager.java:312) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.entity.RenderManager.renderEntity(RenderManager.java:281) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.RenderGlobal.renderEntities(RenderGlobal.java:524) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1160) 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] – Affected level -- 2014-03-23 15:42:50 [INFO] [STDOUT] Details: 2014-03-23 15:42:50 [INFO] [STDOUT] Level name: MpServer 2014-03-23 15:42:50 [INFO] [STDOUT] All players: 1 total; [EntityClientPlayerMP['Sayac12'/17, l='MpServer', x=-326,02, y=2,62, z=-1609,33]] 2014-03-23 15:42:50 [INFO] [STDOUT] Chunk stats: MultiplayerChunkCache: 441 2014-03-23 15:42:50 [INFO] [STDOUT] Level seed: 0 2014-03-23 15:42:50 [INFO] [STDOUT] Level generator: ID 01 - flat, ver 0\. Features enabled: false 2014-03-23 15:42:50 [INFO] [STDOUT] Level generator options: 2014-03-23 15:42:50 [INFO] [STDOUT] Level spawn location: World: (-340,4,-1645), Chunk: (at 12,0,3 in -22,-103; contains blocks -352,0,-1648 to -337,255,-1633), Region: (-1,-4; contains chunks -32,-128 to -1,-97, blocks -512,0,-2048 to -1,255,-1537) 2014-03-23 15:42:50 [INFO] [STDOUT] Level time: 13477 game time, 13477 day time 2014-03-23 15:42:50 [INFO] [STDOUT] Level dimension: 0 2014-03-23 15:42:50 [INFO] [STDOUT] Level storage version: 0x00000 - Unknown? 2014-03-23 15:42:50 [INFO] [STDOUT] Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) 2014-03-23 15:42:50 [INFO] [STDOUT] Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false 2014-03-23 15:42:50 [INFO] [STDOUT] Forced entities: 11 total; [EntityTNTPrimedCustom['entity.tntplusplus.tntprimedcustom.name'/1232, l='MpServer', x=-326,50, y=1,69, z=-1607,53], EntityItem['item.tile.dirt'/4, l='MpServer', x=-354,94, y=1,13, z=-1617,13], EntitySheep['Sheep'/5, l='MpServer', x=-358,84, y=1,00, z=-1596,91], EntityClientPlayerMP['Sayac12'/17, l='MpServer', x=-326,02, y=2,62, z=-1609,33], EntitySheep['Sheep'/6, l='MpServer', x=-344,97, y=1,00, z=-1571,09], EntitySheep['Sheep'/7, l='MpServer', x=-349,41, y=1,00, z=-1581,47], EntitySheep['Sheep'/8, l='MpServer', x=-343,16, y=1,00, z=-1581,75], EntitySheep['Sheep'/9, l='MpServer', x=-276,88, y=1,00, z=-1565,06], EntitySheep['Sheep'/10, l='MpServer', x=-274,81, y=1,00, z=-1551,63], EntitySheep['Sheep'/11, l='MpServer', x=-260,09, y=1,00, z=-1562,09], EntitySheep['Sheep'/12, l='MpServer', x=-267,03, y=1,00, z=-1551,94]] 2014-03-23 15:42:50 [INFO] [STDOUT] Retry entities: 0 total; [] 2014-03-23 15:42:50 [INFO] [STDOUT] Server brand: fml,forge 2014-03-23 15:42:50 [INFO] [STDOUT] Server type: Integrated singleplayer server 2014-03-23 15:42:50 [INFO] [STDOUT] Stacktrace: 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:440) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2312) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.Minecraft.run(Minecraft.java:856) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.client.main.Main.main(Main.java:93) 2014-03-23 15:42:50 [INFO] [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 2014-03-23 15:42:50 [INFO] [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDOUT] at java.lang.reflect.Method.invoke(Unknown Source) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.launchwrapper.Launch.launch(Launch.java:131) 2014-03-23 15:42:50 [INFO] [STDOUT] at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2014-03-23 15:42:50 [INFO] [STDOUT] 2014-03-23 15:42:50 [INFO] [STDOUT] – System Details -- 2014-03-23 15:42:50 [INFO] [STDOUT] Details: 2014-03-23 15:42:50 [INFO] [STDOUT] Minecraft Version: 1.6.4 2014-03-23 15:42:50 [INFO] [STDOUT] Operating System: Windows 8 (x86) version 6.2 2014-03-23 15:42:50 [INFO] [STDOUT] Java Version: 1.7.0_51, Oracle Corporation 2014-03-23 15:42:50 [INFO] [STDOUT] Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation 2014-03-23 15:42:50 [INFO] [STDOUT] Memory: 758665240 bytes (723 MB) / 1046937600 bytes (998 MB) up to 1046937600 bytes (998 MB) 2014-03-23 15:42:50 [INFO] [STDOUT] JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M 2014-03-23 15:42:50 [INFO] [STDOUT] AABB Pool Size: 9463 (529928 bytes; 0 MB) allocated, 281 (15736 bytes; 0 MB) used 2014-03-23 15:42:50 [INFO] [STDOUT] Suspicious classes: FML and Forge are installed 2014-03-23 15:42:50 [INFO] [STDOUT] IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 2014-03-23 15:42:50 [INFO] [STDOUT] FML: MCP v8.11 FML v6.4.45.953 Minecraft Forge 9.11.1.953 4 mods loaded, 4 mods active 2014-03-23 15:42:50 [INFO] [STDOUT] mcp{8.09} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-03-23 15:42:50 [INFO] [STDOUT] FML{6.4.45.953} [Forge Mod Loader] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-03-23 15:42:50 [INFO] [STDOUT] Forge{9.11.1.953} [Minecraft Forge] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-03-23 15:42:50 [INFO] [STDOUT] tntplusplus{1.0.0} [TNT++] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available 2014-03-23 15:42:50 [INFO] [STDOUT] Launched Version: 1.6 2014-03-23 15:42:50 [INFO] [STDOUT] LWJGL: 2.9.0 2014-03-23 15:42:50 [INFO] [STDOUT] OpenGL: Intel Pineview Platform GL version 1.4.0 - Build 8.14.10.2230, Intel 2014-03-23 15:42:50 [INFO] [STDOUT] Is Modded: Definitely; Client brand changed to 'fml,forge' 2014-03-23 15:42:50 [INFO] [STDOUT] Type: Client (map_client.txt) 2014-03-23 15:42:50 [INFO] [STDOUT] Resource Pack: Default 2014-03-23 15:42:50 [INFO] [STDOUT] Current Language: English (US) 2014-03-23 15:42:50 [INFO] [STDOUT] Profiler Position: N/A (disabled) 2014-03-23 15:42:50 [INFO] [STDOUT] Vec3 Pool Size: 213 (11928 bytes; 0 MB) allocated, 115 (6440 bytes; 0 MB) used 2014-03-23 15:42:50 [INFO] [STDOUT] #@!@# Game crashed! Crash report saved to: #@!@# C:\Users\Sayac\Downloads\forge\mcp\jars\.\crash-reports\crash-2014-03-23_15.42.50-client.txt AL lib: (EE) alc_cleanup: 1 device not closed
L’erreur vient du render, non ?
-
RenderTNTPrimed?Custom
Je peux avoir cette classe ? -
Elle est en haut.
-
Replace :
this.blockRenderer.renderBlockAsItem(texture, 0, par1EntityTNTPrimed.getBrightness(par9));
par
this.blockRenderer.renderBlockAsItem(TaClassePrincipale.leBlocDeTNT, 0, par1EntityTNTPrimed.getBrightness(par9));
Et tu peux supprimer la variable texture.
-
En fait c’était fait exprès pour que je puisse mettre le même render pour chaque type de mes futures TNT.
Mais tu pense que c’est ça qui le fait crasher ?
Sinon je sais pas si c’est à cause de ça mais j’ai pas encore mis la texture CompactTNT_down(flemme). -
Si, tu peux le faire, mais dans ce cas il faut initialisé la variable, car actuellement elle est null, d’où le NullPointerException.
Donc dans ton proxy :
RenderingRegistry.registerEntityRenderingHandler(EntityTNTPrimedCustom.class, new RenderTNTPrimedCustom(TntMainClass.CompactTNT));
Et dans ta classe RenderTNTPrimedCustom, ton constructeur devient :public RenderTNTPrimedCustom(Block block) { this.shadowSize = 0.5F; this.texture = block; }
-
Mais si je fais ça, comment je fais pour les textures des autres TNTs que je ferai ?
Au cas-où, voilà les dernières versions des classes :
Classe principale :package fr.kitek.tntplusplus; import net.minecraft.block.Block; import net.minecraft.creativetab.CreativeTabs; import fr.kitek.tntplusplus.proxy.TutoCommonProxy; 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.network.NetworkMod; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = "tntplusplus", name = "TNT++", version = "1.0.0", acceptedMinecraftVersions = "[1.6.4]") @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class TntMainClass { @SidedProxy(clientSide = "fr.kitek.tntplusplus.proxy.TutoClientProxy", serverSide = "fr.kitek.tntplusplus.proxy.TutoCommonProxy") public static TutoCommonProxy proxy; @Instance("tntplusplus") public static TntMainClass instance; public static Block CompactTNT; public static CreativeTabs TNTab = new TNTab("TNTab"); @EventHandler public void PreInit(FMLPreInitializationEvent event) { // Configuration // Blocks CompactTNT = new CompactTNT(1204).setHardness(1.0F).setResistance(5.0F).setStepSound(Block.soundStoneFootstep).setUnlocalizedName("compactTNT"); // Items // Achievements } @EventHandler public void Init(FMLInitializationEvent event) { // Registry GameRegistry.registerBlock(CompactTNT, "CompactTNT"); // Mobs EntityRegistry.registerModEntity(EntityTNTPrimedCustom.class, "tntprimedcustom", 201, this.instance, 256, 1, true); // Render proxy.registerRender(); // NetWork // Recipe } @EventHandler public void PostInit(FMLPostInitializationEvent event) { // Intégration avec les autres mods } }
Classe de la TNTBaseCustom :
package fr.kitek.tntplusplus; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockTNT; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.projectile.EntityArrow; import net.minecraft.item.Item; import net.minecraft.util.Icon; import net.minecraft.world.Explosion; import net.minecraft.world.World; public class TNTBaseCustom extends Block { protected Icon upside; protected Icon downside; protected float power; protected int delaytime; protected Block hy; public TNTBaseCustom(int id) { super(id, Material.tnt); // this.delaytime = 80; // this.power = 4.0F; } /* public TNTBaseCustom(int id, float p, int delay) { super(id, Material.tnt); this.delaytime = delay; this.power = p; } public TNTBaseCustom(int id, float p) { super(id, Material.tnt); this.power = p; this.delaytime = 80; } public TNTBaseCustom(int id, int delay) { super(id, Material.tnt); this.delaytime = delay; this.power = 4.0F; } */ @SideOnly(Side.CLIENT) public Icon getIcon(int side, int metadata) { return side == 0 ? downside : side == 1 ? upside : blockIcon; } // Créer une entity extends enti…Tn.. et redéfinir la méthode explode ? public void onBlockAdded(World par1World, int par2, int par3, int par4) { super.onBlockAdded(par1World, par2, par3, par4); if(par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) { this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); par1World.setBlockToAir(par2, par3, par4); } } /** * Lets the block know when one of its neighbor changes. Doesn't know which * neighbor changed (coordinates passed are their own) Args: x, y, z, * neighbour blockID */ public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) { if(par1World.isBlockIndirectlyGettingPowered(par2, par3, par4)) { this.onBlockDestroyedByPlayer(par1World, par2, par3, par4, 1); par1World.setBlockToAir(par2, par3, par4); } } /** * Returns the quantity of items to drop on block destruction. */ public int quantityDropped(Random par1Random) { return 1; } /** * Called upon the block being destroyed by an explosion */ public void onBlockDestroyedByExplosion(World par1World, int par2, int par3, int par4, Explosion par5Explosion) { if(!par1World.isRemote) { EntityTNTPrimedCustom entitytntprimed = new EntityTNTPrimedCustom(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par5Explosion.getExplosivePlacedBy(), power, delaytime, hy); entitytntprimed.fuse = par1World.rand.nextInt(entitytntprimed.fuse / 4) + entitytntprimed.fuse / 8; par1World.spawnEntityInWorld(entitytntprimed); } } /** * Called right before the block is destroyed by a player. Args: world, x, * y, z, metaData */ public void onBlockDestroyedByPlayer(World par1World, int par2, int par3, int par4, int par5) { this.primeTnt(par1World, par2, par3, par4, par5, (EntityLivingBase)null); } /** * spawns the primed tnt and plays the fuse sound. */ public void primeTnt(World par1World, int par2, int par3, int par4, int par5, EntityLivingBase par6EntityLivingBase) { if(!par1World.isRemote) { if((par5 & 1) == 1) { EntityTNTPrimedCustom entitytntprimed = new EntityTNTPrimedCustom(par1World, (double)((float)par2 + 0.5F), (double)((float)par3 + 0.5F), (double)((float)par4 + 0.5F), par6EntityLivingBase, power, delaytime, hy); par1World.spawnEntityInWorld(entitytntprimed); par1World.playSoundAtEntity(entitytntprimed, "random.fuse", 1.0F, 1.0F); } } } /** * Called upon block activation (right click on the block.) */ public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9) { if(par5EntityPlayer.getCurrentEquippedItem() != null && par5EntityPlayer.getCurrentEquippedItem().itemID == Item.flintAndSteel.itemID) { this.primeTnt(par1World, par2, par3, par4, 1, par5EntityPlayer); par1World.setBlockToAir(par2, par3, par4); par5EntityPlayer.getCurrentEquippedItem().damageItem(1, par5EntityPlayer); return true; } else { return super.onBlockActivated(par1World, par2, par3, par4, par5EntityPlayer, par6, par7, par8, par9); } } /** * Triggered whenever an entity collides with this block (enters into the * block). Args: world, x, y, z, entity */ public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity) { if(par5Entity instanceof EntityArrow && !par1World.isRemote) { EntityArrow entityarrow = (EntityArrow)par5Entity; if(entityarrow.isBurning()) { this.primeTnt(par1World, par2, par3, par4, 1, entityarrow.shootingEntity instanceof EntityLivingBase ? (EntityLivingBase)entityarrow.shootingEntity : null); par1World.setBlockToAir(par2, par3, par4); } } } /** * Return whether this block can drop from an explosion. */ public boolean canDropFromExplosion(Explosion par1Explosion) { return false; } }
Classe de la CompactTNT :
package fr.kitek.tntplusplus; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; public class CompactTNT extends TNTBaseCustom { // float power = 8.0F; // Block hy = TntMainClass.CompactTNT; public CompactTNT(int id) { super(id); this.setCreativeTab(TntMainClass.TNTab); this.power = 8.0F; this.hy = TntMainClass.CompactTNT; this.delaytime = 80; } public void registerIcons(IconRegister iconRegister) { blockIcon = iconRegister.registerIcon("tntplusplus:CompactTNT"); upside = iconRegister.registerIcon("tntplusplus:CompactTNT_up"); downside = iconRegister.registerIcon("tntplusplus:CompactTNT_down"); } }
Classe de l’Entity :
package fr.kitek.tntplusplus; import com.google.common.io.*; import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; public class EntityTNTPrimedCustom extends Entity implements IEntityAdditionalSpawnData { Block type; float p; private EntityLivingBase tntPlacedBy1; /** How long the fuse is */ public int fuse; public EntityTNTPrimedCustom(World par1World) { super(par1World); this.preventEntitySpawning = true; this.setSize(0.98F, 0.98F); this.yOffset = this.height / 2.0F; } public EntityTNTPrimedCustom(World par1World, double par2, double par4, double par6, EntityLivingBase par8EntityLivingBase, float power, int delay, Block i) { this(par1World); this.setPosition(par2, par4, par6); float f = (float)(Math.random() * Math.PI * 2.0D); this.motionX = (double)(-((float)Math.sin((double)f)) * 0.02F); this.motionY = 0.20000000298023224D; this.motionZ = (double)(-((float)Math.cos((double)f)) * 0.02F); this.p = power; this.fuse = delay; this.type = i; this.prevPosX = par2; this.prevPosY = par4; this.prevPosZ = par6; this.tntPlacedBy1 = par8EntityLivingBase; } @Override public void writeSpawnData(ByteArrayDataOutput data) { data.writeInt(this.fuse); } @Override public void readSpawnData(ByteArrayDataInput data) { this.fuse = data.readInt(); } protected void entityInit() {} /** * returns if this entity triggers Block.onEntityWalking on the blocks they * walk on. used for spiders and wolves to prevent them from trampling crops */ protected boolean canTriggerWalking() { return false; } /** * Returns true if other Entities should be prevented from moving through * this Entity. */ public boolean canBeCollidedWith() { return !this.isDead; } /** * Called to update the entity's position/logic. */ public void onUpdate() { this.prevPosX = this.posX; this.prevPosY = this.posY; this.prevPosZ = this.posZ; this.motionY -= 0.03999999910593033D; this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.9800000190734863D; this.motionY *= 0.9800000190734863D; this.motionZ *= 0.9800000190734863D; if(this.onGround) { this.motionX *= 0.699999988079071D; this.motionZ *= 0.699999988079071D; this.motionY *= -0.5D; } if(this.fuse-- <= 0) { this.setDead(); if(!this.worldObj.isRemote) { this.explode(); } } else { this.worldObj.spawnParticle("smoke", this.posX, this.posY + 0.5D, this.posZ, 0.0D, 0.0D, 0.0D); } } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ protected void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { par1NBTTagCompound.setByte("Fuse", (byte)this.fuse); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ protected void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { this.fuse = par1NBTTagCompound.getByte("Fuse"); } @SideOnly(Side.CLIENT) public float getShadowSize() { return 0.0F; } /** * returns null or the entityliving it was placed or ignited by */ public EntityLivingBase getTntPlacedBy() { return this.tntPlacedBy1; } private void explode() { this.worldObj.createExplosion(this, this.posX, this.posY, this.posZ, p, true); } }
Classe du Render :
package fr.kitek.tntplusplus; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.entity.Render; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) public class RenderTNTPrimedCustom extends Render { private RenderBlocks blockRenderer = new RenderBlocks(); private Block texture; public RenderTNTPrimedCustom() { this.shadowSize = 0.5F; } public void renderPrimedTNTCustom(EntityTNTPrimedCustom par1EntityTNTPrimed, double par2, double par4, double par6, float par8, float par9) { this.texture = par1EntityTNTPrimed.type; GL11.glPushMatrix(); GL11.glTranslatef((float)par2, (float)par4, (float)par6); float f2; if((float)par1EntityTNTPrimed.fuse - par9 + 1.0F < 10.0F) { f2 = 1.0F - ((float)par1EntityTNTPrimed.fuse - par9 + 1.0F) / 10.0F; if(f2 < 0.0F) { f2 = 0.0F; } if(f2 > 1.0F) { f2 = 1.0F; } f2 *= f2; f2 *= f2; float f3 = 1.0F + f2 * 0.3F; GL11.glScalef(f3, f3, f3); } f2 = (1.0F - ((float)par1EntityTNTPrimed.fuse - par9 + 1.0F) / 100.0F) * 0.8F; this.bindEntityTexture(par1EntityTNTPrimed); this.blockRenderer.renderBlockAsItem(texture, 0, par1EntityTNTPrimed.getBrightness(par9)); if(par1EntityTNTPrimed.fuse / 5 % 2 == 0) { GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_ALPHA); GL11.glColor4f(1.0F, 1.0F, 1.0F, f2); this.blockRenderer.renderBlockAsItem(texture, 0, 1.0F); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_LIGHTING); GL11.glEnable(GL11.GL_TEXTURE_2D); } GL11.glPopMatrix(); } protected ResourceLocation getTNTPrimedCustomTextures(EntityTNTPrimedCustom par1EntityTNTPrimed) { return TextureMap.locationBlocksTexture; } /** * Returns the location of an entity's texture. Doesn't seem to be called * unless you call Render.bindEntityTexture. */ @Override protected ResourceLocation getEntityTexture(Entity par1Entity) { return this.getTNTPrimedCustomTextures((EntityTNTPrimedCustom)par1Entity); } /** * Actually renders the given argument. This is a synthetic bridge method, * always casting down its argument and then handing it off to a worker * function which does the actual work. In all probabilty, the class Render * is generic (Render <t extends="" entity)="" and="" this="" method="" has="" signature="" public<br="">* void doRender(T entity, double d, double d1, double d2, float f, float * f1). But JAD is pre 1.5 so doesn't do that. */ public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9) { this.renderPrimedTNTCustom((EntityTNTPrimedCustom)par1Entity, par2, par4, par6, par8, par9); } }
Classe du Proxy Client :
package fr.kitek.tntplusplus.proxy; import cpw.mods.fml.client.registry.RenderingRegistry; import fr.kitek.tntplusplus.EntityTNTPrimedCustom; import fr.kitek.tntplusplus.RenderTNTPrimedCustom; public class TutoClientProxy extends TutoCommonProxy { public void registerRender() { // TODO Auto-generated method stub // ici mes futurs client registry RenderingRegistry.registerEntityRenderingHandler(EntityTNTPrimedCustom.class, new RenderTNTPrimedCustom()); } } ```</t>
-
IL te suffira de remplacer par le bloc dans ton constructeur et il prendra sa texture automatiquement
new RenderTNTPrimedCustom(TntMainClass.CompactTNT)deviendra
new RenderTNTPrimedCustom(TntMainClass.Autrebloc)
-
Et donc il faudra que je crée d’autres entity pour chaque TNT ?
-
Oui.
-
Merci je crois que ce sujet est résolu. Merci beaucoup. Il ne reste plus qu’à tester.
-
Il y a un problème je crois :
Dans le Render, j’ai écris ```java
public void renderPrimedTNTCustom(EntityTNTPrimedCustom par1EntityTNTPrimed, double par2, double par4, double par6, float par8, float par9)Vu qu'il y a "EntityTNTPrimedCustom", ça fait le render de cette entity malgré la technique que tu m'a donné. Pour l'instant, je n'ai pas mis les textures de la nouvelle TNT mais je vois la texture de la première. Or, si je fais un extend, il me semble que ça va aussi prendre la texture de la 1ère TNT. Help ? ___ Par contre, la TNT fait ce que je voulait. ___ Si je copie le render, ça devrais marcher mais je croyais que je pouvais faire comme tu m'a dis. ___ J'ai remarqué autre chose : une fois, j'ai inventé un concept de canon à TNT surpuissant mais il était tellement puissant que la TNT explosait dans l'air, Je l'avais fait pour qu'il soit entièrement automatique avec des dispensers. Vu que j'ai réussi à créer une TNT, j'ai voulu réessayer avec la 2e TNT que j'ai créer à laquelle j'ai doublé le fuse SAUF QUE ma TNT se droppe au lieu de s'allumer.