protected int calculateInputStrength(World worldIn, BlockPos pos, IBlockState state) {
    int i = super.calculateInputStrength(worldIn, pos, state);
    EnumFacing enumfacing = (EnumFacing) state.getValue(FACING);
    BlockPos blockpos = pos.offset(enumfacing);
    IBlockState iblockstate = worldIn.getBlockState(blockpos);

    if (iblockstate.hasComparatorInputOverride()) {
      i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
    } else if (i < 15 && iblockstate.isNormalCube()) {
      blockpos = blockpos.offset(enumfacing);
      iblockstate = worldIn.getBlockState(blockpos);

      if (iblockstate.hasComparatorInputOverride()) {
        i = iblockstate.getComparatorInputOverride(worldIn, blockpos);
      } else if (iblockstate.getMaterial() == Material.AIR) {
        EntityItemFrame entityitemframe = this.findItemFrame(worldIn, enumfacing, blockpos);

        if (entityitemframe != null) {
          i = entityitemframe.getAnalogOutput();
        }
      }
    }

    return i;
  }
  /** returns whether or not there is space for a tree to grow at a certain position */
  private boolean isSpaceAt(World worldIn, BlockPos leavesPos, int height) {
    boolean flag = true;

    if (leavesPos.getY() >= 1 && leavesPos.getY() + height + 1 <= 256) {
      for (int i = 0; i <= 1 + height; ++i) {
        int j = 2;

        if (i == 0) {
          j = 1;
        } else if (i >= 1 + height - 2) {
          j = 2;
        }

        for (int k = -j; k <= j && flag; ++k) {
          for (int l = -j; l <= j && flag; ++l) {
            if (leavesPos.getY() + i < 0
                || leavesPos.getY() + i >= 256
                || !this.isReplaceable(worldIn, leavesPos.add(k, i, l))) {
              flag = false;
            }
          }
        }
      }

      return flag;
    } else {
      return false;
    }
  }
  private void dropRecord(World worldIn, BlockPos pos, IBlockState state) {
    if (!worldIn.isRemote) {
      TileEntity tileentity = worldIn.getTileEntity(pos);

      if (tileentity instanceof BlockJukebox.TileEntityJukebox) {
        BlockJukebox.TileEntityJukebox blockjukebox$tileentityjukebox =
            (BlockJukebox.TileEntityJukebox) tileentity;
        ItemStack itemstack = blockjukebox$tileentityjukebox.getRecord();

        if (itemstack != null) {
          worldIn.playEvent(1010, pos, 0);
          worldIn.playRecord(pos, (SoundEvent) null);
          blockjukebox$tileentityjukebox.setRecord((ItemStack) null);
          float f = 0.7F;
          double d0 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
          double d1 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.06000000238418579D + 0.6D;
          double d2 = (double) (worldIn.rand.nextFloat() * 0.7F) + 0.15000000596046448D;
          ItemStack itemstack1 = itemstack.copy();
          EntityItem entityitem =
              new EntityItem(
                  worldIn,
                  (double) pos.getX() + d0,
                  (double) pos.getY() + d1,
                  (double) pos.getZ() + d2,
                  itemstack1);
          entityitem.setDefaultPickupDelay();
          worldIn.spawnEntityInWorld(entityitem);
        }
      }
    }
  }
 @Override
 public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
   if (pos.getY() == neighbor.getY() && world instanceof World) {
     neighborChanged(
         world.getBlockState(pos), (World) world, pos, world.getBlockState(neighbor).getBlock());
   }
 }
