initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
61
java/src/game/pattern/BlockStateHelper.java
Executable file
61
java/src/game/pattern/BlockStateHelper.java
Executable file
|
@ -0,0 +1,61 @@
|
|||
package game.pattern;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import game.block.Block;
|
||||
import game.collect.Maps;
|
||||
import game.properties.IProperty;
|
||||
import game.world.State;
|
||||
|
||||
public class BlockStateHelper implements Predicate<State>
|
||||
{
|
||||
private final Block block;
|
||||
private final Map<IProperty, Predicate> predicates = Maps.<IProperty, Predicate>newHashMap();
|
||||
|
||||
private BlockStateHelper(Block blockStateIn)
|
||||
{
|
||||
this.block = blockStateIn;
|
||||
}
|
||||
|
||||
public static BlockStateHelper forBlock(Block blockIn)
|
||||
{
|
||||
return new BlockStateHelper(blockIn);
|
||||
}
|
||||
|
||||
public boolean test(State p_apply_1_)
|
||||
{
|
||||
if (p_apply_1_ != null && p_apply_1_.getBlock().equals(this.block))
|
||||
{
|
||||
for (Entry<IProperty, Predicate> entry : this.predicates.entrySet())
|
||||
{
|
||||
Object object = p_apply_1_.getValue((IProperty)entry.getKey());
|
||||
|
||||
if (!((Predicate)entry.getValue()).test(object))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public <V extends Comparable<V>> BlockStateHelper where(IProperty<V> property, Predicate <? extends V > is)
|
||||
{
|
||||
if (!this.block.getPropertyMap().contains(property))
|
||||
{
|
||||
throw new IllegalArgumentException(this.block + " cannot support property " + property);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.predicates.put(property, is);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue