Search in sources :

Example 1 with Pair

use of net.minecraft.util.Pair in project Skyblocker by LifeIsAParadox.

the class ItemStackBuilder method parseJsonObj.

public static ItemStack parseJsonObj(JsonObject obj) {
    String internalName = obj.get("internalname").getAsString();
    List<Pair<String, String>> injectors = new ArrayList<>();
    injectors.addAll(petData(internalName));
    NbtCompound root = new NbtCompound();
    root.put("Count", NbtByte.of((byte) 1));
    String id = obj.get("itemid").getAsString();
    int damage = obj.get("damage").getAsInt();
    root.put("id", NbtString.of(ItemFixerUpper.convertItemId(id, damage)));
    NbtCompound tag = new NbtCompound();
    root.put("tag", tag);
    NbtCompound extra = new NbtCompound();
    tag.put("ExtraAttributes", extra);
    extra.put("id", NbtString.of(internalName));
    // add enchantment glint
    if (internalName.contains("ENCHANTED")) {
        NbtList enchantments = new NbtList();
        enchantments.add(new NbtCompound());
        tag.put("Enchantments", enchantments);
    }
    NbtCompound display = new NbtCompound();
    tag.put("display", display);
    String name = injectData(obj.get("displayname").getAsString(), injectors);
    display.put("Name", NbtString.of(Text.Serializer.toJson(Text.of(name))));
    NbtList lore = new NbtList();
    display.put("Lore", lore);
    obj.get("lore").getAsJsonArray().forEach(el -> lore.add(NbtString.of(Text.Serializer.toJson(Text.of(injectData(el.getAsString(), injectors))))));
    String nbttag = obj.get("nbttag").getAsString();
    // add skull texture
    Matcher skullMatcher = Pattern.compile("SkullOwner:\\{Id:\"(.{36})\",Properties:\\{textures:\\[0:\\{Value:\"(.+)\"}]}}").matcher(nbttag);
    if (skullMatcher.find()) {
        NbtCompound skullOwner = new NbtCompound();
        tag.put("SkullOwner", skullOwner);
        UUID uuid = UUID.fromString(skullMatcher.group(1));
        skullOwner.put("Id", NbtHelper.fromUuid(uuid));
        skullOwner.put("Name", NbtString.of(internalName));
        NbtCompound properties = new NbtCompound();
        skullOwner.put("Properties", properties);
        NbtList textures = new NbtList();
        properties.put("textures", textures);
        NbtCompound texture = new NbtCompound();
        textures.add(texture);
        texture.put("Value", NbtString.of(skullMatcher.group(2)));
    }
    // add leather armor dye color
    Matcher colorMatcher = Pattern.compile("color:(\\d+)").matcher(nbttag);
    if (colorMatcher.find()) {
        NbtInt color = NbtInt.of(Integer.parseInt(colorMatcher.group(1)));
        display.put("color", color);
    }
    return ItemStack.fromNbt(root);
}
Also used : Matcher(java.util.regex.Matcher) Pair(net.minecraft.util.Pair)

Example 2 with Pair

use of net.minecraft.util.Pair in project Skyblocker by LifeIsAParadox.

the class ItemStackBuilder method petData.

// TODO: fix stats for GOLDEN_DRAGON (lv1 -> lv200)
private static List<Pair<String, String>> petData(String internalName) {
    List<Pair<String, String>> list = new ArrayList<>();
    String petName = internalName.split(";")[0];
    if (!internalName.contains(";") || !petNums.has(petName))
        return list;
    list.add(new Pair<>("\\{LVL\\}", "1 ➡ 100"));
    final String[] rarities = { "COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY", "MYTHIC" };
    String rarity = rarities[Integer.parseInt(internalName.split(";")[1])];
    JsonObject data = petNums.get(petName).getAsJsonObject().get(rarity).getAsJsonObject();
    JsonObject statNumsMin = data.get("1").getAsJsonObject().get("statNums").getAsJsonObject();
    JsonObject statNumsMax = data.get("100").getAsJsonObject().get("statNums").getAsJsonObject();
    Set<Map.Entry<String, JsonElement>> entrySet = statNumsMin.entrySet();
    for (Map.Entry<String, JsonElement> entry : entrySet) {
        String key = entry.getKey();
        String left = "\\{" + key + "\\}";
        String right = statNumsMin.get(key).getAsString() + " ➡ " + statNumsMax.get(key).getAsString();
        list.add(new Pair<>(left, right));
    }
    JsonArray otherNumsMin = data.get("1").getAsJsonObject().get("otherNums").getAsJsonArray();
    JsonArray otherNumsMax = data.get("100").getAsJsonObject().get("otherNums").getAsJsonArray();
    for (int i = 0; i < otherNumsMin.size(); ++i) {
        String left = "\\{" + i + "\\}";
        String right = otherNumsMin.get(i).getAsString() + " ➡ " + otherNumsMax.get(i).getAsString();
        list.add(new Pair<>(left, right));
    }
    return list;
}
Also used : JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) Pair(net.minecraft.util.Pair)

Example 3 with Pair

use of net.minecraft.util.Pair in project MCDoom by AzureDoom.

the class LivingEntityMixin method tryUseTotem.

