Skip to content

Commit 3f7e588

Browse files
Phoenixvine32908Ghostipediajurrejellegustovafing
authored
Lamp predicates. (#4511)
Co-authored-by: Ghostipedia / Caitlynn <46772882+Ghostipedia@users.noreply.github.com> Co-authored-by: Jurre Groenendijk <jurre@jilles.com> Co-authored-by: Gustavo <77560533+gustovafing@users.noreply.github.com>
1 parent 97847f7 commit 3f7e588

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

docs/content/Modpacks/Changes/v7.5.0.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ You also need to adjust the generics of `getType()` and `createTemplate()` to ma
2525
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.
2626

2727
## Mortar Recipe Fix
28-
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.
28+
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.
29+
30+
## Lamp Predicates
31+
Previously, lamps were not useable with the terminal in multiblocks. There are new lamp predicates that will help solve this problem.
32+
The predicate to use all lamps is: `Predicates.anyLamp()`
33+
The predicate to use a specific color is: `Predicates.lampsByColor(DyeColor.DYE_COLOR)`. Where DYE_COLOR is the name of the color you want.

src/main/java/com/gregtechceu/gtceu/api/pattern/Predicates.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
1818
import com.gregtechceu.gtceu.common.block.BatteryBlock;
1919
import com.gregtechceu.gtceu.common.block.CoilBlock;
20+
import com.gregtechceu.gtceu.common.block.LampBlock;
2021
import com.gregtechceu.gtceu.common.data.GTMaterialBlocks;
2122
import com.gregtechceu.gtceu.common.machine.multiblock.electric.PowerSubstationMachine;
2223
import com.gregtechceu.gtceu.config.ConfigHolder;
@@ -25,11 +26,13 @@
2526

2627
import net.minecraft.network.chat.Component;
2728
import net.minecraft.tags.TagKey;
29+
import net.minecraft.world.item.DyeColor;
2830
import net.minecraft.world.level.block.Block;
2931
import net.minecraft.world.level.block.entity.BlockEntity;
3032
import net.minecraft.world.level.block.state.BlockState;
3133
import net.minecraft.world.level.material.Fluid;
3234

35+
import com.tterrag.registrate.util.entry.BlockEntry;
3336
import com.tterrag.registrate.util.entry.RegistryEntry;
3437
import org.apache.commons.lang3.ArrayUtils;
3538

@@ -38,6 +41,8 @@
3841
import java.util.function.Supplier;
3942

4043
import static com.gregtechceu.gtceu.api.block.property.GTBlockStateProperties.ACTIVE;
44+
import static com.gregtechceu.gtceu.common.data.GTBlocks.BORDERLESS_LAMPS;
45+
import static com.gregtechceu.gtceu.common.data.GTBlocks.LAMPS;
4146
import static com.gregtechceu.gtceu.common.machine.multiblock.electric.PowerSubstationMachine.PMC_BATTERY_HEADER;
4247

4348
public class Predicates {
@@ -100,6 +105,32 @@ public static TraceabilityPredicate air() {
100105
return new TraceabilityPredicate(SimplePredicate.AIR);
101106
}
102107

108+
@SafeVarargs
109+
public static TraceabilityPredicate lamps(BlockEntry<LampBlock>... lampEntries) {
110+
return new TraceabilityPredicate(blockWorldState -> {
111+
BlockState state = blockWorldState.getBlockState();
112+
for (BlockEntry<LampBlock> entry : lampEntries) {
113+
if (state.is(entry.get())) return true;
114+
}
115+
return false;
116+
}, () -> Arrays.stream(lampEntries)
117+
.map(entry -> new BlockInfo(entry.get().defaultBlockState(), null))
118+
.toArray(BlockInfo[]::new));
119+
}
120+
121+
public static TraceabilityPredicate anyLamp() {
122+
List<BlockEntry<LampBlock>> all = new ArrayList<>();
123+
all.addAll(LAMPS.values());
124+
all.addAll(BORDERLESS_LAMPS.values());
125+
return lamps(all.toArray(BlockEntry[]::new));
126+
}
127+
128+
private static final Map<DyeColor, TraceabilityPredicate> LAMPS_BY_COLOR = new EnumMap<>(DyeColor.class);
129+
130+
public static TraceabilityPredicate lampsByColor(DyeColor color) {
131+
return LAMPS_BY_COLOR.computeIfAbsent(color, c -> lamps(LAMPS.get(c), BORDERLESS_LAMPS.get(c)));
132+
}
133+
103134
public static TraceabilityPredicate abilities(PartAbility... abilities) {
104135
return blocks(Arrays.stream(abilities).map(PartAbility::getAllBlocks).flatMap(Collection::stream)
105136
.toArray(Block[]::new));

0 commit comments

Comments
 (0)