Exemple #5
0
  /* Straight from InventoryHelper in vanilla code */
  public static void spawnInWorld(World world, BlockPos pos, ItemStack itemStack) {

    float f = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
    float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;

    while (itemStack.stackSize > 0) {
      int i = RANDOM.nextInt(21) + 10;

      if (i > itemStack.stackSize) i = itemStack.stackSize;

      itemStack.stackSize -= i;
      EntityItem entityitem =
          new EntityItem(
              world,
              pos.getX() + (double) f,
              pos.getY() + (double) f1,
              pos.getZ() + (double) f2,
              new ItemStack(itemStack.getItem(), i, itemStack.getMetadata()));

      if (itemStack.hasTagCompound())
        entityitem
            .getEntityItem()
            .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());

      float f3 = 0.05F;
      entityitem.motionX = RANDOM.nextGaussian() * (double) f3;
      entityitem.motionY = RANDOM.nextGaussian() * (double) f3 + 0.20000000298023224D;
      entityitem.motionZ = RANDOM.nextGaussian() * (double) f3;
      world.spawnEntityInWorld(entityitem);
    }
  }
 @Override
 public boolean canPlaceBlockAt(World worldIn, BlockPos pos) {
   IBlockState soil = worldIn.getBlockState(pos.down());
   return super.canPlaceBlockAt(worldIn, pos)
       && soil.getBlock()
           .canSustainPlant(soil, worldIn, pos.down(), net.minecraft.util.EnumFacing.UP, this);
 }
 @Override
 protected void generateStalagmiteBase(World world, Random random, BlockPos botY, int aux) {
   if (world.getBlockState(botY.down()) == Blocks.stone)
     world.setBlockState(botY.down(), Blocks.sandstone.getDefaultState(), 2);
   super.generateStalagmiteBase(world, random, botY, aux);
   Utils.convertToSandType(world, random, botY);
 }
 float getGrowthSpeed(World world, BlockPos pos, IBlockState sate, int light) {
   float growth = 0.125f * (light - 11);
   if (world.canBlockSeeSky(pos)) growth += 2f;
   IBlockState soil = world.getBlockState(pos.add(0, -1, 0));
   if (soil.getBlock().isFertile(world, pos.add(0, -1, 0))) growth *= 1.5f;
   return 1f + growth;
 }
 @Override
 public void toBytes(ByteBuf buf) {
   buf.writeInt(pos.getX());
   buf.writeInt(pos.getY());
   buf.writeInt(pos.getZ());
   ByteBufUtils.writeItemStack(buf, activeItem);
   MagicAmounts.writeAmounts(buf, remaining);
 }
Exemple #10
0
 /** Returns if the supplied Coordinate is completely inside the bounding box */
 public boolean isVecInside(BlockPos c) {
   return c.getX() >= this.minX
       && c.getX() < this.maxX
       && (c.getY() >= this.minY
           && c.getY() < this.maxY
           && c.getZ() >= this.minZ
           && c.getZ() < this.maxZ);
 }
Exemple #11
0
 @Override
 public void breakBlock(World world, BlockPos pos, IBlockState state, EntityPlayer player) {
   for (int i = 0; i < inventory.size(); i++) {
     if (!world.isRemote) {
       world.spawnEntityInWorld(
           new EntityItem(
               world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, inventory.get(i)));
     }
   }
   this.invalidate();
 }
 @Override
 public void grow(World world, Random rand, BlockPos pos, IBlockState state) {
   int meta = this.getMetaFromState(state);
   if (meta < getMaxMeta(meta)) {
     int span = getMaxMeta(meta) - meta;
     int newMeta = meta + rand.nextInt(span) + 1;
     if (newMeta != meta) world.setBlockState(pos, this.getStateFromMeta(newMeta));
     meta = newMeta;
   }
   if (meta == 4 && world.isAirBlock(pos.add(0, 1, 0)))
     world.setBlockState(pos.add(0, 1, 0), this.getStateFromMeta(meta + 1));
 }
  /**
   * Get the actual Block state of this Block at the given position. This applies properties not
   * visible in the metadata, such as fence connections.
   */
  public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos) {
    EnumFacing.Axis enumfacing$axis = ((EnumFacing) state.getValue(FACING)).getAxis();

    if (enumfacing$axis == EnumFacing.Axis.Z
            && (worldIn.getBlockState(pos.west()).getBlock() == Blocks.COBBLESTONE_WALL
                || worldIn.getBlockState(pos.east()).getBlock() == Blocks.COBBLESTONE_WALL)
        || enumfacing$axis == EnumFacing.Axis.X
            && (worldIn.getBlockState(pos.north()).getBlock() == Blocks.COBBLESTONE_WALL
                || worldIn.getBlockState(pos.south()).getBlock() == Blocks.COBBLESTONE_WALL)) {
      state = state.withProperty(IN_WALL, Boolean.valueOf(true));
    }

    return state;
  }
 public void generateArchEW(World world, Random rand, BlockPos position) {
   int height = 3 + rand.nextInt(1);
   int width = 1 + rand.nextInt(2);
   for (int sides = 0; sides < height; sides++) {
     world.setBlockState(
         position.up(sides).north(width / 2), ModBlocks.frozenCobblestone.getDefaultState(), 3);
     world.setBlockState(
         position.up(sides).south(width / 2), ModBlocks.frozenCobblestone.getDefaultState(), 3);
   }
   for (int way = 0; way < width; way++) {
     world.setBlockState(
         position.up(height).south(way), ModBlocks.frozenCobblestone.getDefaultState(), 3);
   }
 }
