@SideOnly(Side.CLIENT)
  public void randomDisplayTick(World pos, BlockPos state, IBlockState worldIn, Random rand) {
    EnumFacing enumfacing = (EnumFacing) worldIn.getValue(FACING);
    double d0 = (double) state.getX() + 0.5D;
    double d1 = (double) state.getY() + 0.7D;
    double d2 = (double) state.getZ() + 0.5D;
    double d3 = 0.22D;
    double d4 = 0.27D;

    if (enumfacing.getAxis().isHorizontal()) {
      EnumFacing enumfacing1 = enumfacing.getOpposite();
      pos.spawnParticle(
          EnumParticleTypes.SPELL_MOB_AMBIENT,
          d0 + d4 * (double) enumfacing1.getFrontOffsetX(),
          d1 + d3,
          d2 + d4 * (double) enumfacing1.getFrontOffsetZ(),
          0.0D,
          5.0D,
          0.0D,
          new int[0]);
      pos.spawnParticle(
          EnumParticleTypes.REDSTONE,
          d0 + d4 * (double) enumfacing1.getFrontOffsetX(),
          d1 + d3,
          d2 + d4 * (double) enumfacing1.getFrontOffsetZ(),
          -9.0D,
          9.0D,
          -9.0D,
          new int[0]);
    } else {
      pos.spawnParticle(
          EnumParticleTypes.SPELL_MOB_AMBIENT, d0, d1, d2, 0.0D, 5.0D, 0.0D, new int[0]);
      pos.spawnParticle(EnumParticleTypes.REDSTONE, d0, d1, d2, -9.0D, 9.0D, -9.0D, new int[0]);
    }
  }
  /** Dispense the specified stack, play the dispense sound and spawn particles. */
  public ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) {
    EnumFacing enumfacing = BlockDispenser.getFacing(par1IBlockSource.getBlockMetadata());
    World world = par1IBlockSource.getWorld();
    double d0 = par1IBlockSource.getX() + (double) ((float) enumfacing.getFrontOffsetX() * 1.125F);
    double d1 = par1IBlockSource.getY() + (double) ((float) enumfacing.getFrontOffsetY() * 1.125F);
    double d2 = par1IBlockSource.getZ() + (double) ((float) enumfacing.getFrontOffsetZ() * 1.125F);
    int i = par1IBlockSource.getXInt() + enumfacing.getFrontOffsetX();
    int j = par1IBlockSource.getYInt() + enumfacing.getFrontOffsetY();
    int k = par1IBlockSource.getZInt() + enumfacing.getFrontOffsetZ();
    Material material = world.getBlockMaterial(i, j, k);
    double d3;

    if (Material.water.equals(material)) {
      d3 = 1.0D;
    } else {
      if (!Material.air.equals(material)
          || !Material.water.equals(world.getBlockMaterial(i, j - 1, k))) {
        return this.defaultDispenserItemBehavior.dispense(par1IBlockSource, par2ItemStack);
      }

      d3 = 0.0D;
    }

    EntityBoat entityboat = new EntityBoat(world, d0, d1 + d3, d2);
    world.spawnEntityInWorld(entityboat);
    par2ItemStack.splitStack(1);
    return par2ItemStack;
  }
  @Override
  public void checkStack(
      World par1World,
      int par2,
      int par3,
      int par4,
      Entity triggerer,
      ArrayList<ItemStack> stacks) {
    if (stacks.isEmpty()) {
      return;
    }

    if (this.arrayContainsEqualStack(stacks, new ItemStack(Item.firework))
        && this.arrayContainsEqualStack(stacks, new ItemStack(Item.fireballCharge))) {
      int index0 = this.arrayIndexOfStack(stacks, new ItemStack(Item.firework));
      int index1 = this.arrayIndexOfStack(stacks, new ItemStack(Item.fireballCharge));
      EnumFacing face = getFacing(par1World, par2, par3, par4);

      while (stacks.get(index0).stackSize > 0 && stacks.get(index1).stackSize > 0) {
        double d0 = par2 + (double) ((float) face.getFrontOffsetX() * 0.3F);
        double d1 = par3 + (double) ((float) face.getFrontOffsetX() * 0.3F);
        double d2 = par4 + (double) ((float) face.getFrontOffsetZ() * 0.3F);
        Random random = par1World.rand;
        double d3 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetX();
        double d4 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetY();
        double d5 = random.nextGaussian() * 0.05D + (double) face.getFrontOffsetZ();
        EntityFireball fireball = new EntityLargeFireball(par1World, d0, d1, d2, d3, d4, d5);
        par1World.spawnEntityInWorld(fireball);

        if (triggerer instanceof EntityLivingBase) {
          boolean shouldRun = true;
          if (triggerer instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) triggerer;
            if (player.capabilities.isCreativeMode) {
              // Remove the bellow comment to make the player in
              // creative mode not get launched
              // shouldRun = false;
            }
          }

          if (shouldRun) {
            triggerer.mountEntity(fireball);
          }
        }

        this.removeItemFromInventory(par1World, par2, par3, par4, new ItemStack(Item.firework, 1));
        stacks.get(index0).stackSize--;
        this.removeItemFromInventory(
            par1World, par2, par3, par4, new ItemStack(Item.fireballCharge, 1));
        stacks.get(index1).stackSize--;
      }
    }
  }
