Search in sources :

Example 1 with MaterialList

use of net.silentchaos512.gear.api.material.MaterialList in project Silent-Gear by SilentChaos512.

the class MaterialList method deserializeNbt.

public static MaterialList deserializeNbt(ListTag listNbt) {
    MaterialList ret = new MaterialList();
    for (int i = 0; i < listNbt.size(); ++i) {
        CompoundTag compoundNbt = listNbt.getCompound(i);
        MaterialInstance material = MaterialInstance.read(compoundNbt);
        if (material != null) {
            int count = compoundNbt.contains("Count") ? compoundNbt.getByte("Count") : 1;
            for (int j = 0; j < count; ++j) {
                ret.list.add(material);
            }
        }
    }
    return ret;
}
Also used : MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with MaterialList

use of net.silentchaos512.gear.api.material.MaterialList in project Silent-Gear by SilentChaos512.

the class CompounderTileEntity method getInputs.

private MaterialList getInputs() {
    boolean allEmpty = true;
    for (int i = 0; i < getInputSlotCount(); ++i) {
        ItemStack stack = getItem(i);
        if (!stack.isEmpty()) {
            allEmpty = false;
            break;
        }
    }
    if (allEmpty) {
        return MaterialList.empty();
    }
    MaterialList ret = MaterialList.empty();
    for (int i = 0; i < getInputSlotCount(); ++i) {
        ItemStack stack = getItem(i);
        if (!stack.isEmpty()) {
            MaterialInstance material = MaterialInstance.from(stack);
            if (material != null && material.get().isSimple()) {
                ret.add(material);
            } else {
                return MaterialList.empty();
            }
        }
    }
    return ret;
}
Also used : MaterialList(net.silentchaos512.gear.api.material.MaterialList) ItemStack(net.minecraft.world.item.ItemStack) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 3 with MaterialList

use of net.silentchaos512.gear.api.material.MaterialList in project Silent-Gear by SilentChaos512.

the class CompounderTileEntity method tick.

public static <R extends CompoundingRecipe> void tick(Level level, BlockPos pos, BlockState state, CompounderTileEntity<R> blockEntity) {
    if (blockEntity.areInputsEmpty()) {
        // No point in doing anything when input slots are empty
        blockEntity.updateOutputHint(ItemStack.EMPTY);
        return;
    }
    R recipe = blockEntity.getRecipe();
    if (recipe != null) {
        // Inputs match a custom recipe
        blockEntity.doWork(recipe, MaterialList.empty());
    } else {
        // No recipe, but we might be able to make a generic compound
        MaterialList materials = blockEntity.getInputs();
        if (!hasMultipleMaterials(materials) || !blockEntity.canCompoundMaterials(materials)) {
            // Not a valid combination
            blockEntity.stopWork(true);
            return;
        }
        blockEntity.doWork(null, materials);
    }
}
Also used : MaterialList(net.silentchaos512.gear.api.material.MaterialList)

Example 4 with MaterialList

use of net.silentchaos512.gear.api.material.MaterialList in project Silent-Gear by SilentChaos512.

the class CompoundMaterialItem method create.

public ItemStack create(MaterialList materials, int craftedCount) {
    ItemStack result = new ItemStack(this, craftedCount);
    MaterialList materialsWithoutEnhancements = MaterialList.of(materials.stream().map(AbstractMaterial::removeEnhancements).collect(Collectors.toList()));
    result.getOrCreateTag().put(NBT_MATERIALS, materialsWithoutEnhancements.serializeNbt());
    return result;
}
Also used : MaterialList(net.silentchaos512.gear.api.material.MaterialList) AbstractMaterial(net.silentchaos512.gear.gear.material.AbstractMaterial) ItemStack(net.minecraft.world.item.ItemStack)

Example 5 with MaterialList

use of net.silentchaos512.gear.api.material.MaterialList in project Silent-Gear by SilentChaos512.

the class CompoundMaterialItem method getSubMaterials.

public static MaterialList getSubMaterials(ItemStack stack) {
    MaterialList ret = MaterialList.empty();
    ListTag listNbt = stack.getOrCreateTag().getList(NBT_MATERIALS, Tag.TAG_STRING);
    if (!listNbt.isEmpty()) {
        for (Tag nbt : listNbt) {
            IMaterial mat = MaterialManager.get(SilentGear.getIdWithDefaultNamespace(nbt.getAsString()));
            if (mat != null) {
                ret.add(MaterialInstance.of(mat));
            }
        }
    } else {
        ListTag list = stack.getOrCreateTag().getList(NBT_MATERIALS, Tag.TAG_COMPOUND);
        return MaterialList.deserializeNbt(list);
    }
    return ret;
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialList(net.silentchaos512.gear.api.material.MaterialList) Tag(net.minecraft.nbt.Tag) ListTag(net.minecraft.nbt.ListTag) ListTag(net.minecraft.nbt.ListTag)

Aggregations

MaterialList (net.silentchaos512.gear.api.material.MaterialList)4 ItemStack (net.minecraft.world.item.ItemStack)2 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)2 CompoundTag (net.minecraft.nbt.CompoundTag)1 ListTag (net.minecraft.nbt.ListTag)1 Tag (net.minecraft.nbt.Tag)1 IMaterial (net.silentchaos512.gear.api.material.IMaterial)1 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)1 AbstractMaterial (net.silentchaos512.gear.gear.material.AbstractMaterial)1