Exemple #15
0
  /** Send message to all within 64 blocks that have this chunk loaded */
  public static void sendToNearby(World world, BlockPos pos, IMessage toSend) {
    if (world instanceof WorldServer) {
      WorldServer ws = (WorldServer) world;

      for (EntityPlayer player : ws.playerEntities) {
        EntityPlayerMP playerMP = (EntityPlayerMP) player;

        if (playerMP.getDistanceSq(pos) < 64 * 64
            && ws.getPlayerChunkMap()
                .isPlayerWatchingChunk(playerMP, pos.getX() >> 4, pos.getZ() >> 4)) {
          HANDLER.sendTo(toSend, playerMP);
        }
      }
    }
  }
  @Override
  public void processBlockWithinRadius(
      Spellcast cast,
      BlockPos blockPos,
      IBlockState currentState,
      float r,
      @Nullable RayTraceResult mop) {
    if (mop != null) {
      blockPos = blockPos.offset(mop.sideHit);
      currentState = cast.world.getBlockState(blockPos);
    }

    Block block = currentState.getBlock();

    if (block == Blocks.AIR) {
      if (spawnSourceBlocks) {
        cast.world.setBlockState(
            blockPos,
            Blocks.FLOWING_WATER.getDefaultState().withProperty(BlockDynamicLiquid.LEVEL, 0));
      } else {
        cast.world.setBlockState(
            blockPos,
            Blocks.FLOWING_WATER.getDefaultState().withProperty(BlockDynamicLiquid.LEVEL, 15));
      }
    }
  }
Exemple #17
0
 @Override
 public boolean equals(Object o) {
   return o instanceof InvWithLocation
       && handler.equals(((InvWithLocation) o).handler)
       && world == ((InvWithLocation) o).world
       && pos.equals(((InvWithLocation) o).pos);
 }
 private void runThroughNetwork(BlockPos pos) {
   for (EnumFacing facing : EnumFacing.values()) {
     BlockPos searchPos = pos.offset(facing);
     if (worldObj.getTileEntity(pos) instanceof INetworkPart
         && !((INetworkPart) worldObj.getTileEntity(pos)).getNeighborFaces().contains(facing))
       continue;
     if (worldObj.getTileEntity(searchPos) instanceof INetworkPart
         && !((INetworkPart) worldObj.getTileEntity(searchPos))
             .getNeighborFaces()
             .contains(facing.getOpposite())) continue;
     if (!getWorld().isAirBlock(searchPos)) {
       TileEntity tile = getWorld().getTileEntity(searchPos);
       if (tile != null) {
         if (tile instanceof TileNetworkCore && !tile.getPos().equals(this.pos)) {
           worldObj.setBlockToAir(searchPos);
           worldObj.playEvent(2001, searchPos, Block.getIdFromBlock(Registry.networkCore));
           StackHelper.spawnItemStack(worldObj, searchPos, new ItemStack(Registry.networkCore));
           markForNetworkInit();
         } else if (tile instanceof INetworkPart && !network.networkParts.contains(tile)) {
           network.addPart((INetworkPart) tile);
         } else if (InvHelper.hasItemHandler(tile, facing.getOpposite())
             && !network.networkParts.contains(
                 InvHelper.getItemHandler(tile, facing.getOpposite()))) {
           network.addPart(
               new InventoryNetworkPart(
                   tile.getWorld(),
                   searchPos,
                   InvHelper.getItemHandler(tile, facing.getOpposite())));
         } else continue;
         runThroughNetwork(searchPos);
       }
     }
   }
 }
  private int getNeighborEncouragement(World worldIn, BlockPos pos) {
    if (!worldIn.isAirBlock(pos)) return 0;
    else {
      int i = 0;

      for (EnumFacing enumfacing : EnumFacing.values())
        i =
            Math.max(
                worldIn
                    .getBlockState(pos.offset(enumfacing))
                    .getBlock()
                    .getFlammability(worldIn, pos.offset(enumfacing), enumfacing.getOpposite()),
                i);

      return i;
    }
  }
  public static void DropItems(TileEntity tileEntity, int min, int max) {
    if (!(tileEntity instanceof IInventory)) {
      return;
    }

    IInventory inventory = (IInventory) tileEntity;
    World world = tileEntity.getWorld();
    BlockPos blockPos = tileEntity.getPos();

    for (int i = min; i <= max; i++) {
      ItemStack itemStack = inventory.getStackInSlot(i);

      if (itemStack != null && itemStack.stackSize > 0) {
        Random rand = new Random();

        float dX = rand.nextFloat() * 0.8F + 0.1F;
        float dY = rand.nextFloat() * 0.8F + 0.1F;
        float dZ = rand.nextFloat() * 0.8F + 0.1F;

        EntityItem entityItem =
            new EntityItem(
                world,
                blockPos.getX() + dX,
                blockPos.getY() + dY,
                blockPos.getZ() + dZ,
                itemStack.copy());

        if (itemStack.hasTagCompound()) {
          entityItem
              .getEntityItem()
              .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());
        }

        float factor = 0.05F;
        entityItem.motionX = rand.nextGaussian() * factor;
        entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
        entityItem.motionZ = rand.nextGaussian() * factor;
        world.spawnEntityInWorld(entityItem);
        itemStack.stackSize = 0;
        inventory.setInventorySlotContents(i, null);
      }
    }

    inventory.markDirty();
  }
