MFF

    Minecraft Forge France
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes
    • Forge Events
      • Automatique
      • Foncé
      • Clair
    • S'inscrire
    • Se connecter

    Utiliser 2 blockstates

    Planifier Épinglé Verrouillé Déplacé Résolu 1.12.x
    1.12.2
    2 Messages 1 Publieurs 166 Vues 1 Watching
    Charger plus de messages
    • Du plus ancien au plus récent
    • Du plus récent au plus ancien
    • Les plus votés
    Répondre
    • Répondre à l'aide d'un nouveau sujet
    Se connecter pour répondre
    Ce sujet a été supprimé. Seuls les utilisateurs avec les droits d'administration peuvent le voir.
    • FeedBackF Hors-ligne
      FeedBack
      dernière édition par

      Bonjour !
      J’ai créé 2 property pour mon block et j’aimerais les utiliser pour un model.
      Problème, je n’y arrive pas.
      Merci d’avance pour l’aide

      public class BlockActivator extends Block implements IHasModel
      {
          private boolean canPower = false;
          
          public static final PropertyInteger BLOCK_TYPE = PropertyInteger.create("power", 0, 6);
          public static final PropertyDirection FACING = BlockHorizontal.FACING;
                 
          
          public BlockActivator(String name, Material material)
          {
              super(material);
              setUnlocalizedName(name);
              setRegistryName(name);
              setCreativeTab(Main.REDSKYLL_TAB);
              setHardness(8.0F);
              BlockInit.BLOCKS.add(this);
              ItemInit.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
          }
                  
          @Override
          public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
          {
              this.setDefaultFacing(worldIn, pos, state);
              this.setDefaultState(this.blockState.getBaseState().withProperty(BLOCK_TYPE, Integer.valueOf(0)));
          }
      
          private void setDefaultFacing(World worldIn, BlockPos pos, IBlockState state)
          {
              if(!worldIn.isRemote)
              {
                  IBlockState iblockstate = worldIn.getBlockState(pos.north());
                  IBlockState iblockstate1 = worldIn.getBlockState(pos.south());
                  IBlockState iblockstate2 = worldIn.getBlockState(pos.west());
                  IBlockState iblockstate3 = worldIn.getBlockState(pos.east());
                  EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);
      
                  if(enumfacing == EnumFacing.NORTH && iblockstate.isFullBlock() && !iblockstate1.isFullBlock())
                  {
                      enumfacing = EnumFacing.SOUTH;
                  }
                  else if(enumfacing == EnumFacing.SOUTH && iblockstate1.isFullBlock() && !iblockstate.isFullBlock())
                  {
                      enumfacing = EnumFacing.NORTH;
                  }
                  else if(enumfacing == EnumFacing.WEST && iblockstate2.isFullBlock() && !iblockstate3.isFullBlock())
                  {
                      enumfacing = EnumFacing.EAST;
                  }
                  else if(enumfacing == EnumFacing.EAST && iblockstate3.isFullBlock() && !iblockstate2.isFullBlock())
                  {
                      enumfacing = EnumFacing.WEST;
                  }
      
                  worldIn.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);
              }
          }
      
          @Override
          public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
          {
              return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
          }
      
          @Override
          public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
          {
              worldIn.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
          }
      
          @Override
          public IBlockState withRotation(IBlockState state, Rotation rot)
          {
              return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
          }
      
          @Override
          public int getMetaFromState(IBlockState state)
          {
              return ((EnumFacing)state.getValue(FACING)).getIndex();
          }
      
          @Override
          public IBlockState getStateFromMeta(int meta)
          {
              EnumFacing enumfacing = EnumFacing.getFront(meta);
      
              if(enumfacing.getAxis() == EnumFacing.Axis.Y)
              {
                  enumfacing = EnumFacing.NORTH;
              }
      
              return this.getDefaultState().withProperty(FACING, enumfacing);
          }
      
          @Override
          public boolean hasComparatorInputOverride(IBlockState state)
          {
              return true;
          }
      
          @Override
          public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos)
          {
              return SeatUtil.isSomeoneSitting(worldIn, pos.getX(), pos.getY(), pos.getZ()) ? 1 : 0;
          }
      
          @Override
          public IBlockState withMirror(IBlockState state, Mirror mirrorIn)
          {
              return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
          }
      
          @Override
          protected BlockStateContainer createBlockState()
          {
              return new BlockStateContainer(this, new IProperty[] {FACING, BLOCK_TYPE});
          }
      
          @Override
          public boolean isOpaqueCube(IBlockState state)
          {
              return false;
          }
      
          @Override
          public boolean isFullCube(IBlockState state)
          {
              return false;
          }
      
          @Override
          public boolean isFullBlock(IBlockState state)
          {
              return false;
          }
          
          @Override
          public void registerModels()
          {
              Main.proxy.registerItemRederer(Item.getItemFromBlock(this), 0);
          }
        
          @Override
          public boolean canProvidePower(IBlockState state)
          {
              return this.canPower;
          }
      
          public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
          {
              if (!this.canPower)
              {
                  return 0;
              }
              else
              {
                  return 15;
              }
          }
          
          @Override
          public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
          {
              return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
          }
          
          @Override
          public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side)
          {
              return !this.canPower ? 0 : blockState.getWeakPower(blockAccess, pos, side);
          }
      
          @Override
          public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
          {
              if(worldIn.isBlockPowered(pos.west()) && worldIn.getBlockState(pos.west()).getBlock() instanceof BlockRedstoneRepeater)
              {
                  this.canPower = true;
              }
              else
              {
                  this.canPower = false;
              }
          }
      }
      
      {
          "variants": {
              "facing=north,power=0": {
                  "model": "redskyll:activator"
              }, 
              "facing=north,power=1": {
                  "model": "redskyll:activator_on"
              },
              "facing=north,power=2": {
                  "model": "redskyll:activator_off"
              },
              "facing=north,power=3": {
                  "model": "redskyll:activator"            
              },
              "facing=north,power=4": {
                  "model": "redskyll:activator"            
              },
              "facing=north,power=5": {
                  "model": "redskyll:activator"            
              },
              "facing=north,power=6": {
                  "model": "redskyll:activator"            
              },
              "facing=south,power=0": {
                  "model": "redskyll:activator"
              }, 
              "facing=south,power=1": {
                  "model": "redskyll:activator_on"
              },
              "facing=south,power=2": {
                  "model": "redskyll:activator_off"
              },
              "facing=south,power=3": {
                  "model": "redskyll:activator"            
              },
              "facing=south,power=4": {
                  "model": "redskyll:activator"            
              },
              "facing=south,power=5": {
                  "model": "redskyll:activator"            
              },
              "facing=south,power=6": {
                  "model": "redskyll:activator"            
              },
              "facing=east,power=0": {
                  "model": "redskyll:activator"
              }, 
              "facing=east,power=1": {
                  "model": "redskyll:activator_on"
              },
              "facing=east,power=2": {
                  "model": "redskyll:activator_off"
              },
              "facing=east,power=3": {
                  "model": "redskyll:activator"            
              },
              "facing=east,power=4": {
                  "model": "redskyll:activator"            
              },
              "facing=east,power=5": {
                  "model": "redskyll:activator"            
              },
              "facing=east,power=6": {
                  "model": "redskyll:activator"            
              },
              "facing=west,power=0": {
                  "model": "redskyll:activator"
              }, 
              "facing=west,power=1": {
                  "model": "redskyll:activator_on"
              },
              "facing=west,power=2": {
                  "model": "redskyll:activator_off"
              },
              "facing=west,power=3": {
                  "model": "redskyll:activator"            
              },
              "facing=west,power=4": {
                  "model": "redskyll:activator"            
              },
              "facing=west,power=5": {
                  "model": "redskyll:activator"            
              },
              "facing=west,power=6": {
                  "model": "redskyll:activator"            
              }
      }
      
      
      1 réponse Dernière réponse Répondre Citer 0
      • FeedBackF Hors-ligne
        FeedBack
        dernière édition par

        Je suis juste un peu bête et j’avais mal formé le json 😕
        Désolé du dérangement 🙂

        1 réponse Dernière réponse Répondre Citer 0
        • 1 / 1
        • Premier message
          Dernier message
        Design by Woryk
        ContactMentions Légales

        MINECRAFT FORGE FRANCE © 2024

        Powered by NodeBB