/** * Builds the NBT for a new tinker item with the given data. * * @param materials Materials to build with. Have to be in the correct order. No nulls! * @return The built nbt */ public NBTTagCompound buildItemNBT(List<Material> materials) { NBTTagCompound basetag = new NBTTagCompound(); NBTTagCompound toolTag = buildTag(materials); NBTTagCompound dataTag = buildData(materials); basetag.setTag(Tags.BASE_DATA, dataTag); basetag.setTag(Tags.TOOL_DATA, toolTag); // copy of the original tool data basetag.setTag(Tags.TOOL_DATA_ORIG, toolTag.copy()); // save categories on the tool TagUtil.setCategories(basetag, getCategories()); // add traits addMaterialTraits(basetag, materials); // fire toolbuilding event TinkerEvent.OnItemBuilding.fireEvent(basetag, ImmutableList.copyOf(materials), this); return basetag; }
@Nonnull public ItemStack buildItemForRenderingInGui() { List<Material> materials = IntStream.range(0, getRequiredComponents().size()) .mapToObj(this::getMaterialForPartForGuiRendering) .collect(Collectors.toList()); return buildItemForRendering(materials); }
public ToolBuildGuiInfo(@Nonnull TinkersItem tool) { this.tool = tool.buildItemForRenderingInGui(); }
for(int index : getRepairParts()) { Material material = materials.get(index); if(repairCustom(material, items) > 0) { foundMatch = true; int amount = calculateRepairAmount(materials, repairItems); ToolHelper.repairTool(item, calculateRepair(item, amount));
List<PartMaterialType> pms = tinkersItem.getRequiredComponents(); NBTTagCompound toolTag = tinkersItem.buildTag(materials); TagUtil.setToolTag(rootNBT, toolTag); tinkersItem.addMaterialTraits(rootNBT, materials);
/** * Builds an Itemstack of this tool with the given materials, if applicable. * * @param stacks Items to build with. Have to be in the correct order and have exact length. No nulls! * @return The built item or null if invalid input. */ @Nonnull public ItemStack buildItemFromStacks(NonNullList<ItemStack> stacks) { long itemCount = stacks.stream().filter(stack -> !stack.isEmpty()).count(); List<Material> materials = new ArrayList<>(stacks.size()); if(itemCount != requiredComponents.length) { return ItemStack.EMPTY; } // not a valid part arrangement for this tool for(int i = 0; i < itemCount; i++) { if(!validComponent(i, stacks.get(i))) { return ItemStack.EMPTY; } materials.add(TinkerUtil.getMaterialFromStack(stacks.get(i))); } return buildItem(materials); }
List<PartMaterialType> pms = tool.getRequiredComponents(); for(int j = 0; j < pms.size(); j++) { PartMaterialType pmt = pms.get(j); ItemStack copyToCheck = tinkersItem.buildItem(TinkerUtil.getMaterialsFromTagList(materialList));
/** * Builds an Itemstack of this tool with the given materials. * * @param materials Materials to build with. Have to be in the correct order. No nulls! * @return The built item or null if invalid input. */ @Nonnull public ItemStack buildItem(List<Material> materials) { ItemStack tool = new ItemStack(this); tool.setTagCompound(buildItemNBT(materials)); return tool; }
/** * Builds an unusable tool that only has the rendering info */ @Nonnull public ItemStack buildItemForRendering(List<Material> materials) { ItemStack tool = new ItemStack(this); NBTTagCompound base = new NBTTagCompound(); base.setTag(Tags.BASE_DATA, buildData(materials)); tool.setTagCompound(base); return tool; }
@Nonnull @Override public Multimap<String, AttributeModifier> getAttributeModifiers(@Nonnull EntityEquipmentSlot slot, ItemStack stack) { Multimap<String, AttributeModifier> multimap = super.getAttributeModifiers(slot, stack); if(slot == EntityEquipmentSlot.MAINHAND && !ToolHelper.isBroken(stack)) { multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", ToolHelper.getActualAttack(stack), 0)); multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", ToolHelper.getActualAttackSpeed(stack) - 4d, 0)); } TinkerUtil.getTraitsOrdered(stack).forEach(trait -> trait.getAttributeModifiers(slot, stack, multimap)); return multimap; }