-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to use block/fluid tags in multiblock patterns (#1030)
- Loading branch information
Showing
3 changed files
with
91 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/gregtechceu/gtceu/api/pattern/predicates/PredicateBlockTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.gregtechceu.gtceu.api.pattern.predicates; | ||
|
||
import com.lowdragmc.lowdraglib.utils.BlockInfo; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.HolderSet; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
|
||
public class PredicateBlockTag extends SimplePredicate { | ||
public TagKey<Block> tag = null; | ||
|
||
public PredicateBlockTag() { | ||
super("tags"); | ||
} | ||
|
||
public PredicateBlockTag(TagKey<Block> tag) { | ||
this(); | ||
this.tag = tag; | ||
buildPredicate(); | ||
} | ||
|
||
@Override | ||
public SimplePredicate buildPredicate() { | ||
if (tag == null) { | ||
predicate = state -> false; | ||
candidates = () -> new BlockInfo[] {BlockInfo.fromBlock(Blocks.BARRIER)}; | ||
return this; | ||
} | ||
predicate = state -> state.getBlockState().is(tag); | ||
candidates = () -> BuiltInRegistries.BLOCK.getTag(tag) | ||
.stream() | ||
.flatMap(HolderSet.Named::stream) | ||
.map(Holder::value) | ||
.map(BlockInfo::fromBlock) | ||
.toArray(BlockInfo[]::new); | ||
return this; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/gregtechceu/gtceu/api/pattern/predicates/PredicateFluidTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.gregtechceu.gtceu.api.pattern.predicates; | ||
|
||
import com.lowdragmc.lowdraglib.utils.BlockInfo; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.core.HolderSet; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.Blocks; | ||
import net.minecraft.world.level.material.Fluid; | ||
|
||
public class PredicateFluidTag extends SimplePredicate { | ||
public TagKey<Fluid> tag = null; | ||
|
||
public PredicateFluidTag() { | ||
super("tags"); | ||
} | ||
|
||
public PredicateFluidTag(TagKey<Fluid> tag) { | ||
this(); | ||
this.tag = tag; | ||
buildPredicate(); | ||
} | ||
|
||
@Override | ||
public SimplePredicate buildPredicate() { | ||
if (tag == null) { | ||
predicate = state -> false; | ||
candidates = () -> new BlockInfo[] {BlockInfo.fromBlock(Blocks.BARRIER)}; | ||
return this; | ||
} | ||
predicate = state -> state.getBlockState().getFluidState().is(tag); | ||
candidates = () -> BuiltInRegistries.FLUID.getTag(tag) | ||
.stream() | ||
.flatMap(HolderSet.Named::stream) | ||
.map(Holder::value) | ||
.map(fluid -> BlockInfo.fromBlockState(fluid.defaultFluidState().createLegacyBlock())) | ||
.toArray(BlockInfo[]::new); | ||
return this; | ||
} | ||
} |