use of slimeknights.tconstruct.library.tools.item.IModifiable in project TinkersConstruct by SlimeKnights.
the class ToolBuildingRecipeSerializer method fromNetworkSafe.
@Nullable
@Override
protected ToolBuildingRecipe fromNetworkSafe(ResourceLocation recipeId, FriendlyByteBuf buffer) {
String group = buffer.readUtf(Short.MAX_VALUE);
IModifiable result = RecipeHelper.readItem(buffer, IModifiable.class);
return new ToolBuildingRecipe(recipeId, group, result);
}
use of slimeknights.tconstruct.library.tools.item.IModifiable in project TinkersConstruct by SlimeKnights.
the class ToolHarvestLogicTest method calcSpeed_effective_withMiningModifier.
@Test
void calcSpeed_effective_withMiningModifier() {
float modifier = 2f;
ToolDefinition definition = ToolDefinition.builder(new ResourceLocation("test", "mining_tool")).meleeHarvest().skipRegister().build();
definition.setData(ToolDefinitionDataBuilder.builder().harvestLogic(new BlockHarvestLogic(Blocks.COBBLESTONE)).part(MaterialItemFixture.MATERIAL_ITEM_HEAD).part(MaterialItemFixture.MATERIAL_ITEM_HANDLE).part(MaterialItemFixture.MATERIAL_ITEM_EXTRA).multiplier(ToolStats.MINING_SPEED, modifier).build());
IModifiable toolWithMiningModifier = new ModifiableItem(new Item.Properties(), definition);
ItemStack tool = buildTestTool(toolWithMiningModifier);
// boosted by correct block
float speed = ToolHarvestLogic.getDestroySpeed(tool, Blocks.COBBLESTONE.defaultBlockState());
assertThat(speed).isEqualTo(MaterialStatsFixture.MATERIAL_STATS_HEAD.getMiningSpeed() * modifier);
// default speed
speed = ToolHarvestLogic.getDestroySpeed(tool, Blocks.STONE.defaultBlockState());
assertThat(speed).isEqualTo(1.0f);
}
use of slimeknights.tconstruct.library.tools.item.IModifiable in project TinkersConstruct by SlimeKnights.
the class ToolStack method from.
/* Creating */
/**
* Creates a tool stack from an item stack
* @param stack Base stack
* @param copyNbt If true, NBT is copied from the stack
* @return Tool stack
*/
private static ToolStack from(ItemStack stack, boolean copyNbt) {
Item item = stack.getItem();
ToolDefinition definition = item instanceof IModifiable ? ((IModifiable) item).getToolDefinition() : ToolDefinition.EMPTY;
CompoundTag nbt = stack.getTag();
if (nbt == null) {
nbt = new CompoundTag();
if (!copyNbt) {
stack.setTag(nbt);
}
} else if (copyNbt) {
nbt = nbt.copy();
}
return from(item, definition, nbt);
}
use of slimeknights.tconstruct.library.tools.item.IModifiable in project TinkersConstruct by SlimeKnights.
the class ModifierUsageCommand method runForType.
private static int runForType(CommandContext<CommandSourceStack> context, ModifierUsages filter, @Nullable OptionalSlotType slotFilter) {
// recipe modifiers are used in a displayable modifier recipe
HashMultimap<SlotType, Modifier> recipeModifiers = context.getSource().getLevel().getRecipeManager().byType(RecipeTypes.TINKER_STATION).values().stream().filter(r -> r instanceof IModifierRecipe).map(r -> (IModifierRecipe) r).collect(Collector.of(HashMultimap::create, (map, r) -> map.put(r.getSlotType(), r.getModifier()), (m1, m2) -> {
m1.putAll(m2);
return m1;
}));
// material traits are used in material traits (kinda obvious)
IMaterialRegistry matReg = MaterialRegistry.getInstance();
Set<Modifier> materialTraits = matReg.getAllMaterials().stream().flatMap(mat -> {
MaterialId matId = mat.getIdentifier();
return Stream.concat(matReg.getDefaultTraits(matId).stream(), matReg.getAllStats(matId).stream().filter(stat -> matReg.hasUniqueTraits(matId, stat.getIdentifier())).flatMap(stat -> matReg.getTraits(matId, stat.getIdentifier()).stream()));
}).map(ModifierEntry::getModifier).collect(Collectors.toSet());
// finally, tool traits we limit to anything in the modifiable tag
Set<Modifier> toolTraits = TinkerTags.Items.MODIFIABLE.getValues().stream().filter(item -> item instanceof IModifiable).flatMap(item -> ((IModifiable) item).getToolDefinition().getData().getTraits().stream()).map(ModifierEntry::getModifier).collect(Collectors.toSet());
// next, get our list of modifiers
Stream<Modifier> modifierStream;
switch(filter) {
case RECIPE:
// filter to just one type of modifier if requested
if (slotFilter != null) {
modifierStream = recipeModifiers.get(slotFilter.slotType()).stream();
} else {
modifierStream = recipeModifiers.values().stream();
}
break;
case MATERIAL_TRAIT:
modifierStream = materialTraits.stream();
break;
case TOOL_TRAIT:
modifierStream = toolTraits.stream();
break;
default:
modifierStream = TinkerRegistries.MODIFIERS.getValues().stream();
break;
}
// if requested, filter out all
if (filter == ModifierUsages.UNUSED) {
modifierStream = modifierStream.filter(modifier -> !recipeModifiers.containsValue(modifier) && !materialTraits.contains(modifier) && !toolTraits.contains(modifier));
}
// start building the table for output
TablePrinter<ModifierUsageRow> table = new TablePrinter<>();
table.header("ID", r -> r.modifierId().toString());
if (filter != ModifierUsages.UNUSED) {
if (filter != ModifierUsages.RECIPE || slotFilter == null) {
table.header("Recipe", ModifierUsageRow::recipe);
}
if (filter != ModifierUsages.MATERIAL_TRAIT) {
table.header("material Trait", r -> r.materialTrait() ? "Material trait" : "");
}
if (filter != ModifierUsages.TOOL_TRAIT) {
table.header("tool Trait", r -> r.toolTrait() ? "Tool trait" : "");
}
}
StringBuilder logOutput = new StringBuilder();
logOutput.append(filter.logPrefix);
if (slotFilter != null) {
if (slotFilter.slotType() == null) {
logOutput.append(" (slotless)");
} else {
logOutput.append(" (").append(slotFilter.slotType().getName()).append(")");
}
}
logOutput.append(System.lineSeparator());
// for all the modifiers (sorted), add table rows
Collection<Modifier> finalList = modifierStream.sorted(Comparator.comparing(Modifier::getId)).toList();
finalList.forEach(modifier -> {
// determine which recipes use this by slot type
List<String> recipeUsages = SlotType.getAllSlotTypes().stream().filter(type -> recipeModifiers.containsEntry(type, modifier)).map(SlotType::getName).collect(Collectors.toList());
String recipes;
if (recipeUsages.isEmpty()) {
recipes = recipeModifiers.containsEntry(null, modifier) ? "slotless" : "";
} else {
recipes = String.join(", ", recipeUsages);
}
table.add(new ModifierUsageRow(modifier.getId(), recipes, toolTraits.contains(modifier), materialTraits.contains(modifier)));
});
// finally, output the table
table.build(logOutput);
TConstruct.LOG.info(logOutput.toString());
context.getSource().sendSuccess(SUCCESS, true);
return finalList.size();
}
use of slimeknights.tconstruct.library.tools.item.IModifiable in project TinkersConstruct by SlimeKnights.
the class TooltipUtil method getComponents.
/**
* Gets the tooltip of the components list of a tool
* @param item Modifiable item instance
* @param stack Item stack being displayed
* @param tooltips List of tooltips
*/
public static void getComponents(IModifiable item, ItemStack stack, List<Component> tooltips) {
// no components, nothing to do
List<PartRequirement> components = item.getToolDefinition().getData().getParts();
if (components.isEmpty()) {
return;
}
// no materials is bad
MaterialNBT materials = ToolStack.from(stack).getMaterials();
if (materials.size() == 0) {
tooltips.add(NO_DATA);
return;
}
// wrong number is bad
if (materials.size() < components.size()) {
return;
}
// finally, display them all
int max = components.size() - 1;
for (int i = 0; i <= max; i++) {
PartRequirement requirement = components.get(i);
MaterialVariantId material = materials.get(i).getVariant();
tooltips.add(requirement.nameForMaterial(material).copy().withStyle(ChatFormatting.UNDERLINE).withStyle(style -> style.withColor(MaterialTooltipCache.getColor(material))));
MaterialRegistry.getInstance().getMaterialStats(material.getId(), requirement.getStatType()).ifPresent(stat -> tooltips.addAll(stat.getLocalizedInfo()));
if (i != max) {
tooltips.add(TextComponent.EMPTY);
}
}
}
Aggregations