Hitbox en fonction de la direction du bloc
-
Avec la fonction onBlockActivated, tu fais un setBlock
-
et j’aimerais faire que ce ne soit que les gens qui ont un scoreboard de 1 Policier qui puisse l’ouvrir comment faire avec le if == et tout là ? :S
-
Et bien tu trouves par toi même comment récupérer le ScoreBoard, il faut chercher un peu !
-
En passant j’ai changé le titre, avec l’ancien titre 0 % de chance que quelqu’un qui a le même problème tombe sur ce sujet.
Il faut mettre un titre qui décrit le problème. -
J’ai supprimé l’autre discussion que tu venais de créer, ça ne sert à rien de créer plusieurs discussions pour un même problème …
Tu avais juste à up celle-ci.Ajoutes ceux deux fonctions :
@SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBox(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getSelectedBoundingBox(world, x, y, z); } public AxisAlignedBB getCollisionBoundingBox(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getCollisionBoundingBox(world, x, y, z); } -
Il ne veut pas getSelectedBoundingBox et getCollisionBoundingBox il n’accepte que getCollisionBoundingBoxFromPool et de même pour getSelected :S et ça ne change rien avec ce code…
package fr.altiscraft.altiscraft.common; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.altiscraft.altiscraft.proxy.ClientProxy; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; public class BlocPoubelle extends Block { protected BlocPoubelle() { super(Material.ground); } public boolean hasTileEntity(int metadata) { return true; } public TileEntity createTileEntity(World world, int metadata) { return new TileEntityPoubelle(); } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } @SideOnly(Side.CLIENT) public int getRenderType() { return ClientProxy.tesrRenderId; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBox(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getSelectedBoundingBoxFromPool(world, x, y, z); } public AxisAlignedBB getCollisionBoundingBox(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getCollisionBoundingBoxFromPool(world, x, y, z); } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { if (stack.getItemDamage() == 0) { TileEntity tile = world.getTileEntity(x, y, z); if ((tile instanceof TileEntityPoubelle)) { int direction = MathHelper.floor_double(living.rotationYaw * 4.0F / 360.0F + 2.5D) & 0x3; ((TileEntityPoubelle) tile).setDirection((byte) direction); } } } public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) { if (((axis == ForgeDirection.UP) || (axis == ForgeDirection.DOWN)) && (!world.isRemote) && (world.getBlockMetadata(x, y, z) == 0)) { TileEntity tile = world.getTileEntity(x, y, z); if ((tile instanceof TileEntityPoubelle)) { TileEntityPoubelle tilePoubelle = (TileEntityPoubelle) tile; byte direction = tilePoubelle.getDirection(); direction = (byte) (direction + 1); if (direction > 3) { direction = 0; } tilePoubelle.setDirection(direction); return true; } } return false; } public ForgeDirection[] getValidRotations(World world, int x, int y, int z) { return world.getBlockMetadata(x, y, z) == 0 ? new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN } : ForgeDirection.VALID_DIRECTIONS; } public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityPoubelle) { int direction = ((TileEntityPoubelle)tile).getDirection(); if(direction == 0) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F); } if(direction == 1) { this.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } if(direction == 2) { this.setBlockBounds(0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.5F); } if(direction == 3) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F); } } } }L’emplacement de la classe du bloc est la bonne ?
-
Comme ça alors :
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getSelectedBoundingBoxFromPool(world, x, y, z); } public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getCollisionBoundingBoxFromPool(world, x, y, z); }Je suis en 1.8, visiblement le nom des fonctions ne sont pas les mêmes.
-
Toujours le même problème… :S
Ps: normal que tu es enlevé le side only client ?
-
Non, remets-le.
Vérifies que la fonction setBlockBoundsBasedOnState est bien appelé (ajoutes des System.out.println(“test”) a différent endroit de la fonction) -
package fr.altiscraft.altiscraft.common; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.altiscraft.altiscraft.proxy.ClientProxy; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; public class BlocPoubelle extends Block { protected BlocPoubelle() { super(Material.ground); } public boolean hasTileEntity(int metadata) { return true; } public TileEntity createTileEntity(World world, int metadata) { return new TileEntityPoubelle(); } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } @SideOnly(Side.CLIENT) public int getRenderType() { System.out.println("hello"); return ClientProxy.tesrRenderId; } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { System.out.println("ici"); this.setBlockBoundsBasedOnState(world, x, y, z); System.out.println("la"); return super.getSelectedBoundingBoxFromPool(world, x, y, z); } public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBoundsBasedOnState(world, x, y, z); return super.getCollisionBoundingBoxFromPool(world, x, y, z); } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { if (stack.getItemDamage() == 0) { TileEntity tile = world.getTileEntity(x, y, z); if ((tile instanceof TileEntityPoubelle)) { int direction = MathHelper.floor_double(living.rotationYaw * 4.0F / 360.0F + 2.5D) & 0x3; ((TileEntityPoubelle) tile).setDirection((byte) direction); } } } public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis) { if (((axis == ForgeDirection.UP) || (axis == ForgeDirection.DOWN)) && (!world.isRemote) && (world.getBlockMetadata(x, y, z) == 0)) { TileEntity tile = world.getTileEntity(x, y, z); if ((tile instanceof TileEntityPoubelle)) { TileEntityPoubelle tilePoubelle = (TileEntityPoubelle) tile; byte direction = tilePoubelle.getDirection(); direction = (byte) (direction + 1); if (direction > 3) { direction = 0; } tilePoubelle.setDirection(direction); return true; } } return false; } public ForgeDirection[] getValidRotations(World world, int x, int y, int z) { return world.getBlockMetadata(x, y, z) == 0 ? new ForgeDirection[] { ForgeDirection.UP, ForgeDirection.DOWN } : ForgeDirection.VALID_DIRECTIONS; } public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityPoubelle) { int direction = ((TileEntityPoubelle)tile).getDirection(); if(direction == 0) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F); } if(direction == 1) { this.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } if(direction == 2) { this.setBlockBounds(0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.5F); } if(direction == 3) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F); } } } }Et ça spam la console de ici hello et la… :S
-
Et comme ça ?
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); if(tile instanceof TileEntityPoubelle) { int direction = ((TileEntityPoubelle)tile).getDirection(); System.out.println(direction); if(direction == 0) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.5F); } if(direction == 1) { this.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } if(direction == 2) { this.setBlockBounds(0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.5F); } if(direction == 3) { this.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 1.0F, 1.0F); } } } -
Non mais la hitbox est très bizarre quand je vise le bas ça met le bloc d’en dessous et sinon parfois je passe et parfois non…
-
Comment ça ? Et avec ce que je t’ai donné les logs affichent quoi ?
-
Ca spam de 0, 1 et 2 mais le 3 est absent…
-
Tu as posé des blocs dans les 4 directions possibles ?
Si ce print s’affiche bien ta hitbox devrait aussi fonctionner normalement. -
Oui dans tous les sens… :S
EDIT: Ah maintenant le 3 apparait… :S Que faire ?
-
Ah maintenant le 3 apparait… :S Que faire ?
-
J’en ai profité d’avoir ton code pour tester de mon côté.
Toutes les hitbox fonctionne correctement sauf celle de la direction 2.
Car tu as mit une valeur au minimum supérieur au maximum …Regarde bien ce que tu as mit :
if (direction == 2) { this.setBlockBounds(0.0F, 0.0F, 1.0F, 1.0F, 1.0F, 0.5F); }La fonction setBlockBounds a pour argument minX, minY, minZ, maxX, maxY, maxZ. Or 1.0F > 0.5F (minZ et maxZ)
Il faut donc mettre :if (direction == 2) { this.setBlockBounds(0.0F, 0.0F, 0.5F, 1.0F, 1.0F, 1.0F); } -
Effectivement j’avais oublié cette restriction merci beaucoup et désolé de la maladresse…