use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.
the class JEIPlugin method registerItemSubtypes.
@Override
public void registerItemSubtypes(ISubtypeRegistration registry) {
// retexturable blocks
IIngredientSubtypeInterpreter<ItemStack> tables = (stack, context) -> {
if (context == UidContext.Ingredient) {
return RetexturedBlockItem.getTextureName(stack);
}
return IIngredientSubtypeInterpreter.NONE;
};
registry.registerSubtypeInterpreter(TinkerTables.craftingStation.asItem(), tables);
registry.registerSubtypeInterpreter(TinkerTables.partBuilder.asItem(), tables);
registry.registerSubtypeInterpreter(TinkerTables.tinkerStation.asItem(), tables);
registry.registerSubtypeInterpreter(TinkerTables.tinkersAnvil.asItem(), tables);
registry.registerSubtypeInterpreter(TinkerTables.scorchedAnvil.asItem(), tables);
IIngredientSubtypeInterpreter<ItemStack> toolPartInterpreter = (stack, context) -> {
MaterialVariantId materialId = IMaterialItem.getMaterialFromStack(stack);
if (materialId.equals(IMaterial.UNKNOWN_ID)) {
return IIngredientSubtypeInterpreter.NONE;
}
return materialId.getId().toString();
};
// parts
for (Item item : TinkerTags.Items.TOOL_PARTS.getValues()) {
registry.registerSubtypeInterpreter(item, toolPartInterpreter);
}
// tools
Item slimeskull = TinkerTools.slimesuit.get(ArmorSlotType.HELMET);
registry.registerSubtypeInterpreter(slimeskull, ToolSubtypeInterpreter.ALWAYS);
for (Item item : TinkerTags.Items.MULTIPART_TOOL.getValues()) {
if (item != slimeskull) {
registry.registerSubtypeInterpreter(item, ToolSubtypeInterpreter.INGREDIENT);
}
}
registry.registerSubtypeInterpreter(TinkerSmeltery.copperCan.get(), (stack, context) -> CopperCanItem.getSubtype(stack));
registry.registerSubtypeInterpreter(TinkerModifiers.creativeSlotItem.get(), (stack, context) -> {
SlotType slotType = CreativeSlotItem.getSlot(stack);
return slotType != null ? slotType.getName() : "";
});
}
use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.
the class MaterialRenderInfoLoader method onReloadSafe.
@Override
public void onReloadSafe(ResourceManager manager) {
// first, we need to fetch all relevant JSON files
int trim = FOLDER.length() + 1;
Map<MaterialVariantId, MaterialRenderInfo> map = new HashMap<>();
for (ResourceLocation location : manager.listResources(FOLDER, (loc) -> loc.endsWith(".json"))) {
// clean up ID by trimming off the extension and folder
String path = location.getPath();
String localPath = path.substring(trim, path.length() - 5);
// locate variant as a subfolder, and create final ID
String variant = "";
int slashIndex = localPath.lastIndexOf('/');
if (slashIndex >= 0) {
variant = localPath.substring(slashIndex + 1);
localPath = localPath.substring(0, slashIndex);
}
MaterialVariantId id = MaterialVariantId.create(location.getNamespace(), localPath, variant);
// read in the JSON data
try (Resource resource = manager.getResource(location);
InputStream inputstream = resource.getInputStream();
Reader reader = new BufferedReader(new InputStreamReader(inputstream, StandardCharsets.UTF_8))) {
MaterialRenderInfoJson json = GSON.fromJson(reader, MaterialRenderInfoJson.class);
if (json == null) {
log.error("Couldn't load data file {} from {} as it's null or empty", id, location);
} else {
// parse it into material render info
MaterialRenderInfo old = map.put(id, loadRenderInfo(id, json));
if (old != null) {
throw new IllegalStateException("Duplicate data file ignored with ID " + id);
}
}
} catch (IllegalArgumentException | IOException | JsonParseException jsonparseexception) {
log.error("Couldn't parse data file {} from {}", id, location, jsonparseexception);
}
}
// store the list immediately, otherwise it is not in place in time for models to load
this.renderInfos = map;
log.debug("Loaded material render infos: {}", Util.toIndentedStringList(map.keySet()));
log.info("{} material render infos loaded", map.size());
}
use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.
the class MaterialIdNBT method readFromNBT.
/**
* Parses the material list from NBT
* @param nbt NBT instance
* @return MaterialNBT instance
*/
public static MaterialIdNBT readFromNBT(@Nullable Tag nbt) {
if (nbt == null || nbt.getId() != Tag.TAG_LIST) {
return EMPTY;
}
ListTag listNBT = (ListTag) nbt;
if (listNBT.getElementType() != Tag.TAG_STRING) {
return EMPTY;
}
List<MaterialVariantId> materials = listNBT.stream().map(Tag::getAsString).map(MaterialVariantId::tryParse).filter(Objects::nonNull).collect(Collectors.toList());
return new MaterialIdNBT(materials);
}
use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.
the class MaterialRecipeSerializer method fromNetworkSafe.
@Nullable
@Override
protected MaterialRecipe fromNetworkSafe(ResourceLocation recipeId, FriendlyByteBuf buffer) {
String group = buffer.readUtf(Short.MAX_VALUE);
Ingredient ingredient = Ingredient.fromNetwork(buffer);
int value = buffer.readInt();
int needed = buffer.readInt();
MaterialVariantId materialId = MaterialVariantId.parse(buffer.readUtf(Short.MAX_VALUE));
ItemOutput leftover = ItemOutput.read(buffer);
return new MaterialRecipe(recipeId, group, ingredient, value, needed, materialId, leftover);
}
use of slimeknights.tconstruct.library.materials.definition.MaterialVariantId in project TinkersConstruct by SlimeKnights.
the class MaterialRecipeSerializer method fromJson.
@Override
public MaterialRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
String group = GsonHelper.getAsString(json, "group", "");
Ingredient ingredient = Ingredient.fromJson(JsonHelper.getElement(json, "ingredient"));
int value = GsonHelper.getAsInt(json, "value", 1);
int needed = GsonHelper.getAsInt(json, "needed", 1);
MaterialVariantId materialId = MaterialVariantId.fromJson(json, "material");
ItemOutput leftover = EMPTY;
if (value > 1 && json.has("leftover")) {
leftover = ItemOutput.fromJson(json.get("leftover"));
}
return new MaterialRecipe(recipeId, group, ingredient, value, needed, materialId, leftover);
}
Aggregations