|
17 | 17 | import com.gregtechceu.gtceu.api.recipe.GTRecipeType; |
18 | 18 | import com.gregtechceu.gtceu.common.block.BatteryBlock; |
19 | 19 | import com.gregtechceu.gtceu.common.block.CoilBlock; |
| 20 | +import com.gregtechceu.gtceu.common.block.LampBlock; |
20 | 21 | import com.gregtechceu.gtceu.common.data.GTMaterialBlocks; |
21 | 22 | import com.gregtechceu.gtceu.common.machine.multiblock.electric.PowerSubstationMachine; |
22 | 23 | import com.gregtechceu.gtceu.config.ConfigHolder; |
|
25 | 26 |
|
26 | 27 | import net.minecraft.network.chat.Component; |
27 | 28 | import net.minecraft.tags.TagKey; |
| 29 | +import net.minecraft.world.item.DyeColor; |
28 | 30 | import net.minecraft.world.level.block.Block; |
29 | 31 | import net.minecraft.world.level.block.entity.BlockEntity; |
30 | 32 | import net.minecraft.world.level.block.state.BlockState; |
31 | 33 | import net.minecraft.world.level.material.Fluid; |
32 | 34 |
|
| 35 | +import com.tterrag.registrate.util.entry.BlockEntry; |
33 | 36 | import com.tterrag.registrate.util.entry.RegistryEntry; |
34 | 37 | import org.apache.commons.lang3.ArrayUtils; |
35 | 38 |
|
|
38 | 41 | import java.util.function.Supplier; |
39 | 42 |
|
40 | 43 | 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; |
41 | 46 | import static com.gregtechceu.gtceu.common.machine.multiblock.electric.PowerSubstationMachine.PMC_BATTERY_HEADER; |
42 | 47 |
|
43 | 48 | public class Predicates { |
@@ -100,6 +105,32 @@ public static TraceabilityPredicate air() { |
100 | 105 | return new TraceabilityPredicate(SimplePredicate.AIR); |
101 | 106 | } |
102 | 107 |
|
| 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 | + |
103 | 134 | public static TraceabilityPredicate abilities(PartAbility... abilities) { |
104 | 135 | return blocks(Arrays.stream(abilities).map(PartAbility::getAllBlocks).flatMap(Collection::stream) |
105 | 136 | .toArray(Block[]::new)); |
|
0 commit comments