@Inject(method = "tryUseTotem", at = @At(value = "HEAD"), cancellable = true)
private void tryUseTotem(DamageSource source, CallbackInfoReturnable<Boolean> ci) {
    LivingEntity livingEntity = (LivingEntity) (Object) this;
    if (source.isOutOfWorld()) {
        ci.setReturnValue(false);
    } else {
        ItemStack stack = TrinketsApi.getTrinketComponent(livingEntity).map(component -> {
            List<Pair<SlotReference, ItemStack>> res = component.getEquipped(DoomItems.SOULCUBE);
            return res.size() > 0 ? res.get(0).getRight() : ItemStack.EMPTY;
        }).orElse(ItemStack.EMPTY);
        if (!stack.isEmpty()) {
            stack.damage(1, livingEntity, p -> p.sendToolBreakStatus(livingEntity.getActiveHand()));
            livingEntity.setHealth(20.0F);
            livingEntity.clearStatusEffects();
            livingEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.RESISTANCE, 100, 4));
            livingEntity.addStatusEffect(new StatusEffectInstance(StatusEffects.FIRE_RESISTANCE, 100, 4));
            livingEntity.world.sendEntityStatus(livingEntity, (byte) 95);
            ci.setReturnValue(true);
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) TrinketsApi(dev.emi.trinkets.api.TrinketsApi) Pair(net.minecraft.util.Pair) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) Inject(org.spongepowered.asm.mixin.injection.Inject) LivingEntity(net.minecraft.entity.LivingEntity) StatusEffects(net.minecraft.entity.effect.StatusEffects) DamageSource(net.minecraft.entity.damage.DamageSource) DoomItems(mod.azure.doom.util.registry.DoomItems) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) SlotReference(dev.emi.trinkets.api.SlotReference) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Mixin(org.spongepowered.asm.mixin.Mixin) At(org.spongepowered.asm.mixin.injection.At) SlotReference(dev.emi.trinkets.api.SlotReference) StatusEffectInstance(net.minecraft.entity.effect.StatusEffectInstance) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with Pair

use of net.minecraft.util.Pair in project Primeval by devs-immortal.

the class PrimevalFluids method combineFluids.

public static Pair<FluidVariant, Integer> combineFluids(HashMap<FluidVariant, Integer> fluids) {
    if (fluids.keySet().size() == 1) {
        for (FluidVariant fluid : fluids.keySet()) {
            return new Pair<>(fluid, fluids.get(fluid));
        }
    }
    int overallFluid = 0;
    for (FluidVariant fluid : fluids.keySet()) {
        System.out.print(fluid.toNbt().getString("fluid") + " | " + fluids.get(fluid));
        overallFluid += fluids.get(fluid);
    }
    for (AlloyRatio a : alloys) {
        if (a.satisfies(fluids, overallFluid)) {
            return new Pair<>(a.getResult(), overallFluid);
        }
    }
    return new Pair<>(FluidVariant.of(MOLTEN_BOTCHED_ALLOY), overallFluid);
}
Also used : FluidVariant(net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant) Pair(net.minecraft.util.Pair)

Example 5 with Pair

use of net.minecraft.util.Pair in project Primeval by devs-immortal.

the class VesselItem method onStackClicked.

// 
// COPIED BUNDLE METHODS
// 
public boolean onStackClicked(ItemStack stack, Slot slot, ClickType clickType, PlayerEntity player) {
    if (clickType != ClickType.RIGHT) {
        return false;
    } else if (slot.getStack().getItem() instanceof ClayMoldItem) {
        ItemStack moldItemStack = slot.getStack();
        NbtCompound nbt = stack.getOrCreateNbt();
        NbtCompound fluidNbt = nbt.getCompound("Fluid");
        int fluidAmount = fluidNbt.getInt("Amount");
        Pair<FluidVariant, Integer> fluidPair = new Pair<>(FluidVariant.fromNbt(fluidNbt), fluidAmount);
        int amountInserted = ClayMoldItem.insertFluid(fluidPair, moldItemStack);
        fluidNbt.putInt("Amount", fluidAmount - amountInserted);
        nbt.put("Fluid", fluidNbt);
        stack.setNbt(nbt);
        return true;
    } else if (canAddItem(stack)) {
        ItemStack itemStack = slot.getStack();
        if (itemStack.isEmpty()) {
            this.playRemoveOneSound(player);
            removeFirstStack(stack).ifPresent((removedStack) -> addToBundle(stack, slot.insertStack(removedStack)));
        } else if (itemStack.getItem().canBeNested()) {
            int i = (64 - getBundleOccupancy(stack)) / getItemOccupancy(itemStack);
            int j = addToBundle(stack, slot.takeStackRange(itemStack.getCount(), i, player));
            if (j > 0) {
                this.playInsertSound(player);
            }
        }
        return true;
    }
    return false;
}
Also used : NbtCompound(net.minecraft.nbt.NbtCompound) ItemStack(net.minecraft.item.ItemStack) Pair(net.minecraft.util.Pair)

Aggregations

Pair (net.minecraft.util.Pair)17 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Collection (java.util.Collection)4 Comparator (java.util.Comparator)4 Consumer (java.util.function.Consumer)4 ItemStack (net.minecraft.item.ItemStack)4 Registry (net.minecraft.util.registry.Registry)4 BlockPos (net.minecraft.util.math.BlockPos)3 Direction (net.minecraft.util.math.Direction)3 Helper (com.qouteall.immersive_portals.Helper)2 IntegerAABBInclusive (com.qouteall.immersive_portals.my_util.IntegerAABBInclusive)2 Arrays (java.util.Arrays)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Predicate (java.util.function.Predicate)2 IntStream (java.util.stream.IntStream)2 Stream (java.util.stream.Stream)2 GuiTheme (mathax.client.gui.GuiTheme)2 WindowScreen (mathax.client.gui.WindowScreen)2