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);
}
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;
}
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);
}
}
}
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);
}
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;
}
Aggregations