Résolu Rotation d'un bloc / Texture side 1 (TOP)
-
Salut à tous, alors j’essaie de créer un bloc flèche qui pointe dans la direction du joueur qui le place.
Cependant j’ai suivi le tutoriel de robin, j’ai regardé la classe BlockPumpkin et BlockAnvil et je n’y arrive pas
Le metadata se met bien mais la texture de la flèche pointe toujours vers le nord.
Merci pour votre aide! -
Salut
Si tu veux que l’on puisse t’aider, il nous faut ton fichier blockstate et la class de ton block.
EDIT : oups j’avais pas vu la version xD Donc juste la class de ton block -
@‘LeBossMax2’:
Salut
Si tu veux que l’on puisse t’aider, il nous faut ton fichier blockstate et la class de ton block.
EDIT : oups j’avais pas vu la version xD Donc juste la class de ton blockHonnêtement, la classe du bloc ne va pas servir à grand chose xD
C’est simplement un bloc basique ^^package qc.maxx.azeliummod.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockAnvil; import net.minecraft.block.BlockPumpkin; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import qc.maxx.azeliummod.main.AzeliumMod; public class BlockArrow extends Block { public BlockArrow() { super(Material.carpet); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.02F, 1.0F); this.setTickRandomly(true); this.setCreativeTab(AzeliumMod.azeliumCreativeTab); setBlockTextureName("azeliummod:arrow_block"); } /** * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been * cleared to be reused) */ public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_) { byte b0 = 0; float f = 0.02F; return AxisAlignedBB.getBoundingBox((double)p_149668_2_ + this.minX, (double)p_149668_3_ + this.minY, (double)p_149668_4_ + this.minZ, (double)p_149668_2_ + this.maxX, (double)((float)p_149668_3_ + (float)b0 * f), (double)p_149668_4_ + this.maxZ); } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } }
-
Donc c’est normal que ça ne fonctionne pas.
Il manque la fonction getIcon et onBlockPlaceBy -
@‘robin4002’:
Donc c’est normal que ça ne fonctionne pas.
Il manque la fonction getIcon et onBlockPlaceByJ’ai essayé avec les deux fonctions et ça ne fonctionnait toujours pas…
package qc.maxx.azeliummod.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockAnvil; import net.minecraft.block.BlockPumpkin; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import qc.maxx.azeliummod.main.AzeliumMod; public class BlockArrow extends Block { private IIcon blockIcon; public BlockArrow() { super(Material.carpet); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.02F, 1.0F); this.setTickRandomly(true); this.setCreativeTab(AzeliumMod.azeliumCreativeTab); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister p_149651_1_) { this.blockIcon = p_149651_1_.registerIcon("azeliummod:arrow_block"); } @SideOnly(Side.CLIENT) public IIcon getIcon(int p_149691_1_, int p_149691_2_) { return this.blockIcon; } /** * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been * cleared to be reused) */ public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_) { byte b0 = 0; float f = 0.02F; return AxisAlignedBB.getBoundingBox((double)p_149668_2_ + this.minX, (double)p_149668_3_ + this.minY, (double)p_149668_4_ + this.minZ, (double)p_149668_2_ + this.maxX, (double)((float)p_149668_3_ + (float)b0 * f), (double)p_149668_4_ + this.maxZ); } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } 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; world.setBlockMetadataWithNotify(x, y, z, direction, 2); } }
-
Sachant que tu ne changes pas l’icône en fonction du metadata dans ta fonction getIcon normal que tu n’obtiens toujours rien.
-
@‘robin4002’:
Sachant que tu ne changes pas l’icône en fonction du metadata dans ta fonction getIcon normal que tu n’obtiens toujours rien.
Donc du coup tu me dis qu’il me faut 4 textures différentes, une pour chaque direction?
-
Oui, ou utiliser des FlippedIcon (voir code de la porte).
-
Merci beaucoup
J’y arrivais pas avec les FlippedIcon du coup j’ai fais 4 imagesCode finale:
package qc.maxx.azeliummod.blocks; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.List; import net.minecraft.block.Block; import net.minecraft.block.BlockAnvil; import net.minecraft.block.BlockDoor; import net.minecraft.block.BlockLog; import net.minecraft.block.BlockPumpkin; import net.minecraft.block.BlockRotatedPillar; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.IconFlipped; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; import qc.maxx.azeliummod.main.AzeliumMod; public class BlockArrow extends Block { @SideOnly(Side.CLIENT) private IIcon[] blockIcon; public BlockArrow() { super(Material.carpet); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.02F, 1.0F); this.setCreativeTab(AzeliumMod.azeliumCreativeTab); } @SideOnly(Side.CLIENT) public IIcon getIcon(int p_149691_1_, int p_149691_2_) { return this.blockIcon[0]; } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister p_149651_1_) { this.blockIcon = new IIcon[4]; for(int i = 0; i < this.blockIcon.length; ++i) { this.blockIcon* = p_149651_1_.registerIcon("azeliummod:arrow_block_" + i); } } @SideOnly(Side.CLIENT) public IIcon getIcon(IBlockAccess blockAccess, int x, int y, int z, int p_149673_5_) { return this.blockIcon[blockAccess.getBlockMetadata(x, y, z)]; } public AxisAlignedBB getCollisionBoundingBoxFromPool(World p_149668_1_, int p_149668_2_, int p_149668_3_, int p_149668_4_) { byte b0 = 0; float f = 0.02F; return AxisAlignedBB.getBoundingBox((double)p_149668_2_ + this.minX, (double)p_149668_3_ + this.minY, (double)p_149668_4_ + this.minZ, (double)p_149668_2_ + this.maxX, (double)((float)p_149668_3_ + (float)b0 * f), (double)p_149668_4_ + this.maxZ); } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } 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; world.setBlockMetadataWithNotify(x, y, z, direction, 2); } }