Search in sources :

Example 1 with MaterialGrade

use of net.silentchaos512.gear.api.part.MaterialGrade in project Silent-Gear by SilentChaos512.

the class LazyMaterialInstance method read.

public static LazyMaterialInstance read(FriendlyByteBuf buffer) {
    ResourceLocation id = buffer.readResourceLocation();
    MaterialGrade grade = buffer.readEnum(MaterialGrade.class);
    return new LazyMaterialInstance(id, grade);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialGrade(net.silentchaos512.gear.api.part.MaterialGrade)

Example 2 with MaterialGrade

use of net.silentchaos512.gear.api.part.MaterialGrade in project Silent-Gear by SilentChaos512.

the class IMaterialInstance method serialize.

default JsonObject serialize() {
    JsonObject json = new JsonObject();
    json.addProperty("material", getId().toString());
    MaterialGrade grade = getGrade();
    if (grade != MaterialGrade.NONE) {
        json.addProperty("grade", grade.name());
    }
    return json;
}
Also used : JsonObject(com.google.gson.JsonObject) MaterialGrade(net.silentchaos512.gear.api.part.MaterialGrade)

Example 3 with MaterialGrade

use of net.silentchaos512.gear.api.part.MaterialGrade in project Silent-Gear by SilentChaos512.

the class GraderTileEntity method tryGradeItem.

private void tryGradeItem(ItemStack input, int catalystTier, IMaterialInstance material) {
    MaterialGrade targetGrade = MaterialGrade.selectWithCatalyst(SilentGear.RANDOM, catalystTier);
    this.lastGradeAttempt = targetGrade;
    if (targetGrade.ordinal() > material.getGrade().ordinal()) {
        // Assign grade, move to output slot
        ItemStack stack = input.split(1);
        targetGrade.setGradeOnStack(stack);
        InventoryUtils.mergeItem(this, 2, 2 + SLOTS_OUTPUT.length, stack);
    }
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) MaterialGrade(net.silentchaos512.gear.api.part.MaterialGrade)

Example 4 with MaterialGrade

use of net.silentchaos512.gear.api.part.MaterialGrade in project Silent-Gear by SilentChaos512.

the class LazyMaterialInstance method deserialize.

public static LazyMaterialInstance deserialize(JsonObject json) {
    ResourceLocation id = new ResourceLocation(GsonHelper.getAsString(json, "material"));
    MaterialGrade grade = EnumUtils.byName(GsonHelper.getAsString(json, "grade", "NONE"), MaterialGrade.NONE);
    return new LazyMaterialInstance(id, grade);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialGrade(net.silentchaos512.gear.api.part.MaterialGrade)

Example 5 with MaterialGrade

use of net.silentchaos512.gear.api.part.MaterialGrade in project Silent-Gear by SilentChaos512.

the class MaterialInstance method readShorthand.

@Nullable
public static MaterialInstance readShorthand(String str) {
    if (str.contains("#")) {
        String[] parts = str.split("#");
        ResourceLocation id = SilentGear.getIdWithDefaultNamespace(parts[0]);
        IMaterial material = MaterialManager.get(id);
        if (material != null) {
            MaterialGrade grade = MaterialGrade.fromString(parts[1]);
            return new MaterialInstance(material, grade);
        }
        return null;
    }
    ResourceLocation id = SilentGear.getIdWithDefaultNamespace(str);
    IMaterial material = MaterialManager.get(id);
    if (material != null) {
        return new MaterialInstance(material);
    }
    return null;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) MaterialGrade(net.silentchaos512.gear.api.part.MaterialGrade) Nullable(javax.annotation.Nullable)

Aggregations

MaterialGrade (net.silentchaos512.gear.api.part.MaterialGrade)6 ResourceLocation (net.minecraft.resources.ResourceLocation)3 JsonObject (com.google.gson.JsonObject)1 Nullable (javax.annotation.Nullable)1 Component (net.minecraft.network.chat.Component)1 ItemStack (net.minecraft.world.item.ItemStack)1