Esempio n. 4
0
  private void func_174856_o() {
    if (this.field_174860_b != null) {
      double var1 = (double) this.field_174861_a.getX() + 0.5D;
      double var3 = (double) this.field_174861_a.getY() + 0.5D;
      double var5 = (double) this.field_174861_a.getZ() + 0.5D;
      double var7 = 0.46875D;
      double var9 = this.func_174858_a(this.getWidthPixels());
      double var11 = this.func_174858_a(this.getHeightPixels());
      var1 -= (double) this.field_174860_b.getFrontOffsetX() * 0.46875D;
      var5 -= (double) this.field_174860_b.getFrontOffsetZ() * 0.46875D;
      var3 += var11;
      EnumFacing var13 = this.field_174860_b.rotateYCCW();
      var1 += var9 * (double) var13.getFrontOffsetX();
      var5 += var9 * (double) var13.getFrontOffsetZ();
      this.posX = var1;
      this.posY = var3;
      this.posZ = var5;
      double var14 = (double) this.getWidthPixels();
      double var16 = (double) this.getHeightPixels();
      double var18 = (double) this.getWidthPixels();

      if (this.field_174860_b.getAxis() == EnumFacing.Axis.Z) {
        var18 = 1.0D;
      } else {
        var14 = 1.0D;
      }

      var14 /= 32.0D;
      var16 /= 32.0D;
      var18 /= 32.0D;
      this.func_174826_a(
          new AxisAlignedBB(
              var1 - var14, var3 - var16, var5 - var18, var1 + var14, var3 + var16, var5 + var18));
    }
  }
  public int findPathOptions(
      PathPoint[] pathOptions,
      Entity entityIn,
      PathPoint currentPoint,
      PathPoint targetPoint,
      float maxDistance) {
    int i = 0;

    for (EnumFacing enumfacing : EnumFacing.values()) {
      PathPoint pathpoint =
          this.getSafePoint(
              entityIn,
              currentPoint.xCoord + enumfacing.getFrontOffsetX(),
              currentPoint.yCoord + enumfacing.getFrontOffsetY(),
              currentPoint.zCoord + enumfacing.getFrontOffsetZ());

      if (pathpoint != null
          && !pathpoint.visited
          && pathpoint.distanceTo(targetPoint) < maxDistance) {
        pathOptions[i++] = pathpoint;
      }
    }

    return i;
  }
  @Override
  protected void onImpact(@Nonnull RayTraceResult pos) {
    if (isReturning()) return;

    switch (pos.typeOfHit) {
      case BLOCK:
        {
          Block block = worldObj.getBlockState(pos.getBlockPos()).getBlock();
          if (block instanceof BlockBush || block instanceof BlockLeaves) return;

          int bounces = getTimesBounced();
          if (bounces < MAX_BOUNCES) {
            Vector3 currentMovementVec = new Vector3(motionX, motionY, motionZ);
            EnumFacing dir = pos.sideHit;
            Vector3 normalVector =
                new Vector3(dir.getFrontOffsetX(), dir.getFrontOffsetY(), dir.getFrontOffsetZ())
                    .normalize();
            Vector3 movementVec =
                normalVector
                    .multiply(-2 * currentMovementVec.dotProduct(normalVector))
                    .add(currentMovementVec);

            motionX = movementVec.x;
            motionY = movementVec.y;
            motionZ = movementVec.z;
            bounced = true;

            if (!worldObj.isRemote) setTimesBounced(getTimesBounced() + 1);
          }

          break;
        }
      case ENTITY:
        {
          if (!worldObj.isRemote
              && pos.entityHit != null
              && pos.entityHit instanceof EntityLivingBase
              && pos.entityHit != getThrower()) {
            EntityLivingBase thrower = getThrower();
            pos.entityHit.attackEntityFrom(
                thrower != null
                    ? thrower instanceof EntityPlayer
                        ? DamageSource.causeThrownDamage(this, thrower)
                        : DamageSource.causeMobDamage(thrower)
                    : DamageSource.generic,
                12);
            if (isFire()) pos.entityHit.setFire(5);
            else if (worldObj.rand.nextInt(3) == 0)
              ((EntityLivingBase) pos.entityHit)
                  .addPotionEffect(new PotionEffect(MobEffects.POISON, 60, 0));
          }

          break;
        }
    }
  }
