diff --git a/docs/content/Modpacks/Changes/v7.5.0.md b/docs/content/Modpacks/Changes/v7.5.0.md index 5be1593ff4..8480fd6014 100644 --- a/docs/content/Modpacks/Changes/v7.5.0.md +++ b/docs/content/Modpacks/Changes/v7.5.0.md @@ -25,4 +25,9 @@ You also need to adjust the generics of `getType()` and `createTemplate()` to ma A new system for copying machines using the Machine Memory Card has been added, see [this page](../Other-Topics/Cover-Machine-Copy-Paste-Support.md) if you want to add extra copy/paste behaviour to your own machines and covers. ## Mortar Recipe Fix -Previously, adding GTToolType.MORTAR to your tool did not automatically generate the recipe. This has been fixed. If you previously generated a recipe using this, you need to remove your manual recipe. \ No newline at end of file +Previously, adding GTToolType.MORTAR to your tool did not automatically generate the recipe. This has been fixed. If you previously generated a recipe using this, you need to remove your manual recipe. + +## Lamp Predicates +Previously, lamps were not useable with the terminal in multiblocks. There are new lamp predicates that will help solve this problem. +The predicate to use all lamps is: `Predicates.anyLamp()` +The predicate to use a specific color is: `Predicates.lampsByColor(DyeColor.DYE_COLOR)`. Where DYE_COLOR is the name of the color you want. \ No newline at end of file diff --git a/src/main/java/com/gregtechceu/gtceu/api/pattern/Predicates.java b/src/main/java/com/gregtechceu/gtceu/api/pattern/Predicates.java index 413a17137e..962b35c357 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/pattern/Predicates.java +++ b/src/main/java/com/gregtechceu/gtceu/api/pattern/Predicates.java @@ -17,6 +17,7 @@ import com.gregtechceu.gtceu.api.recipe.GTRecipeType; import com.gregtechceu.gtceu.common.block.BatteryBlock; import com.gregtechceu.gtceu.common.block.CoilBlock; +import com.gregtechceu.gtceu.common.block.LampBlock; import com.gregtechceu.gtceu.common.data.GTMaterialBlocks; import com.gregtechceu.gtceu.common.machine.multiblock.electric.PowerSubstationMachine; import com.gregtechceu.gtceu.config.ConfigHolder; @@ -25,11 +26,13 @@ import net.minecraft.network.chat.Component; import net.minecraft.tags.TagKey; +import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; +import com.tterrag.registrate.util.entry.BlockEntry; import com.tterrag.registrate.util.entry.RegistryEntry; import org.apache.commons.lang3.ArrayUtils; @@ -38,6 +41,8 @@ import java.util.function.Supplier; import static com.gregtechceu.gtceu.api.block.property.GTBlockStateProperties.ACTIVE; +import static com.gregtechceu.gtceu.common.data.GTBlocks.BORDERLESS_LAMPS; +import static com.gregtechceu.gtceu.common.data.GTBlocks.LAMPS; import static com.gregtechceu.gtceu.common.machine.multiblock.electric.PowerSubstationMachine.PMC_BATTERY_HEADER; public class Predicates { @@ -100,6 +105,32 @@ public static TraceabilityPredicate air() { return new TraceabilityPredicate(SimplePredicate.AIR); } + @SafeVarargs + public static TraceabilityPredicate lamps(BlockEntry... lampEntries) { + return new TraceabilityPredicate(blockWorldState -> { + BlockState state = blockWorldState.getBlockState(); + for (BlockEntry entry : lampEntries) { + if (state.is(entry.get())) return true; + } + return false; + }, () -> Arrays.stream(lampEntries) + .map(entry -> new BlockInfo(entry.get().defaultBlockState(), null)) + .toArray(BlockInfo[]::new)); + } + + public static TraceabilityPredicate anyLamp() { + List> all = new ArrayList<>(); + all.addAll(LAMPS.values()); + all.addAll(BORDERLESS_LAMPS.values()); + return lamps(all.toArray(BlockEntry[]::new)); + } + + private static final Map LAMPS_BY_COLOR = new EnumMap<>(DyeColor.class); + + public static TraceabilityPredicate lampsByColor(DyeColor color) { + return LAMPS_BY_COLOR.computeIfAbsent(color, c -> lamps(LAMPS.get(c), BORDERLESS_LAMPS.get(c))); + } + public static TraceabilityPredicate abilities(PartAbility... abilities) { return blocks(Arrays.stream(abilities).map(PartAbility::getAllBlocks).flatMap(Collection::stream) .toArray(Block[]::new));