use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class MaterialStatsManagerTest method testLoadFile_multipleStatsInOneFile.
@Test
void testLoadFile_multipleStatsInOneFile() {
MaterialId material = new MaterialId(TConstruct.getResource("multiple"));
MaterialStatsId statId1 = new MaterialStatsId("test", "stat1");
materialStatsManager.registerMaterialStat(new ComplexTestStats(statId1, 1, 1f, "one"), ComplexTestStats.class, ComplexTestStats::new);
MaterialStatsId statId2 = new MaterialStatsId("test", "stat2");
materialStatsManager.registerMaterialStat(new ComplexTestStats(statId2, 2, 2f, "two"), ComplexTestStats.class, ComplexTestStats::new);
fileLoader.loadAndParseFiles(null, material);
assertThat(materialStatsManager.getStats(material, statId1)).isPresent();
assertThat(materialStatsManager.getStats(material, statId2)).isPresent();
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class MaterialStatsManagerTest method loadFileWithOnlyUnregisteredStats_doNothing.
@Test
void loadFileWithOnlyUnregisteredStats_doNothing() {
MaterialId material = new MaterialId(TConstruct.getResource("invalid"));
fileLoader.loadAndParseFiles(null, material);
Optional<ComplexTestStats> optionalStats = materialStatsManager.getStats(material, new MaterialStatsId("test", "fails"));
assertThat(optionalStats).isEmpty();
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class SlimeskullArmorModel method setup.
/**
* Called before the model is rendered to set the base model and the tool stack data
*/
private void setup(HumanoidModel<?> base, ItemStack stack) {
this.base = base;
this.hasGlint = stack.hasFoil();
MaterialId materialId = MaterialIdNBT.from(stack).getMaterial(0).getId();
if (!materialId.equals(IMaterial.UNKNOWN_ID)) {
SkullModelBase model = getHeadModel(materialId);
ResourceLocation texture = HEAD_TEXTURES.get(materialId);
if (model != null && texture != null) {
headModel = model;
headTexture = texture;
return;
}
}
headTexture = null;
headModel = null;
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class SlimeskullArmorModel method getHeadModel.
/**
* Gets the head model for the given material
*/
@Nullable
private static SkullModelBase getHeadModel(MaterialId materialId) {
if (HEAD_MODELS == null) {
// vanilla rebakes these a lot, so figure we should at least do it every resource reload
EntityModelSet modelSet = Minecraft.getInstance().getEntityModels();
ImmutableMap.Builder<MaterialId, SkullModelBase> models = ImmutableMap.builder();
for (Entry<MaterialId, Function<EntityModelSet, ? extends SkullModelBase>> entry : HEAD_MODEL_FACTORIES.entrySet()) {
models.put(entry.getKey(), entry.getValue().apply(modelSet));
}
HEAD_MODELS = models.build();
}
return HEAD_MODELS.get(materialId);
}
use of slimeknights.tconstruct.library.materials.definition.MaterialId in project TinkersConstruct by SlimeKnights.
the class TinkerStationRepairRecipe method getValidatedResult.
@Override
public ValidatedResult getValidatedResult(ITinkerStationContainer inv) {
ToolStack tool = ToolStack.from(inv.getTinkerableStack());
if (tool.getDefinition() == ToolDefinition.EMPTY) {
return ValidatedResult.PASS;
}
// ensure input needs repair
if (!tool.isBroken() && tool.getDamage() == 0) {
return FULLY_REPAIRED;
}
// first, determine how much we can repair
MaterialId primaryMaterial = getPrimaryMaterial(tool);
int repairNeeded = tool.getDamage();
int repairRemaining = repairNeeded;
// iterate stacks, adding up amount we can repair, assumes the material is correct per #matches()
for (int i = 0; i < inv.getInputCount() && repairRemaining > 0; i++) {
repairRemaining -= repairFromSlot(tool, primaryMaterial, inv, repairRemaining, i, NO_ACTION);
}
// did we actually repair something?
if (repairRemaining < repairNeeded) {
tool = tool.copy();
ToolDamageUtil.repair(tool, repairNeeded - repairRemaining);
// repair remaining can be negative
return ValidatedResult.success(tool.createStack());
}
// for some odd reason, did not repair anything
return ValidatedResult.PASS;
}
Aggregations