Esempio n. 7
0
 /**
  * Whether it is connected on the specified side
  *
  * @param world The World
  * @param pos The Block pos
  * @param facing The Side
  * @return Whether it is connected
  */
 public static boolean isConnected(IBlockAccess world, BlockPos pos, EnumFacing facing) {
   return blockStatesEqual(
       getBlockOrFacade(world, pos, facing),
       getBlockOrFacade(
           world,
           pos(
               pos.getX() + facing.getFrontOffsetX(),
               pos.getY() + facing.getFrontOffsetY(),
               pos.getZ() + facing.getFrontOffsetZ()),
           facing));
 }
Esempio n. 8
0
 private void putVertex(
     UnpackedBakedQuad.Builder builder,
     EnumFacing side,
     float x,
     float y,
     float z,
     float u,
     float v) {
   for (int e = 0; e < format.getElementCount(); e++) {
     switch (format.getElement(e).getUsage()) {
       case POSITION:
         float[] data =
             new float[] {
               x - side.getDirectionVec().getX() * eps,
               y,
               z - side.getDirectionVec().getZ() * eps,
               1
             };
         if (transformation.isPresent()
             && transformation.get() != TRSRTransformation.identity()) {
           Vector4f vec = new Vector4f(data);
           transformation.get().getMatrix().transform(vec);
           vec.get(data);
         }
         builder.put(e, data);
         break;
       case COLOR:
         builder.put(
             e,
             ((color >> 16) & 0xFF) / 255f,
             ((color >> 8) & 0xFF) / 255f,
             (color & 0xFF) / 255f,
             ((color >> 24) & 0xFF) / 255f);
         break;
       case UV:
         if (format.getElement(e).getIndex() == 0) {
           builder.put(e, u, v, 0f, 1f);
           break;
         }
       case NORMAL:
         builder.put(
             e,
             (float) side.getFrontOffsetX(),
             (float) side.getFrontOffsetY(),
             (float) side.getFrontOffsetZ(),
             0f);
         break;
       default:
         builder.put(e);
         break;
     }
   }
 }
  @Override
  public Object execute(SpellContext context) throws SpellRuntimeException {
    Entity e = this.<Entity>getParamValue(context, target);

    if (e == null) throw new SpellRuntimeException(SpellRuntimeException.NULL_TARGET);
    Vec3d look = e.getLook(1F);
    EnumFacing facing =
        EnumFacing.getFacingFromVector(
            (float) look.xCoord, (float) look.yCoord, (float) look.zCoord);

    return new Vector3(
        facing.getFrontOffsetX(), facing.getFrontOffsetY(), facing.getFrontOffsetZ());
  }
 @Override
 protected ItemStack dispenseStack(IBlockSource dispenser, ItemStack dispensedItem) {
   EnumFacing enumfacing = BlockDispenser.func_149937_b(dispenser.getBlockMetadata());
   World world = dispenser.getWorld();
   int i = dispenser.getXInt() + enumfacing.getFrontOffsetX();
   int j = dispenser.getYInt() + enumfacing.getFrontOffsetY();
   int k = dispenser.getZInt() + enumfacing.getFrontOffsetZ();
   EntityTinyTNTPrimed primedTinyTNTEntity =
       new EntityTinyTNTPrimed(world, i + 0.5F, j + 0.5F, k + 0.5F, null);
   world.spawnEntityInWorld(primedTinyTNTEntity);
   --dispensedItem.stackSize;
   return dispensedItem;
 }
  @Override
  public ItemStack dispenseStack(IBlockSource block, ItemStack stack) {
    EnumFacing enumfacing = BlockDispenser.func_149937_b(block.getBlockMetadata());
    double d0 = block.getX() + enumfacing.getFrontOffsetX();
    double d1 = block.getYInt() + 0.2F;
    double d2 = block.getZ() + enumfacing.getFrontOffsetZ();
    Entity entity = ItemEntityEgg.spawnEntity(block.getWorld(), stack.getItemDamage(), d0, d1, d2);

    if (entity instanceof EntityLivingBase && stack.hasDisplayName())
      ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());

    stack.splitStack(1);
    return stack;
  }
  public ItemStack dispenseStack(IBlockSource BlockSource, ItemStack stack) {
    EnumFacing enumfacing = BlockDispenser.getFacing(BlockSource.getBlockMetadata());
    double d0 = BlockSource.getX() + (double) enumfacing.getFrontOffsetX();
    double d1 = BlockSource.getY() + (double) enumfacing.getFrontOffsetY();
    double d2 = BlockSource.getZ() + (double) enumfacing.getFrontOffsetZ();
    Entity entity =
        ItemGaiaSpawnEgg.spawnCreature(BlockSource.getWorld(), stack.getItemDamage(), d0, d1, d2);

    if (entity instanceof EntityLivingBase && stack.hasDisplayName()) {
      ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());
    }

    stack.splitStack(1);
    return stack;
  }
