Example #1
0
  /**
   * Called frequently so the entity can update its state every tick as required. For example,
   * zombies and skeletons use this to react to sunlight and start to burn.
   */
  public void onLivingUpdate() {
    super.onLivingUpdate();

    if (this.attackTimer > 0) {
      --this.attackTimer;
    }

    if (this.holdRoseTick > 0) {
      --this.holdRoseTick;
    }

    if (this.motionX * this.motionX + this.motionZ * this.motionZ > 2.500000277905201E-7D
        && this.rand.nextInt(5) == 0) {
      int i = MathHelper.floor_double(this.posX);
      int j = MathHelper.floor_double(this.posY - 0.20000000298023224D);
      int k = MathHelper.floor_double(this.posZ);
      IBlockState iblockstate = this.worldObj.getBlockState(new BlockPos(i, j, k));
      Block block = iblockstate.getBlock();

      if (block.getMaterial() != Material.air) {
        this.worldObj.spawnParticle(
            EnumParticleTypes.BLOCK_CRACK,
            this.posX + ((double) this.rand.nextFloat() - 0.5D) * (double) this.width,
            this.getEntityBoundingBox().minY + 0.1D,
            this.posZ + ((double) this.rand.nextFloat() - 0.5D) * (double) this.width,
            4.0D * ((double) this.rand.nextFloat() - 0.5D),
            0.5D,
            ((double) this.rand.nextFloat() - 0.5D) * 4.0D,
            new int[] {Block.getStateId(iblockstate)});
      }
    }
  }
  public static void playBlockBreakParticles(BlockPos pos, IBlockState state) {
    ParticleManager pm = Minecraft.getMinecraft().effectRenderer;

    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        for (int l = 0; l < 4; l++) {
          double d0 = (double) pos.getX() + ((double) j + 0.5D) / 4D;
          double d1 = (double) pos.getY() + ((double) k + 0.5D) / 4D;
          double d2 = (double) pos.getZ() + ((double) l + 0.5D) / 4D;
          Particle digging =
              diggingFactory.getEntityFX(
                  0,
                  Minecraft.getMinecraft().theWorld,
                  d0,
                  d1,
                  d2,
                  d0 - (double) pos.getX() - 0.5D,
                  d1 - (double) pos.getY() - 0.5D,
                  d2 - (double) pos.getZ() - 0.5D,
                  Block.getStateId(state));
          pm.addEffect(digging);
        }
      }
    }
  }
Example #3
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    positionAt++;
    if (positionAt == POSITIONS.length) positionAt = 0;

    BlockPos acoords = POSITIONS[positionAt];
    BlockPos coords = supertile.getPos().add(acoords);
    World world = supertile.getWorld();
    if (!world.isAirBlock(coords)) {
      IBlockState state = world.getBlockState(coords);
      RecipePureDaisy recipe = null;
      for (RecipePureDaisy recipe_ : BotaniaAPI.pureDaisyRecipes)
        if (recipe_.matches(world, coords, this, state)) {
          recipe = recipe_;
          break;
        }

      if (recipe != null) {
        if (ticksRemaining[positionAt] == -1) ticksRemaining[positionAt] = recipe.getTime();
        ticksRemaining[positionAt]--;

        Botania.proxy.sparkleFX(
            supertile.getWorld(),
            coords.getX() + Math.random(),
            coords.getY() + Math.random(),
            coords.getZ() + Math.random(),
            1F,
            1F,
            1F,
            (float) Math.random(),
            5);

        if (ticksRemaining[positionAt] <= 0) {
          ticksRemaining[positionAt] = -1;

          if (recipe.set(world, coords, this)) {
            for (int i = 0; i < 25; i++) {
              double x = coords.getX() + Math.random();
              double y = coords.getY() + Math.random() + 0.5;
              double z = coords.getZ() + Math.random();

              Botania.proxy.wispFX(
                  supertile.getWorld(), x, y, z, 1F, 1F, 1F, (float) Math.random() / 2F);
            }
            if (ConfigHandler.blockBreakParticles)
              supertile
                  .getWorld()
                  .playEvent(2001, coords, Block.getStateId(recipe.getOutputState()));
          }
        }
      } else ticksRemaining[positionAt] = -1;
    }
  }
Example #4
0
  public static void removeBlockWithDrops(
      SpellContext context,
      EntityPlayer player,
      World world,
      ItemStack tool,
      BlockPos pos,
      boolean particles) {
    if (!world.isBlockLoaded(pos)
        || context.positionBroken != null && pos.equals(context.positionBroken.getBlockPos()))
      return;

    int harvestLevel = ConfigHandler.cadHarvestLevel;
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (!world.isRemote
        && block != null
        && !block.isAir(world, pos)
        && !(block instanceof BlockLiquid)
        && block.getPlayerRelativeBlockHardness(player, world, pos) > 0) {
      int neededHarvestLevel = block.getHarvestLevel(state);
      if (neededHarvestLevel > harvestLevel) return;

      BreakEvent event = new BreakEvent(world, pos, state, player);
      MinecraftForge.EVENT_BUS.post(event);
      if (!event.isCanceled()) {
        if (!player.capabilities.isCreativeMode) {
          block.onBlockHarvested(world, pos, state, player);

          if (block.removedByPlayer(world, pos, player, true)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
            block.harvestBlock(world, player, pos, state, world.getTileEntity(pos));
          }
        } else world.setBlockToAir(pos);
      }

      if (particles) world.playAuxSFX(2001, pos, Block.getStateId(state));
    }
  }
Example #5
0
 public void func_174899_a(IBlockState p_174899_1_) {
   this.getDataWatcher().updateObject(20, Integer.valueOf(Block.getStateId(p_174899_1_)));
   this.setHasDisplayTile(true);
 }
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (supertile.getWorld().isRemote || redstoneSignal > 0) return;

    if (ticksExisted % 10 == 0) {
      IBlockState filter = getUnderlyingBlock();

      boolean scanned = false;
      List<BlockPos> validPositions = new ArrayList<>();

      int rangePlace = getRange();
      int rangePlaceY = getRangeY();

      BlockPos pos = supertile.getPos();

      List<EntityItem> items =
          supertile
              .getWorld()
              .getEntitiesWithinAABB(
                  EntityItem.class,
                  new AxisAlignedBB(
                      supertile.getPos().add(-RANGE, -RANGE_Y, -RANGE),
                      supertile.getPos().add(RANGE + 1, RANGE_Y + 1, RANGE + 1)));
      int slowdown = getSlowdownFactor();
      for (EntityItem item : items) {
        int age;
        try {
          age = (int) MethodHandles.itemAge_getter.invokeExact(item);
        } catch (Throwable t) {
          continue;
        }

        if (age < (60 + slowdown) || item.isDead) continue;

        ItemStack stack = item.getEntityItem();
        Item stackItem = stack.getItem();
        if (stackItem instanceof ItemBlock
            || stackItem instanceof ItemBlockSpecial
            || stackItem instanceof ItemRedstone
            || stackItem instanceof IFlowerPlaceable) {
          if (!scanned) {
            for (BlockPos pos_ :
                BlockPos.getAllInBox(
                    pos.add(-rangePlace, -rangePlaceY, -rangePlace),
                    pos.add(rangePlace, rangePlaceY, rangePlace))) {
              IBlockState stateAbove = supertile.getWorld().getBlockState(pos_.up());
              Block blockAbove = stateAbove.getBlock();
              BlockPos up = pos_.up();
              if (filter == supertile.getWorld().getBlockState(pos_)
                  && (blockAbove.isAir(stateAbove, supertile.getWorld(), up)
                      || blockAbove.isReplaceable(supertile.getWorld(), up)))
                validPositions.add(up);
            }

            scanned = true;
          }

          if (!validPositions.isEmpty()) {
            BlockPos coords =
                validPositions.get(supertile.getWorld().rand.nextInt(validPositions.size()));

            IBlockState stateToPlace = null;
            if (stackItem instanceof IFlowerPlaceable)
              stateToPlace =
                  ((IFlowerPlaceable) stackItem).getBlockToPlaceByFlower(stack, this, coords);
            if (stackItem instanceof ItemBlock)
              stateToPlace =
                  ((ItemBlock) stackItem)
                      .block.getStateFromMeta(stackItem.getMetadata(stack.getItemDamage()));
            else if (stackItem instanceof ItemBlockSpecial)
              stateToPlace =
                  ((Block)
                          ReflectionHelper.getPrivateValue(
                              ItemBlockSpecial.class,
                              (ItemBlockSpecial) stackItem,
                              LibObfuscation.REED_ITEM))
                      .getDefaultState();
            else if (stackItem instanceof ItemRedstone)
              stateToPlace = Blocks.REDSTONE_WIRE.getDefaultState();

            if (stateToPlace != null) {
              if (stateToPlace.getBlock().canPlaceBlockAt(supertile.getWorld(), coords)) {
                supertile.getWorld().setBlockState(coords, stateToPlace, 1 | 2);
                if (ConfigHandler.blockBreakParticles)
                  supertile.getWorld().playEvent(2001, coords, Block.getStateId(stateToPlace));
                validPositions.remove(coords);

                TileEntity tile = supertile.getWorld().getTileEntity(coords);
                if (tile != null && tile instanceof ISubTileContainer) {
                  ISubTileContainer container = (ISubTileContainer) tile;
                  String subtileName = ItemBlockSpecialFlower.getType(stack);
                  container.setSubTile(subtileName);
                  SubTileEntity subtile = container.getSubTile();
                  subtile.onBlockPlacedBy(
                      supertile.getWorld(),
                      coords,
                      supertile.getWorld().getBlockState(coords),
                      null,
                      stack);
                }

                if (stackItem instanceof IFlowerPlaceable)
                  ((IFlowerPlaceable) stackItem).onBlockPlacedByFlower(stack, this, coords);

                stack.stackSize--;
                if (stack.stackSize <= 0) item.setDead();

                if (mana > 1) mana--;
                return;
              }
            }
          }
        }
      }
    }
  }
 public void func_175490_a(IBlockState p_175490_1_)
 {
     this.dataWatcher.updateObject(16, Short.valueOf((short)(Block.getStateId(p_175490_1_) & 65535)));
 }