Пример #1
0
 /** Called when the block is placed in the world. */
 @Override
 public void onBlockPlacedBy(
     World par1World,
     int x,
     int y,
     int z,
     EntityLivingBase par5EntityLivingBase,
     ItemStack par6ItemStack) {
   TileEntity te = par1World.getTileEntity(x, y, z);
   ((TileEntityDoorController) te).setOwner(par5EntityLivingBase.getUniqueID().toString());
   ((TileEntityDoorController) te)
       .overrideTexture(
           ContentRegistry.DoorController,
           new ItemStack(Item.getItemFromBlock(ContentRegistry.DoorController)),
           ForgeDirection.getOrientation(1));
 }
Пример #2
0
  /**
   * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
   */
  @Override
  @SideOnly(Side.CLIENT)
  public IIcon getIcon(IBlockAccess block, int x, int y, int z, int side) {
    // int metadata = block.getBlockMetadata(x, y, z);
    TileEntityDoorController te = (TileEntityDoorController) block.getTileEntity(x, y, z);
    IIcon thisBlockTextures[] = new IIcon[6];

    if (te.DoorControllerCamo[0] != null) {
      te.overrideTexture(te.DoorControllerCamo[0]);
    }
    for (int getSide = 0; getSide < thisBlockTextures.length; getSide++) {
      if (te.blockTextures[getSide] != null) {
        if (side == getSide) {
          return te.blockTextures[getSide];
        }
      }
    }

    return topIcon;
  }
Пример #3
0
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer player,
      int side,
      float clickX,
      float clickY,
      float clickZ) {
    TileEntityDoorController tileEntity = (TileEntityDoorController) world.getTileEntity(x, y, z);
    if (tileEntity == null || player.isSneaking()) {
      return false;
    }

    // If the user is not the owner, or the user is not in creative drop out.
    if (tileEntity.getOwner() != null) {
      if (!tileEntity.getOwner().equals(player.getUniqueID().toString())
          && !player.capabilities.isCreativeMode) {
        if (!tileEntity.getOwner().isEmpty()) {
          return false;
        }
      }
    }
    // Change the block texture
    if (player.getCurrentEquippedItem() != null
        && player.getCurrentEquippedItem().getItem() instanceof ItemBlock) {
      Block block = Block.getBlockFromItem(player.getCurrentEquippedItem().getItem());
      Item oldBlock = tileEntity.DoorControllerCamo[0].getItem();
      if (block.isOpaqueCube()
          || block instanceof BlockGlass
          || block instanceof BlockStainedGlass) {
        if (!tileEntity
            .DoorControllerCamo[0]
            .getItem()
            .equals(player.getCurrentEquippedItem().getItem())) {
          if (player.capabilities.isCreativeMode) {
            tileEntity.overrideTexture(
                block,
                player.getCurrentEquippedItem().splitStack(0),
                ForgeDirection.getOrientation(side));
          } else {
            tileEntity.overrideTexture(
                block,
                player.getCurrentEquippedItem().splitStack(1),
                ForgeDirection.getOrientation(side));
          }
          world.scheduleBlockUpdate(x, y, z, tileEntity.block, 5);
          if (!world.isRemote) {
            ItemStack testAgainst = new ItemStack(oldBlock);
            if (!testAgainst
                .getItem()
                .equals(Item.getItemFromBlock(ContentRegistry.DoorController))) {
              EntityItem myItemEntity = new EntityItem(world, x, y, z, testAgainst);
              world.spawnEntityInWorld(myItemEntity);
            }
          }
        }
      }
      // Remove the block texture with the scrench
    } else if (player.getCurrentEquippedItem() != null
        && player.getCurrentEquippedItem().getItem() instanceof Wrench) {
      if (!world.isRemote) {
        if (!tileEntity
            .DoorControllerCamo[0]
            .getItem()
            .equals(Item.getItemFromBlock(ContentRegistry.DoorController))) {
          EntityItem myItemEntity =
              new EntityItem(world, x, y, z, tileEntity.DoorControllerCamo[0]);
          world.spawnEntityInWorld(myItemEntity);
        }
      }
      tileEntity.overrideTexture(
          ContentRegistry.DoorController,
          new ItemStack(Item.getItemFromBlock(ContentRegistry.DoorController)),
          ForgeDirection.getOrientation(side));
      world.scheduleBlockUpdate(x, y, z, tileEntity.block, 5);
    }
    return true;
  }