Esempio n. 13
0
 private void addPositions(WorldData world, BlockPos pos, ReachData c, EnumFacing d) {
   int dvertMax = 4;
   for (int dhor = 0; dhor < 4; dhor++) {
     int y = pos.getY() - dhor;
     for (int dvert = 1; dvert <= dvertMax; dvert++) {
       int x = pos.getX() + dvert * d.getFrontOffsetX();
       int z = pos.getZ() + dvert * d.getFrontOffsetZ();
       if (!THROUGH_REACHABLE.isAt(world, x, y, z)) {
         dvertMax = dvert;
       } else if (dvert > 1) {
         BlockPos allowed = new BlockPos(x, y, z);
         addReachable(allowed, c);
       }
     }
   }
 }
 /** Dispense the specified stack, play the dispense sound and spawn particles. */
 protected ItemStack dispenseStack(IBlockSource par1IBlockSource, ItemStack par2ItemStack) {
   EnumFacing enumfacing = BlockDispenser.getFacing(par1IBlockSource.getBlockMetadata());
   World world = par1IBlockSource.getWorld();
   int i = par1IBlockSource.getXInt() + enumfacing.getFrontOffsetX();
   int j = par1IBlockSource.getYInt() + enumfacing.getFrontOffsetY();
   int k = par1IBlockSource.getZInt() + enumfacing.getFrontOffsetZ();
   EntityTNTPrimed entitytntprimed =
       new EntityTNTPrimed(
           world,
           (double) ((float) i + 0.5F),
           (double) ((float) j + 0.5F),
           (double) ((float) k + 0.5F),
           (EntityLivingBase) null);
   world.spawnEntityInWorld(entitytntprimed);
   --par2ItemStack.stackSize;
   return par2ItemStack;
 }
  @Override
  public void executeLogic(
      World par1World,
      int par2,
      int par3,
      int par4,
      ItemStack par5ItemStack,
      Entity triggerer,
      boolean willBlockBeRemoved) {
    EnumFacing enumfacing = getFacing(par1World, par2, par3, par4);
    double d0 = par2 + Math.random() + (double) enumfacing.getFrontOffsetX();
    double d1 = (double) ((float) par3 + 0.2F);
    double d2 = par4 + Math.random() + (double) enumfacing.getFrontOffsetZ();
    Entity entity =
        ItemMonsterPlacer.spawnCreature(par1World, par5ItemStack.getItemDamage(), d0, d1, d2);

    if (entity instanceof EntityLivingBase && par5ItemStack.hasDisplayName()) {
      ((EntityLiving) entity).setCustomNameTag(par5ItemStack.getDisplayName());
    }
  }
  public static void doDispense(
      World worldIn, ItemStack stack, int speed, EnumFacing p_82486_3_, IPosition position) {
    double var5 = position.getX();
    double var7 = position.getY();
    double var9 = position.getZ();
    if (p_82486_3_.getAxis() == EnumFacing.Axis.Y) {
      var7 -= 0.125D;
    } else {
      var7 -= 0.15625D;
    }

    EntityItem var11 = new EntityItem(worldIn, var5, var7, var9, stack);
    double var12 = worldIn.rand.nextDouble() * 0.1D + 0.2D;
    var11.motionX = (double) p_82486_3_.getFrontOffsetX() * var12;
    var11.motionY = 0.20000000298023224D;
    var11.motionZ = (double) p_82486_3_.getFrontOffsetZ() * var12;
    var11.motionX += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double) speed;
    var11.motionY += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double) speed;
    var11.motionZ += worldIn.rand.nextGaussian() * 0.007499999832361937D * (double) speed;
    worldIn.spawnEntityInWorld(var11);
  }
 private int func_82488_a(EnumFacing facingIn) {
   return facingIn.getFrontOffsetX() + 1 + (facingIn.getFrontOffsetZ() + 1) * 3;
 }
