Beispiel #1
0
  @Override
  public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    super.receiveCommand(command, side, sender, stream);
    if (side.isClient()) {
      if ("clearItemRequirements".equals(command)) {
        requiredToBuild = null;
      } else if ("setItemRequirements".equals(command)) {
        int size = stream.readUnsignedMedium();
        requiredToBuild = new ArrayList<RequirementItemStack>();
        for (int i = 0; i < size; i++) {
          int itemId = stream.readUnsignedShort();
          int itemDamage = stream.readShort();
          int stackSize = stream.readUnsignedMedium();
          boolean hasCompound = stackSize >= 0x800000;

          ItemStack stack = new ItemStack(Item.getItemById(itemId), 1, itemDamage);
          if (hasCompound) {
            stack.setTagCompound(NetworkUtils.readNBT(stream));
          }

          if (stack != null && stack.getItem() != null) {
            requiredToBuild.add(new RequirementItemStack(stack, stackSize & 0x7FFFFF));
          } else {
            BCLog.logger.error(
                "Corrupt ItemStack in TileBuilder.receiveCommand! This should not happen! (ID "
                    + itemId
                    + ", damage "
                    + itemDamage
                    + ")");
          }
        }
      }
    } else if (side.isServer()) {
      EntityPlayer player = (EntityPlayer) sender;
      if ("eraseFluidTank".equals(command)) {
        int id = stream.readInt();
        if (id < 0 || id >= fluidTanks.length) {
          return;
        }
        if (isUseableByPlayer(player) && player.getDistanceSq(xCoord, yCoord, zCoord) <= 64) {
          fluidTanks[id].setFluid(null);
          sendNetworkUpdate();
        }
      }
    }
  }
  public static void inject(
      ModContainer mod, ASMDataTable data, Side side, ILanguageAdapter languageAdapter) {
    FMLLog.fine("Attempting to inject @SidedProxy classes into %s", mod.getModId());
    Set<ASMData> targets = data.getAnnotationsFor(mod).get(SidedProxy.class.getName());
    ClassLoader mcl = Loader.instance().getModClassLoader();

    for (ASMData targ : targets) {
      try {
        Class<?> proxyTarget = Class.forName(targ.getClassName(), true, mcl);
        Field target = proxyTarget.getDeclaredField(targ.getObjectName());
        if (target == null) {
          // Impossible?
          FMLLog.severe(
              "Attempted to load a proxy type into %s.%s but the field was not found",
              targ.getClassName(), targ.getObjectName());
          throw new LoaderException();
        }

        SidedProxy annotation = target.getAnnotation(SidedProxy.class);
        if (!Strings.isNullOrEmpty(annotation.modId())
            && !annotation.modId().equals(mod.getModId())) {
          FMLLog.fine(
              "Skipping proxy injection for %s.%s since it is not for mod %s",
              targ.getClassName(), targ.getObjectName(), mod.getModId());
          continue;
        }
        String targetType = side.isClient() ? annotation.clientSide() : annotation.serverSide();
        Object proxy = Class.forName(targetType, true, mcl).newInstance();

        if (languageAdapter.supportsStatics() && (target.getModifiers() & Modifier.STATIC) == 0) {
          FMLLog.severe(
              "Attempted to load a proxy type %s into %s.%s, but the field is not static",
              targetType, targ.getClassName(), targ.getObjectName());
          throw new LoaderException();
        }
        if (!target.getType().isAssignableFrom(proxy.getClass())) {
          FMLLog.severe(
              "Attempted to load a proxy type %s into %s.%s, but the types don't match",
              targetType, targ.getClassName(), targ.getObjectName());
          throw new LoaderException();
        }
        languageAdapter.setProxy(target, proxyTarget, proxy);
      } catch (Exception e) {
        FMLLog.log(
            Level.SEVERE,
            e,
            "An error occured trying to load a proxy into %s.%s",
            targ.getAnnotationInfo(),
            targ.getClassName(),
            targ.getObjectName());
        throw new LoaderException(e);
      }
    }

    // Allow language specific proxy injection.
    languageAdapter.setInternalProxies(mod, side, mcl);
  }
 @Override
 public final void register(Side side) {
   if (isCreated) {
     registerItem();
     if (!side.isServer()) {
       clientRegisterItem();
     }
   }
 }
 @Override
 public void execute(EntityPlayer player, Side side) {
   if (side.isServer()) {
     TileEntitySolderingStation tile =
         (TileEntitySolderingStation) player.worldObj.getBlockTileEntity(x, y, z);
     if (remove) {
       tile.remUser(playerName);
     } else {
       tile.updateData(playerName, size, types, upgrade, downgrade);
     }
   }
 }
 @Override
 public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
   if (side.isServer()) {
     if ("setLabel".equals(command)) {
       setLabel(NetworkUtils.readUTF(stream));
     } else if ("switchButton".equals(command)) {
       switchButton(stream.readUnsignedByte(), stream.readUnsignedByte());
     } else if ("setStack".equals(command)) {
       setStack(
           stream.readUnsignedByte(), stream.readUnsignedByte(), NetworkUtils.readStack(stream));
     }
   }
 }
 @Override
 public void execute(EntityPlayer player, Side side) {
   if (side.isServer()) {
     if (player.openContainer instanceof ContainerEnchantTable) {
       try {
         ((ContainerEnchantTable) player.openContainer).repair(player, cost, amount);
       } catch (final Exception e) {
         EnchantingPlus.log.info("Repair failed because: " + e.getMessage());
         PacketDispatcher.sendPacketToPlayer(
             new DisenchantErrorPacket(e.getMessage()).makePacket(), (Player) player);
       }
       player.openContainer.detectAndSendChanges();
     }
   }
 }
 @Override
 public void interpret(DataInputStream stream, Object[] extradata, Side side) {
   if (side.equals(Side.CLIENT)) interpretClient(stream, extradata);
   else FlansMod.log("Sound packet recieved on server. Skipping interpretation.");
 }