Exemple #21
0
 /**
  * Return an {@link AxisAlignedBB} that controls the visible scope of a {@link
  * TileEntitySpecialRenderer} associated with this {@link TileEntity} Defaults to the collision
  * bounding box {@link Block#getCollisionBoundingBoxFromPool(World, int, int, int)} associated
  * with the block at this location.
  *
  * @return an appropriately size {@link AxisAlignedBB} for the {@link TileEntity}
  */
 @SideOnly(Side.CLIENT)
 public net.minecraft.util.math.AxisAlignedBB getRenderBoundingBox() {
   net.minecraft.util.math.AxisAlignedBB bb = INFINITE_EXTENT_AABB;
   Block type = getBlockType();
   BlockPos pos = getPos();
   if (type == Blocks.ENCHANTING_TABLE) {
     bb = new net.minecraft.util.math.AxisAlignedBB(pos, pos.add(1, 1, 1));
   } else if (type == Blocks.CHEST || type == Blocks.TRAPPED_CHEST) {
     bb = new net.minecraft.util.math.AxisAlignedBB(pos.add(-1, 0, -1), pos.add(2, 2, 2));
   } else if (type != null && type != Blocks.BEACON) {
     net.minecraft.util.math.AxisAlignedBB cbb = null;
     try {
       cbb =
           worldObj
               .getBlockState(getPos())
               .getCollisionBoundingBox(worldObj, pos)
               .addCoord(pos.getX(), pos.getY(), pos.getZ());
     } catch (Exception e) {
       // We have to capture any exceptions that may occur here because BUKKIT servers like to send
       // the tile entity data BEFORE the chunk data, you know, the OPPOSITE of what vanilla does!
       // So we can not GARENTEE that the world state is the real state for the block...
       // So, once again in the long line of US having to accommodate BUKKIT breaking things,
       // here it is, assume that the TE is only 1 cubic block. Problem with this is that it may
       // cause the TileEntity renderer to error further down the line! But alas, nothing we can
       // do.
       cbb =
           new net.minecraft.util.math.AxisAlignedBB(
               getPos().add(-1, 0, -1), getPos().add(1, 1, 1));
     }
     if (cbb != null) bb = cbb;
   }
   return bb;
 }
 @Override
 public boolean canBlockStay(World world, BlockPos pos, IBlockState state) {
   boolean b = super.canBlockStay(world, pos, state);
   if (this.getMetaFromState(state) == 5) {
     IBlockState stateBelow = world.getBlockState(pos.add(0, -1, 0));
     b = stateBelow.getBlock().equals(this) && this.getMetaFromState(stateBelow) == getMaxMeta(0);
   }
   return b;
 }
 @Override
 public void updateTick(World world, BlockPos pos, IBlockState state, Random random) {
   this.checkAndDropBlock(world, pos, state);
   int light = world.getLight(pos);
   if (light >= 12) {
     int meta = this.getMetaFromState(state);
     if (meta > 4) return;
     float growth = this.getGrowthSpeed(world, pos, state, light);
     if (random.nextInt((int) (50F / growth) + 1) == 0) {
       if (this.getMaxMeta(meta) != meta) {
         meta++;
         world.setBlockState(pos, this.getStateFromMeta(meta));
       }
       if (meta > 3 && world.isAirBlock(pos.add(0, 1, 0)))
         world.setBlockState(pos.add(0, 1, 0), this.getStateFromMeta(meta + 1));
     }
   }
 }
  @Override
  public EnumActionResult onItemUse(
      ItemStack stack,
      EntityPlayer player,
      World world,
      BlockPos pos,
      EnumHand hand,
      EnumFacing side,
      float hitX,
      float hitY,
      float hitZ) {
    if (!world.isRemote) {
      HelicopterBaseEntity helicopter = new HelicopterBaseEntity(world, UUID.randomUUID());
      helicopter.setPosition(pos.getX() + hitX, pos.getY() + hitY, pos.getZ() + hitZ);
      world.spawnEntityInWorld(helicopter);
    }

    return EnumActionResult.SUCCESS;
  }
 @Override
 public boolean generate(World worldIn, Random rand, BlockPos position) {
   int dragonAge = 50 + rand.nextInt(25);
   burnGround(worldIn, rand, position, dragonAge / 5);
   generateStructures(worldIn, rand, position, dragonAge / 5);
   EntityIceDragon dragon = new EntityIceDragon(worldIn);
   dragon.setGender(dragon.getRNG().nextBoolean());
   dragon.growDragon(dragonAge);
   dragon.setHunger(50);
   dragon.setVariant(new Random().nextInt(4));
   dragon.setPositionAndRotation(
       position.getX() + 0.5,
       worldIn.getHeight(position).getY() + 1.5,
       position.getZ() + 0.5,
       rand.nextFloat() * 360,
       0);
   dragon.homeArea = position;
   worldIn.spawnEntityInWorld(dragon);
   return true;
 }