Esempio n. 18
0
  void markValidLakesThenFill(World world, int chunkX, int chunkZ) {
    int size = 16 * 3;

    int dx, dz;
    int ndx, ndz;
    int yPos, nhgt, chunkIndex, nchunkIndex;

    int rain =
        VCraftWorld.instance.getRainfall(
            world.getHorizon(new BlockPos(chunkX * 16 + 8, 0, chunkZ * 16 + 8)));
    if (rain < 100) rain /= 2;
    int maxTries = (rain * rain) / (8 * 255);
    // System.out.println("rain = "+rain+", so tries: " + maxTries);

    Queue<Point> queue = new LinkedList<Point>();
    Queue<Point> water = new LinkedList<Point>();

    int lakeYPos;

    while (maxTries-- > 0) {
      dx = world.rand.nextInt(16);
      dz = world.rand.nextInt(16);

      queue.clear();
      water.clear();
      int[] checked = new int[size * size];

      BlockPos pos = getHorizon(world, new BlockPos(chunkX * 16 + dx, 0, chunkZ * 16 + dz));
      if (pos == null) continue;

      lakeYPos = pos.getY();
      queue.add(new Point(dx, dz));
      checked[(dz + 16) * size + dx + 16] = 1;

      while (!queue.isEmpty()) {
        Point p = queue.remove();

        for (int i = 0; i < EnumFacing.HORIZONTALS.length; i++) {
          EnumFacing direction = EnumFacing.HORIZONTALS[i];
          ndx = p.x + direction.getFrontOffsetX();
          ndz = p.y + direction.getFrontOffsetZ();

          BlockPos neibpos = new BlockPos(chunkX * 16 + ndx, lakeYPos, chunkZ * 16 + ndz);

          // Cannot be at our 3x3 chunk border and we need a solid face below the water
          // otherwise cancel lake generation
          if (ndx > -15
              && ndz > -15
              && ndx < 31
              && ndz < 31
              && world.isSideSolid(neibpos.down(), EnumFacing.UP)) {

            // Already checked or did we reach a lake border?
            if (checked[(ndz + 16) * size + ndx + 16] == 0
                && world.getBlockState(neibpos).getBlock().isReplaceable(world, neibpos)) {
              queue.add(new Point(ndx, ndz));
              water.add(new Point(ndx, ndz));
              checked[(ndz + 16) * size + ndx + 16] = 1;
            }

          } else {
            water.clear();
            queue.clear();
            break;
          }
        }
      }

      /*if (water.size() > 0) {
      	System.out.println("found " + water.size() + " water points");
      }*/

      for (Point p : water) {
        pos = new BlockPos(chunkX * 16 + p.x, lakeYPos, chunkZ * 16 + p.y);

        if (world.getBlockState(pos).getBlock().isReplaceable(world, pos)) {
          world.setBlockState(pos, Blocks.water.getDefaultState());
        }
      }
    }
  }
