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;
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations