NaturesAura/src/main/java/de/ellpeck/naturesaura/api/multiblock/Matcher.java

62 lines
2.2 KiB
Java
Raw Normal View History

package de.ellpeck.naturesaura.api.multiblock;
import net.minecraft.block.Block;
2019-10-20 22:30:49 +02:00
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class Matcher {
2019-10-20 22:30:49 +02:00
private final BlockState defaultState;
private final ICheck check;
2019-10-20 22:30:49 +02:00
public Matcher(BlockState defaultState, ICheck check) {
this.defaultState = defaultState;
this.check = check;
}
2019-10-20 22:30:49 +02:00
public BlockState getDefaultState() {
return this.defaultState;
}
public ICheck getCheck() {
return this.check;
}
public static Matcher wildcard() {
return new Matcher(Blocks.AIR.getDefaultState(), null);
}
public static Matcher oreDict(Block defaultBlock, String name) {
2020-01-21 21:04:44 +01:00
return new Matcher(defaultBlock.getDefaultState(),
(world, start, offset, pos, state, otherC) -> state.getBlock() == defaultBlock);
/* TODO return new Matcher(defaultBlock.getDefaultState(), new ICheck() {
2019-10-20 22:30:49 +02:00
private List<BlockState> states;
@Override
2019-10-20 22:30:49 +02:00
public boolean matches(World world, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c) {
if (this.states == null) {
this.states = new ArrayList<>();
for (ItemStack stack : OreDictionary.getOres(name)) {
Block block = Block.getBlockFromItem(stack.getItem());
if (block != null && block != Blocks.AIR) {
int damage = stack.getItemDamage();
if (damage == OreDictionary.WILDCARD_VALUE)
this.states.addAll(block.getBlockState().getValidStates());
else
this.states.add(block.getStateFromMeta(damage));
}
}
}
return this.states.isEmpty() || this.states.contains(state);
}
2020-01-21 21:04:44 +01:00
});*/
}
public interface ICheck {
2019-10-20 22:30:49 +02:00
boolean matches(World world, BlockPos start, BlockPos offset, BlockPos pos, BlockState state, char c);
}
}