Ejemplo n.º 1
1
    private SegmentItem deserializeItem(JsonObject json, JsonDeserializationContext context) {
      if (!json.has("actions")) {
        throw new ProtectionParseException("Missing actions identifier");
      }

      SegmentItem segment = new SegmentItem();

      segment.types.addAll(
          deserializeAsArray(
              json.get("actions"),
              context,
              new TypeToken<ItemType>() {},
              new TypeToken<List<ItemType>>() {}.getType()));
      json.remove("actions");

      if (json.has("isAdjacent")) {
        segment.isAdjacent = json.get("isAdjacent").getAsBoolean();
        json.remove("isAdjacent");
      }

      if (json.has("clientUpdate")) {
        JsonObject jsonClientUpdate = json.get("clientUpdate").getAsJsonObject();
        segment.clientUpdate =
            new ClientBlockUpdate(
                (Volume) context.deserialize(jsonClientUpdate.get("coords"), Volume.class));
        if (jsonClientUpdate.has("directional")) {
          segment.directionalClientUpdate = jsonClientUpdate.get("directional").getAsBoolean();
        }
        json.remove("clientUpdate");
      }

      return segment;
    }
Ejemplo n.º 2
0
  public static void checkBreakWithItem(ItemStack stack, Resident res, BlockPos bp, Event ev) {
    if (!ev.isCancelable()) {
      return;
    }

    for (SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
      if (!segment.shouldBreakBlock(stack, res, bp)) {
        ev.setCanceled(true);
      }
    }
  }
Ejemplo n.º 3
0
  public static void checkUsage(
      ItemStack stack,
      Resident res,
      PlayerInteractEvent.Action action,
      BlockPos bp,
      int face,
      Event ev) {
    if (!ev.isCancelable()) {
      return;
    }

    for (SegmentItem segment : segmentsItem.get(stack.getItem().getClass())) {
      if (!segment.shouldInteract(stack, res, action, bp, face)) {
        ev.setCanceled(true);
      }
    }
  }