コード例 #1
0
 @Override
 public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) {
   TileEntityDoorController tileEntity = (TileEntityDoorController) world.getTileEntity(x, y, z);
   // 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())) {
       this.setResistance(0F);
       this.setHardness(0F);
     }
   }
 }
コード例 #2
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;
  }