Search in sources :

Example 1 with IMaterial

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);
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) ResourceLocation(net.minecraft.resources.ResourceLocation) Resource(net.minecraft.server.packs.resources.Resource) IOException(java.io.IOException)

Example 2 with IMaterial

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);
}
Also used : JsonParseException(com.google.gson.JsonParseException) ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) JsonObject(com.google.gson.JsonObject) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) GearHelper(net.silentchaos512.gear.util.GearHelper) MaterialManager(net.silentchaos512.gear.gear.material.MaterialManager) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) PartGearKey(net.silentchaos512.gear.api.util.PartGearKey) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) IPartData(net.silentchaos512.gear.api.part.IPartData) GsonHelper(net.minecraft.util.GsonHelper) ColorUtils(net.silentchaos512.gear.client.util.ColorUtils) Nullable(javax.annotation.Nullable) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) Component(net.minecraft.network.chat.Component) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) MathUtils(net.silentchaos512.utils.MathUtils) Collection(java.util.Collection) SynergyUtils(net.silentchaos512.gear.util.SynergyUtils) Collectors(java.util.stream.Collectors) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) IPartSerializer(net.silentchaos512.gear.api.part.IPartSerializer) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) MaterialList(net.silentchaos512.gear.api.material.MaterialList) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) GetStatModifierEvent(net.silentchaos512.gear.api.event.GetStatModifierEvent) ItemStack(net.minecraft.world.item.ItemStack) TraitHelper(net.silentchaos512.gear.util.TraitHelper) CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) Collections(java.util.Collections) IMaterial(net.silentchaos512.gear.api.material.IMaterial) ArrayList(java.util.ArrayList) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 3 with IMaterial

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;
    }
}
Also used : IMaterialModifierType(net.silentchaos512.gear.api.material.modifier.IMaterialModifierType) ItemStack(net.minecraft.world.item.ItemStack)

Example 4 with IMaterial

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;
    }
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 5 with IMaterial

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));
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance) StaticLayer(net.silentchaos512.gear.api.material.StaticLayer)

Aggregations

IMaterial (net.silentchaos512.gear.api.material.IMaterial)17 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)9 ResourceLocation (net.minecraft.resources.ResourceLocation)8 ItemStack (net.minecraft.world.item.ItemStack)6 Nullable (javax.annotation.Nullable)5 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)5 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)4 Component (net.minecraft.network.chat.Component)3 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)3 PartType (net.silentchaos512.gear.api.part.PartType)3 LazyMaterialInstance (net.silentchaos512.gear.gear.material.LazyMaterialInstance)3 ArrayList (java.util.ArrayList)2 Collectors (java.util.stream.Collectors)2 ListTag (net.minecraft.nbt.ListTag)2 Tag (net.minecraft.nbt.Tag)2 ClickEvent (net.minecraft.network.chat.ClickEvent)2 TextComponent (net.minecraft.network.chat.TextComponent)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 Player (net.minecraft.world.entity.player.Player)2