Skip to content

Commit

Permalink
Logic hacking for certain contexts to abide to the correct StoneType (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rongmario authored Feb 21, 2022
1 parent e7f9f08 commit fc4aefb
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/main/java/gregtech/api/unification/ore/StoneType.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,40 @@ public int compareTo(@Nonnull StoneType stoneType) {
return STONE_TYPE_REGISTRY.getIDForObject(this) - STONE_TYPE_REGISTRY.getIDForObject(stoneType);
}

private static final ThreadLocal<Boolean> hasDummyPredicateRan = ThreadLocal.withInitial(() -> false);
private static final com.google.common.base.Predicate<IBlockState> dummyPredicate = state -> {
hasDummyPredicateRan.set(true);
return false;
};

public static void init() {
//noinspection ResultOfMethodCallIgnored
StoneTypes.STONE.name.getBytes();
}

public static StoneType computeStoneType(IBlockState blockState, IBlockAccess world, BlockPos blockPos) {
//TODO ADD CONFIG HOOK HERE FOR MATCHING BLOCKS WITH STONE TYPES
for (StoneType stoneType : STONE_TYPE_REGISTRY) {
if (blockState.getBlock().isReplaceableOreGen(blockState, world, blockPos, stoneType.predicate))
return stoneType;
public static StoneType computeStoneType(IBlockState state, IBlockAccess world, BlockPos pos) {
// First: check if this Block's isReplaceableOreGen even considers the predicate passed through
boolean dummy$isReplaceableOreGen = state.getBlock().isReplaceableOreGen(state, world, pos, dummyPredicate);
if (hasDummyPredicateRan.get()) {
// Current Block's isReplaceableOreGen does indeed consider the predicate
// Reset hasDummyPredicateRan for the next test
hasDummyPredicateRan.set(false);
// Pass through actual predicates and test for real
for (StoneType stoneType : STONE_TYPE_REGISTRY) {
if (state.getBlock().isReplaceableOreGen(state, world, pos, stoneType.predicate)) {
// Found suitable match
return stoneType;
}
}
} else if (dummy$isReplaceableOreGen) {
// It is not considered, but the test still returned true (this means the impl was probably very lazily done)
// We have to test against the IBlockState ourselves to see if there's a suitable StoneType
for (StoneType stoneType : STONE_TYPE_REGISTRY) {
if (stoneType.predicate.test(state)) {
// Found suitable match
return stoneType;
}
}
}
return null;
}
Expand Down

0 comments on commit fc4aefb

Please sign in to comment.