Esempio n. 19
0
  /** Called on both Client and Server when World#addBlockEvent is called */
  public boolean onBlockEventReceived(
      World worldIn, BlockPos pos, IBlockState state, int eventID, int eventParam) {
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);

    if (!worldIn.isRemote) {
      boolean flag = this.shouldBeExtended(worldIn, pos, enumfacing);

      if (flag && eventID == 1) {
        worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2);
        return false;
      }

      if (!flag && eventID == 0) {
        return false;
      }
    }

    if (eventID == 0) {
      if (!this.doMove(worldIn, pos, enumfacing, true)) {
        return false;
      }

      worldIn.setBlockState(pos, state.withProperty(EXTENDED, Boolean.valueOf(true)), 2);
      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "tile.piston.out",
          0.5F,
          worldIn.rand.nextFloat() * 0.25F + 0.6F);
    } else if (eventID == 1) {
      TileEntity tileentity1 = worldIn.getTileEntity(pos.offset(enumfacing));

      if (tileentity1 instanceof TileEntityPiston) {
        ((TileEntityPiston) tileentity1).clearPistonTileEntity();
      }

      worldIn.setBlockState(
          pos,
          Blocks.piston_extension
              .getDefaultState()
              .withProperty(BlockPistonMoving.FACING, enumfacing)
              .withProperty(
                  BlockPistonMoving.TYPE,
                  this.isSticky
                      ? BlockPistonExtension.EnumPistonType.STICKY
                      : BlockPistonExtension.EnumPistonType.DEFAULT),
          3);
      worldIn.setTileEntity(
          pos,
          BlockPistonMoving.newTileEntity(
              this.getStateFromMeta(eventParam), enumfacing, false, true));

      if (this.isSticky) {
        BlockPos blockpos =
            pos.add(
                enumfacing.getFrontOffsetX() * 2,
                enumfacing.getFrontOffsetY() * 2,
                enumfacing.getFrontOffsetZ() * 2);
        Block block = worldIn.getBlockState(blockpos).getBlock();
        boolean flag1 = false;

        if (block == Blocks.piston_extension) {
          TileEntity tileentity = worldIn.getTileEntity(blockpos);

          if (tileentity instanceof TileEntityPiston) {
            TileEntityPiston tileentitypiston = (TileEntityPiston) tileentity;

            if (tileentitypiston.getFacing() == enumfacing && tileentitypiston.isExtending()) {
              tileentitypiston.clearPistonTileEntity();
              flag1 = true;
            }
          }
        }

        if (!flag1
            && block.getMaterial() != Material.air
            && canPush(block, worldIn, blockpos, enumfacing.getOpposite(), false)
            && (block.getMobilityFlag() == 0
                || block == Blocks.piston
                || block == Blocks.sticky_piston)) {
          this.doMove(worldIn, pos, enumfacing, false);
        }
      } else {
        worldIn.setBlockToAir(pos.offset(enumfacing));
      }

      worldIn.playSoundEffect(
          (double) pos.getX() + 0.5D,
          (double) pos.getY() + 0.5D,
          (double) pos.getZ() + 0.5D,
          "tile.piston.in",
          0.5F,
          worldIn.rand.nextFloat() * 0.15F + 0.6F);
    }

    return true;
  }