Skip to content

Commit

Permalink
only consider valid block states in regex match; should fix lawremi#170
Browse files Browse the repository at this point in the history
  • Loading branch information
lawremi committed Dec 6, 2016
1 parent f131890 commit 9c7060b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/CustomOreGen/Util/BlockDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import java.util.Random;
import java.util.regex.Pattern;

import com.google.common.collect.ImmutableList;

import CustomOreGen.Server.DistributionSettingMap.Copyable;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
Expand Down Expand Up @@ -254,8 +256,7 @@ protected void compileMatches()
}
} else if (desc.regexp) {
for (Block block : Block.REGISTRY) {
String name = Block.REGISTRY.getNameForObject(block).toString();
float[] weights = desc.regexMatch(name);
float[] weights = desc.regexMatch(block);
this.add(block, desc.nbt, weights[Short.SIZE]);
if (weights[Short.SIZE] > 0 && desc.matchFirst) {
break;
Expand Down Expand Up @@ -493,14 +494,17 @@ public int getMeta() {
}
}

public float[] regexMatch(String name)
public float[] regexMatch(Block block)
{
float[] weights = new float[Short.SIZE + 1];

String name = Block.REGISTRY.getNameForObject(block).toString();

if (!this.getPattern().matcher(name).matches())
{
for (int m = 0; m < Short.SIZE; ++m)
ImmutableList<IBlockState> states = block.getBlockState().getValidStates();
for (IBlockState state : states)
{
int m = block.getMetaFromState(state);
if (this.getPattern().matcher(name + ":" + m).matches())
{
weights[m] += this.weight;
Expand Down

0 comments on commit 9c7060b

Please sign in to comment.