TESR qui rend mal, et qui n'a pas une jolie Hitbox
-
@Override public void renderInventory(double x, double y, double z) { }Il te manque this.renderTileEntityTileEntityPanneauAt(null, x, y, z, 0.0F); la dedans.
Et pas besoin de faire plusieurs icon dans ton bloc, le TileEntitySpecial rendu s’occupe de tout.
Pour la hitbox, elle ne peut pas être plus grande que 1x1, enfin, si tu le fais, elle n’apparaîtra que si tu passe la souris sur l’emplacement du bloc, et non sur ce qui dépasse le bloc.
La solution est donc de faire une hitbox plus grande, mais aussi de poser des blocs fantôme sur les 3 autres emplacement qui servirons juste pour afficher la hitbox (cf, parasol et lampadaire de nanotech mod city).
-
Voila ma classe actuellement, elle ne veut toujours pas s’orienter.
package assets.city01.Blocks; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import assets.city01.Data.ClientProxy; import assets.city01.Data.HL2; import assets.city01.TileEntity.TileEntityPanneau; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class B_Panneau extends BlockContainer { private Icon icontop, iconbottom, iconfront; private Icon[] Icon1 = new Icon[6]; private Icon[] Icon2 = new Icon[5]; private Icon[] Icon3 = new Icon[4]; private Icon[] Icon4 = new Icon[3]; private Icon[] Icon5 = new Icon[2]; private Icon[] Icon6 = new Icon[2]; private Icon Icon7, Icon8; public B_Panneau(int par1) { super(par1, Material.wood); this.setCreativeTab(HL2.Tab); } /* * public void registerIcons(IconRegister iconRegister) { blockIcon = * iconRegister.registerIcon("city01:nope"); iconfront = * iconRegister.registerIcon("city01:a"); icontop = * iconRegister.registerIcon("city01:b"); iconbottom = * iconRegister.registerIcon("city01:c"); } */ public void registerIcons(IconRegister iconregister) { Icon1[0] = iconregister.registerIcon("city01:nope"); Icon1[1] = iconregister.registerIcon("city01:nope"); Icon1[2] = iconregister.registerIcon("city01:nope"); Icon1[3] = iconregister.registerIcon("city01:a"); Icon1[4] = iconregister.registerIcon("city01:a"); Icon1[5] = iconregister.registerIcon("city01:a"); Icon2[0] = iconregister.registerIcon("city01:nope"); Icon2[1] = iconregister.registerIcon("city01:nope"); Icon2[2] = iconregister.registerIcon("city01:nope"); Icon2[3] = iconregister.registerIcon("city01:a"); Icon2[4] = iconregister.registerIcon("city01:a"); Icon3[0] = iconregister.registerIcon("city01:nope"); Icon3[1] = iconregister.registerIcon("city01:nope"); Icon3[2] = iconregister.registerIcon("city01:a"); Icon3[3] = iconregister.registerIcon("city01:a"); Icon4[0] = iconregister.registerIcon("city01:nope"); Icon4[1] = iconregister.registerIcon("city01:nope"); Icon4[2] = iconregister.registerIcon("city01:a"); Icon5[0] = iconregister.registerIcon("city01:nope"); Icon5[1] = iconregister.registerIcon("city01:a"); Icon6[0] = iconregister.registerIcon("city01:nope"); Icon6[1] = iconregister.registerIcon("city01:a"); Icon7 = iconregister.registerIcon("city01:nope"); Icon8 = iconregister.registerIcon("city01:a"); } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { int direction = MathHelper .floor_double((double) (living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3; TileEntity te = world.getBlockTileEntity(x, y, z); if (te != null && stack.getItemDamage() == 2 && te instanceof TileEntityPanneau) { ((TileEntityPanneau) te).setDirection((byte) direction); world.markBlockForUpdate(x, y, z); } } @SideOnly(Side.CLIENT) public Icon getIcon(int side, int metadata) { /* * return side == 1 ? this.icontop : (side == 0 ? this.iconbottom : * (metadata == 2 && side == 2 ? this.iconfront : (metadata == 3 && side * == 5 ? this.iconfront : (metadata == 0 && side == 3 ? this.iconfront * : (metadata == 1 && side == 4 ? this.iconfront : this.blockIcon))))); */ switch (metadata) { case 0: return Icon1[side]; case 1: return side > 1 ? Icon2[side - 1] : Icon2[0]; case 2: return side < 4 ? Icon3[side] : Icon3[3]; case 3: return side < 3 ? Icon4[side] : Icon4[2]; case 4: return side < 2 ? Icon5[0] : Icon5[1]; case 5: return side == 1 ? Icon6[0] : Icon6[1]; case 6: return Icon7; case 7: return Icon8; default: return blockIcon; } } @Override public TileEntity createNewTileEntity(World world) { return new TileEntityPanneau(); } public boolean renderAsNormalBlock() { return false; } public boolean isOpaqueCube() { return false; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { return AxisAlignedBB.getAABBPool().getAABB( (double) x + this.minX + 0.0D, (double) y + this.minY, (double) z + this.minZ + 0.6D, (double) x + this.maxX + 1.0D, (double) y + this.maxY + 1.0D, (double) z + this.maxZ - 0.6D); } public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { return AxisAlignedBB.getAABBPool().getAABB( (double) x + this.minX + 0.0D, (double) y + this.minY, (double) z + this.minZ + 0.6D, (double) x + this.maxX + 2.0D, (double) y + this.maxY + 1.0D, (double) z + this.maxZ - 0.6D); } @SideOnly(Side.CLIENT) public int getRenderType() { return ClientProxy.renderInventoryTESRId; } @SideOnly(Side.CLIENT) public Icon getBlockTexture(IBlockAccess blockAccess, int x, int y, int z, int side) { TileEntity te = blockAccess.getBlockTileEntity(x, y, z); if (te != null && te instanceof TileEntityPanneau) { TileEntityPanneau panneau = (TileEntityPanneau) te; int direction = panneau.getDirection(); return side == 1 ? Icon3[0] : (side == 0 ? Icon3[1] : (direction == 2 && side == 2 ? Icon3[2] : (direction == 3 && side == 5 ? Icon3[2] : (direction == 0 && side == 3 ? Icon3[2] : (direction == 1 && side == 4 ? Icon3[2] : Icon3[3]))))); } return this.getIcon(side, blockAccess.getBlockMetadata(x, y, z)); } } -
Mais mais, pourquoi utiliser les icônes ? Les icônes ne servent que pour un bloc avec un rendu normal.
@‘robin4002’:Et pas besoin de faire plusieurs icon dans ton bloc, le TileEntitySpecial rendu s’occupe de tout.
Ton problème d’orientation vient de la :
public void renderTileEntityTileEntityPanneauAt(TileEntityPanneau te, double x, double y, double z, float tick) { GL11.glPushMatrix(); GL11.glTranslated(x + 1.05F, y + 1.5F, z + 0.5F); this.bindTexture(textureLocation); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); this.model.render(0.0625F); if(te != null) { GL11.glRotatef(90F * te.getDirection(), 0.0F, 1.0F, 0.0F); } GL11.glPopMatrix(); }Cela devrait être :
public void renderTileEntityTileEntityPanneauAt(TileEntityPanneau te, double x, double y, double z, float tick) { GL11.glPushMatrix(); GL11.glTranslated(x + 1.05F, y + 1.5F, z + 0.5F); this.bindTexture(textureLocation); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); if(te != null) { GL11.glRotatef(90F * te.getDirection(), 0.0F, 1.0F, 0.0F); } this.model.render(0.0625F); GL11.glPopMatrix(); }Le this.model.render doit être en dernier.
-
ça ne change toujours rien.
-
Bon, étant donné que ces blocks ne seront pas usés par les joueurs, je vais faire en sorte qu’ils tournent en clique droit dessus.
Donc j’ai mis ce code dans TileEntityPanneauSpecialRender.java, mais aucun changements.public boolean interact(EntityPlayer player) { GL11.glPushMatrix(); GL11.glRotatef(90F, 1.0F, 0.0F, 0.0F); GL11.glPopMatrix(); return false; } -
Problème trouvé. Dans la classe de ton bloc, dans la fonction onBlockPlacedBy :
if(te != null && stack.getItemDamage() == 2 && te instanceof TileEntityPanneau) { ((TileEntityPanneau)te).setDirection((byte)direction); world.markBlockForUpdate(x, y, z); }enlève le stack.getItemDamage() == 2 &&, je l’ai mit dans mon tutoriel car j’ai expliqué que j’orientais que le bloc de metadata 2.
-
Parfait, sauf que j’ai quelques légers problèmes :

-
Ha oui, comme tu as centré le modèle avec la direction par défaut, ça fail pour les autres directions.
Dans le if(te != null) de ta fonction renderTileEntityTileEntityPanneauAt dans ta classe TileEntitySpecialRender, il faut que tu ajoute une condition qui check la direction, et tu fais des gl11.translate par rapport à la direction. -
Euh, le block bouge en même temps que moi Oo
-
What x) ?
Envoie ton code. -
public void renderTileEntityTileEntityPanneauAt(TileEntityPanneau te, double x, double y, double z, float tick) { GL11.glPushMatrix(); GL11.glTranslated(x + 1.05F, y + 1.5F, z + 0.5F); this.bindTexture(textureLocation); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); if (te != null) { GL11.glRotatef(90F * te.getDirection(), 0.0F, 1.0F, 0.0F); if (te.direction == 1) { // GL11.glTranslated(x + 1.05F, y + 1.5F, z + 0.5F); } if (te.direction == 2) { GL11.glTranslated(x + 0.2F, y + 0.0F, z + 0.0F); } if (te.direction == 3) { // GL11.glTranslated(x + 1.05F, y + 1.5F, z + 0.5F); } if (te.direction == 0) { //base, pas besoin de modifier } System.out.println("La direction est " + te.direction); } this.model.render(0.0625F); GL11.glPopMatrix(); } -
Ne mets pas les x, y et z dans les translates qui ajuste en fonction de la direction.
-
Je mets quoi alors ?
-
GL11.glTranslated(0.2F, 0.0F, 0.0F);
Tout simplement.
Le premier GL11.glTranlate déplace déjà le bloc au coord x, y, z. -
Parfait !

et peut-tu me passer le lien du lampadaire de Nanotech City, pour que je voie pour les blocs fantômes ? -
C’est lui normalement ^^
Pour les rendus dans l’inventaire, pense a GL11.glScale
-
L’item bloc est aussi différent : https://github.com/FFMT/nanotech_mod/blob/master/common/fr/mcnanotech/kevin_68/nanotechmod/city/blocks/ItemBlockLamp.java#L39-L69