• S'inscrire
    • Se connecter
    • Recherche
    • Récent
    • Mots-clés
    • Populaire
    • Utilisateurs
    • Groupes

    Résolu Timer Sur Block

    1.12.x
    1.12.2
    2
    3
    150
    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.
    • FeedBack
      FeedBack dernière édition par

      Bonjour,
      je voudrais que mon block vérifie une condition toutes les 5m mais la fonction updateTick ne marche pas 😕

      public class BlockIncubator extends Block implements IHasModel
      {
          private static EnumDragonType dragonType = EnumDragonType.NONE;
          private static int timer = 60 * 3 * 20;
      
          private static World world;
          private static BlockPos pos;
      
          public BlockIncubator(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 registerModels()
          {
              Main.proxy.registerItemRederer(Item.getItemFromBlock(this), 0);
          }
      
          @Override
          public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
          {
              super.onBlockAdded(worldIn, pos, state);
              this.world = worldIn;
              this.pos = pos;
          }
      
          public EnumDragonType getDragonType()
          {
              return this.dragonType;
          }
      
          public void setDragonType(EnumDragonType typeIn)
          {
              this.dragonType = typeIn;
          }
      
          @Override
          public boolean isFullBlock(IBlockState state)
          {
              return false;
          }
      
          @Override
          public boolean isFullCube(IBlockState state)
          {
              return false;
          }
      
          @Override
          public boolean isOpaqueCube(IBlockState state)
          {
              return false;
          }
      
          @Override
          public boolean requiresUpdates()
          {
              return true;
          }
      
          @Override
          public void updateTick(World worldIn, BlockPos pos, IBlockState state, Random rand)
          {
              System.out.println("juio^hee");
              if(this.getDragonType() == EnumDragonType.NONE)
              {
                  worldIn.spawnParticle(EnumParticleTypes.PORTAL, pos.getX(), pos.getY(), pos.getZ(), 0, 0, 0, 0);
              }
              else if(this.getDragonType() == EnumDragonType.EARTH)
              {
                  worldIn.spawnParticle(EnumParticleTypes.SLIME, pos.getX(), pos.getY(), pos.getZ(), 0, 0, 0, 0);
                  if(worldIn.getBlockState(pos.up()).getBlock() == BlockInit.EGG_EARTH)
                  {
                      if(this.timer >= 1)
                      {
                          this.timer--;
                      }
                      if(this.timer == 1)
                      {
                          worldIn.setBlockToAir(pos.up());
                          worldIn.spawnEntity(new EntityBabyEarthDragon(worldIn, pos.getX(), pos.getY(), pos.getZ()));
                          worldIn.setBlockToAir(pos);
                      }
                  }
              }
              else if(this.getDragonType() == EnumDragonType.FIRE)
              {
                  worldIn.spawnParticle(EnumParticleTypes.FLAME, pos.getX(), pos.getY(), pos.getZ(), 0, 0, 0, 0);
                  if(worldIn.getBlockState(pos.up()).getBlock() == BlockInit.EGG_FIRE)
                  {
                      if(this.timer >= 1)
                      {
                          this.timer--;
                      }
                      if(this.timer == 1)
                      {
                          worldIn.setBlockToAir(pos.up());
                          worldIn.spawnEntity(new EntityBabyFireDragon(worldIn, pos.getX(), pos.getY(), pos.getZ()));
                          worldIn.setBlockToAir(pos);
                      }
                  }
              }
              else if(this.getDragonType() == EnumDragonType.ICE)
              {
                  worldIn.spawnParticle(EnumParticleTypes.SNOWBALL, pos.getX(), pos.getY(), pos.getZ(), 0, 0, 0, 0);
                  if(worldIn.getBlockState(pos.up()).getBlock() == BlockInit.EGG_ICE)
                  {
                      if(this.timer >= 1)
                      {
                          this.timer--;
                      }
                      if(this.timer == 1)
                      {
                          worldIn.setBlockToAir(pos.up());
                          worldIn.spawnEntity(new EntityBabyIceDragon(worldIn, pos.getX(), pos.getY(), pos.getZ()));
                          worldIn.setBlockToAir(pos);
                      }
                  }
              }
          }
      
          @Override
          public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
          {
      
              if(this.getDragonType() == EnumDragonType.NONE)
              {
                  if(worldIn.getBlockState(pos.up()).getBlock() == Blocks.DRAGON_EGG)
                  {
                      if(playerIn.getHeldItem(hand).getItem() == ItemInit.EARTH_ATTACK)
                      {
                          playerIn.getHeldItem(hand).shrink(1);
                          worldIn.setBlockState(pos.up(), BlockInit.EGG_EARTH.getDefaultState());
                          if(worldIn.isRemote)
                          {
                              playerIn.sendMessage(new TextComponentString(TextFormatting.GREEN + "Vous venez choisi votre type de dragon en : " + TextFormatting.GREEN + "EARTH"));
                          }
                          this.setDragonType(EnumDragonType.EARTH);
                          return true;
                      }
                      else if(playerIn.getHeldItem(hand).getItem() == ItemInit.ICE_ATTACK)
                      {
                          playerIn.getHeldItem(hand).shrink(1);
                          worldIn.setBlockState(pos.up(), BlockInit.EGG_ICE.getDefaultState());
                          if(worldIn.isRemote)
                          {
                              playerIn.sendMessage(new TextComponentString(TextFormatting.GREEN + "Vous venez choisi votre type de dragon en : " + TextFormatting.AQUA + "ICE"));
                          }
                          this.setDragonType(EnumDragonType.ICE);
                          return true;
                      }
                      else if(playerIn.getHeldItem(hand).getItem() == ItemInit.MAGMA_BALL)
                      {
                          playerIn.getHeldItem(hand).shrink(1);
                          worldIn.setBlockState(pos.up(), BlockInit.EGG_FIRE.getDefaultState());
                          if(worldIn.isRemote)
                          {
                              playerIn.sendMessage(new TextComponentString(TextFormatting.GREEN + "Vous venez choisi votre type de dragon en : " + TextFormatting.RED + "FIRE"));
                          }
                          this.setDragonType(EnumDragonType.FIRE);
                          return true;
                      }
                      else
                      {
                          if(worldIn.isRemote)
                          {
                              playerIn.sendMessage(new TextComponentString(TextFormatting.RED + "Vous tenir un : " + TextFormatting.RED + "I" + TextFormatting.GOLD + "T" + TextFormatting.YELLOW + "E" + TextFormatting.GREEN + "M" + TextFormatting.DARK_GREEN + " E" + TextFormatting.DARK_AQUA + "L" + TextFormatting.AQUA + "E" + TextFormatting.BLUE + "M" + TextFormatting.DARK_BLUE + "E" + TextFormatting.DARK_PURPLE + "N" + TextFormatting.LIGHT_PURPLE + "T" + TextFormatting.RED + "A" + TextFormatting.GOLD + "I" + TextFormatting.YELLOW + "R" + TextFormatting.GREEN + "E"));
                          }
                          return false;
                      }
                  }
                  else
                  {
                      playerIn.sendMessage(new TextComponentString(TextFormatting.RED + "Veuillez poser un " + TextFormatting.DARK_PURPLE + "OEUF DE DRAGON" + TextFormatting.RED + " avant"));
                      return true;
                  }
              }
              else
              {
                  if(playerIn.getHeldItem(hand).getItem() == ItemInit.EARTH_ATTACK || playerIn.getHeldItem(hand).getItem() == ItemInit.ICE_ATTACK || playerIn.getHeldItem(hand).getItem() == ItemInit.MAGMA_BALL)
                  {
                      if(this.getDragonType() == EnumDragonType.EARTH)
                      {
                          if(worldIn.isRemote)
                              playerIn.sendMessage(new TextComponentString(TextFormatting.RED + "Vous avez deja choisi votre type : " + TextFormatting.GREEN + "EARTH"));
                      }
                      else if(this.getDragonType() == EnumDragonType.ICE)
                      {
                          if(worldIn.isRemote)
                              playerIn.sendMessage(new TextComponentString(TextFormatting.RED + "Vous avez deja choisi votre type : " + TextFormatting.AQUA + "ICE"));
                      }
                      else if(this.getDragonType() == EnumDragonType.FIRE)
                      {
                          if(worldIn.isRemote)
                              playerIn.sendMessage(new TextComponentString(TextFormatting.RED + "Vous avez deja choisi votre type : " + TextFormatting.DARK_RED + "FIRE"));
                      }
                  }
                  return false;
              }
      
          }
      
          @Override
          public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos)
          {
              super.neighborChanged(state, worldIn, pos, blockIn, fromPos);
              if(worldIn.getBlockState(pos.up()).getBlock() != BlockInit.EGG_EARTH && worldIn.getBlockState(pos.up()).getBlock() != BlockInit.EGG_FIRE && worldIn.getBlockState(pos.up()).getBlock() != BlockInit.EGG_ICE && worldIn.getBlockState(pos.up()).getBlock() != Blocks.DRAGON_EGG)
              {
                  this.setDragonType(EnumDragonType.NONE);
              }
          }
      
      }
      
      1 réponse Dernière réponse Répondre Citer 0
      • LeBossMax2
        LeBossMax2 dernière édition par

        Déja, l’utilisation de variable static dans c’est ps est très mauvais, ça va pars marcher quand ton block sera placé à plusieurs endroits dans le monde. Mais c’est le même problème pour les variables non statiques dans un block. En bref, il y a deux manières de stoker des données dans un bock : soit avec blockstate, c’est moins coûteux mais ça laisse moins de possibilités, soit tileentity où là tu as plus de possibilités mais c’est plus coûteux, donc a réserver aux blocks sont pas beaucoups présents dans le monde

        FeedBack 1 réponse Dernière réponse Répondre Citer 0
        • LeBossMax2
          LeBossMax2 dernière édition par

          Déja, l’utilisation de variable static dans c’est ps est très mauvais, ça va pars marcher quand ton block sera placé à plusieurs endroits dans le monde. Mais c’est le même problème pour les variables non statiques dans un block. En bref, il y a deux manières de stoker des données dans un bock : soit avec blockstate, c’est moins coûteux mais ça laisse moins de possibilités, soit tileentity où là tu as plus de possibilités mais c’est plus coûteux, donc a réserver aux blocks sont pas beaucoups présents dans le monde

          FeedBack 1 réponse Dernière réponse Répondre Citer 0
          • FeedBack
            FeedBack @LeBossMax2 dernière édition par

            @lebossmax2 bon bah j’ai rien fait et ca marche xD

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

            MINECRAFT FORGE FRANCE © 2018

            Powered by NodeBB