Exemple #26
0
  public void setPos(BlockPos posIn) {
    if (posIn instanceof BlockPos.MutableBlockPos
        || posIn instanceof BlockPos.PooledMutableBlockPos) {
      LOGGER.warn(
          (String) "Tried to assign a mutable BlockPos to a block entity...",
          (Throwable) (new Error(posIn.getClass().toString())));
      posIn = new BlockPos(posIn);
    }

    this.pos = posIn;
  }
  @Override
  public boolean onBlockActivated(
      World world,
      BlockPos pos,
      IBlockState state,
      EntityPlayer player,
      EnumHand hand,
      ItemStack held,
      EnumFacing facing,
      float fx,
      float par8,
      float par9) {

    System.out.println("Im awake!");
    if (world.isRemote == false) {
      player.openGui(LabStuffMain.instance, 0, world, pos.getX(), pos.getY(), pos.getZ());
      return true;
    }
    return false;
  }
Exemple #28
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;
    }
  }
 public void generateStructures(World world, Random rand, BlockPos position, int radius) {
   for (int i = 0; radius >= 0 && i < 3; ++i) {
     int j = radius + rand.nextInt(2);
     int k = (radius + rand.nextInt(2));
     int l = radius + rand.nextInt(2);
     float f = (float) (j + k + l) * 0.333F + 0.5F;
     for (BlockPos blockpos :
         BlockPos.getAllInBox(position.add(-j, -k, -l), position.add(j, k, l))) {
       if (blockpos.distanceSq(position) <= (double) (f * f)
           && world.isAirBlock(blockpos)
           && world
               .getBlockState(blockpos.down())
               .getBlock()
               .getUnlocalizedName()
               .contains("frozen")) {
         int chance = rand.nextInt(100);
         if (chance < 4) {
           int chance2 = rand.nextInt(20);
           System.out.println(chance2);
           switch (chance2) {
             default:
               generateGoldPile(world, rand, blockpos);
               break;
             case 1:
               generateArchNS(world, rand, blockpos);
               break;
             case 2:
               generateArchEW(world, rand, blockpos);
               break;
           }
         }
       }
     }
   }
 }
  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);
        }
      }
    }
  }