use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class MaterialManager method onResourceManagerReload.
@Override
public void onResourceManagerReload(ResourceManager resourceManager) {
Collection<ResourceLocation> resources = resourceManager.listResources(DATA_PATH, s -> s.endsWith(".json"));
if (resources.isEmpty())
return;
Multimap<String, IMaterial> ingredientConflicts = HashMultimap.create();
Collection<ResourceLocation> skippedList = new ArrayList<>();
synchronized (MATERIALS) {
MATERIALS.clear();
ERROR_LIST.clear();
SilentGear.LOGGER.info(MARKER, "Reloading material files");
for (ResourceLocation id : resources) {
String path = id.getPath().substring(DATA_PATH.length() + 1, id.getPath().length() - ".json".length());
ResourceLocation name = new ResourceLocation(id.getNamespace(), path);
String packName = "ERROR";
try (Resource iresource = resourceManager.getResource(id)) {
packName = iresource.getSourceName();
JsonObject json = GsonHelper.fromJson(GSON, IOUtils.toString(iresource.getInputStream(), StandardCharsets.UTF_8), JsonObject.class);
if (json == null) {
// Something is very wrong or the JSON is somehow empty
SilentGear.LOGGER.error(MARKER, "Could not load material {} as it's null or empty", name);
} else if (!CraftingHelper.processConditions(json, "conditions")) {
// Conditions not met, so do not load the material
skippedList.add(name);
} else {
// Attempt to deserialize the material
IMaterial material = MaterialSerializers.deserialize(name, packName, json);
MATERIALS.put(material.getId(), material);
addIngredientChecks(ingredientConflicts, material, json);
}
} catch (IllegalArgumentException | JsonParseException ex) {
SilentGear.LOGGER.error(MARKER, "Parsing error loading material {}", name, ex);
ERROR_LIST.add(String.format("%s (%s)", name, packName));
} catch (IOException ex) {
SilentGear.LOGGER.error(MARKER, "Could not read material {}", name, ex);
ERROR_LIST.add(String.format("%s (%s)", name, packName));
}
}
}
checkForIngredientConflicts(ingredientConflicts);
logSkippedMaterials(skippedList);
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class CompoundPart method getRandomMaterials.
private List<MaterialInstance> getRandomMaterials(GearType gearType, int count, int tier) {
// Excludes children, will select a random child material (if appropriate) below
List<IMaterial> matsOfTier = MaterialManager.getValues(tier == 0).stream().map(MaterialInstance::of).filter(m -> tier < 0 || tier == m.getTier(this.partType)).filter(m -> m.allowedInPart(this.partType) && m.isCraftingAllowed(this.partType, gearType)).map(MaterialInstance::get).collect(Collectors.toList());
if (!matsOfTier.isEmpty()) {
List<MaterialInstance> ret = new ArrayList<>();
for (int i = 0; i < count; ++i) {
IMaterial material = matsOfTier.get(SilentGear.RANDOM.nextInt(matsOfTier.size()));
ret.add(getRandomChildMaterial(material));
}
return ret;
}
if (tier == -1) {
// Something went wrong...
return Collections.emptyList();
}
// No materials of tier? Select randoms of any tier.
return getRandomMaterials(gearType, count, -1);
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class AbstractMaterial method removeEnhancements.
public static IMaterialInstance removeEnhancements(IMaterialInstance material) {
ItemStack stack = material.getItem().copy();
for (IMaterialModifierType modifierType : MaterialModifiers.getTypes()) {
modifierType.removeModifier(stack);
}
EnchantmentHelper.setEnchantments(Collections.emptyMap(), stack);
IMaterial iMaterial = material.get();
if (iMaterial != null) {
return MaterialInstance.of(iMaterial, stack);
} else {
return material;
}
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class GearDisplayManager method getMaterials.
public static Collection<IMaterialDisplay> getMaterials() {
synchronized (MATERIALS) {
Collection<IMaterialDisplay> ret = new ArrayList<>();
for (IMaterial material : MaterialManager.getValues()) {
MaterialInstance mat = MaterialInstance.of(material);
ret.add(mat.getDisplayProperties());
}
ret.addAll(MATERIALS.values());
return ret;
}
}
use of net.silentchaos512.gear.api.material.IMaterial in project Silent-Gear by SilentChaos512.
the class CompoundPartModel method buildFakeModel.
private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
// This method will display an example item for items with no data (ie, for advancements)
MaterialInstance mat = MaterialInstance.of(material);
IMaterialDisplay model = mat.getDisplayProperties();
MaterialLayer exampleMain = model.getLayerList(this.gearType, this.partType, mat).getFirstLayer();
if (exampleMain != null) {
builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(this.texturePath, 0))), rotation, exampleMain.getColor()));
}
builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, new StaticLayer(PART_MARKER_TEXTURE).getTexture(this.gearType, 0))), rotation, Color.VALUE_WHITE));
}
Aggregations