Example #1
0
  @Override
  public boolean attackEntityFrom(DamageSource source, float damage) {
    if (!worldObj.isRemote && !isDead) {
      setTimeSinceHit(10);
      setDamageTaken(this.getDamageTaken() + damage * 10.0F);

      boolean isPlayer = source.getEntity() instanceof EntityPlayer;

      if (this.getDamageTaken() > 20.0F) {
        setDead();
        if (isPlayer) {
          if (!((EntityPlayer) source.getEntity()).capabilities.isCreativeMode)
            dropItem(Extruder.Items.extruder, 1);
          if (source.getEntity().isSprinting()) setMotion(0, 0, 0);
        }

        if (inventory.contents().size() != 0)
          for (ItemStack stack : inventory.contents()) if (stack != null) entityDropItem(stack, 0);
      }

      if (!getRunning())
        setMotion(
            (double) getFacing().offsetX / 10,
            (double) getFacing().offsetY / 10,
            (double) getFacing().offsetZ / 10);
      setRunning(!getRunning());
    }

    if (worldObj.isRemote) worldObj.playAuxSFX(1001, (int) posX, (int) posY, (int) posZ, 0);

    return false;
  }
Example #2
0
 @Override
 public void readEntityFromNBT(NBTTagCompound tag) {
   setFacing(ForgeDirection.getOrientation(tag.getByte(TAG_FACING)));
   setRunning(tag.getBoolean(TAG_RUNNING));
   fuel.readFromNBT(tag, TAG_FUEL);
   inventory.readFromNBT(tag);
 }
Example #3
0
 @Override
 public void writeEntityToNBT(NBTTagCompound tag) {
   tag.setByte(TAG_FACING, (byte) getFacing().ordinal());
   tag.setBoolean(TAG_RUNNING, getRunning());
   fuel.writeToNBT(tag, TAG_FUEL);
   inventory.writeToNBT(tag);
 }
Example #4
0
  @Override
  public void onUpdate() {
    super.onUpdate();

    if (getRunning()) run();
    else postRun();

    if (Config.useFuel && !worldObj.isRemote) {
      if (inventory.getStackInSlot(0) != null
          && TileEntityFurnace.isItemFuel(inventory.getStackInSlot(0))
          && (fuel.get() + TileEntityFurnace.getItemBurnTime(inventory.getStackInSlot(0)))
              <= Config.maxFuelLevel)
        if (inventory.getStackInSlot(0).getItem().equals(Items.lava_bucket)) {
          fuel.modify(TileEntityFurnace.getItemBurnTime(inventory.decrStackSize(0, 1)));
          inventory.setInventorySlotContents(0, new ItemStack(Items.bucket));
        } else {
          fuel.modify(TileEntityFurnace.getItemBurnTime(inventory.decrStackSize(0, 1)));
        }

      if (fuel.isDirty()) sync();
    }

    lastTickPosX = posX;
    lastTickPosY = posY;
    lastTickPosZ = posZ;

    posX += motionX;
    posY += motionY;
    posZ += motionZ;

    setPosition(posX, posY, posZ);

    if (getTimeSinceHit() > 0) setTimeSinceHit(getTimeSinceHit() - 1);
    if (getDamageTaken() > 0) setDamageTaken(getDamageTaken() - 1);
  }
Example #5
0
  private boolean placeBlock(BlockCoord coord) {
    if (worldObj
        .getBlock(coord.x, coord.y, coord.z)
        .canPlaceBlockAt(worldObj, coord.x, coord.y, coord.z)) {
      slot++;
      if (slot > 9) slot = 1;
      if (inventory.getStackInSlot(slot) != null) {
        ItemStack stack = inventory.getStackInSlot(slot);
        if (!(stack.getItem() instanceof ItemBlock)) return false;
        stack = inventory.decrStackSize(slot, 1);
        return worldObj.setBlock(
            coord.x,
            coord.y,
            coord.z,
            Block.getBlockFromItem(stack.getItem()),
            stack.getItemDamage(),
            2);
      }
    }

    return false;
  }
Example #6
0
  private boolean breakBlock(BlockCoord coord) {
    Block block = worldObj.getBlock(coord.x, coord.y, coord.z);
    int blockMetadata = worldObj.getBlockMetadata(coord.x, coord.y, coord.z);

    if (block.equals(Blocks.obsidian)
        || block.equals(Blocks.bedrock)
        || block.equals(Blocks.lava)
        || block.equals(Blocks.flowing_lava)) {
      setRunning(false);
      setMotion(0, 0, 0);
    } else if (block.isBlockSolid(worldObj, coord.x, coord.y, coord.z, blockMetadata)) {
      if (!Config.destroyBlocks) {
        for (int i = 10; i < 37; ++i) { // runs through slots 10-36 (mined inventory)
          if (block.getItemDropped(blockMetadata, rand, 0) == null)
            break; // check for beds, doors...
          ItemStack blockStack =
              new ItemStack(
                  block.getItemDropped(blockMetadata, rand, 0),
                  block.quantityDropped(rand),
                  blockMetadata);
          ItemStack stackInSlot = inventory.getStackInSlot(i);
          if (blockStack.stackSize == 0) break;
          if (stackInSlot != null) {
            if (InventoryUtils.areMergeCandidates(blockStack, stackInSlot)) {
              if (InventoryUtils.tryMergeStacks(blockStack, stackInSlot)) break;
            }
          } else {
            inventory.setInventorySlotContents(i, blockStack);
            break;
          }
        }
      }
      return worldObj.setBlockToAir(coord.x, coord.y, coord.z);
    }

    return false;
  }