BlockStateHelper .java

net.minecraft.block.state.pattern.BlockStateHelper (class): members: propertyPredicates, blockstate, forBlock, apply, where. imports: Predicate, IProperty.

net.minecraft.block.state.patternclass62 linescommon1.8 KB

Implements

API Surface (3)

BlockStateHelper forBlock(Block blockIn)
boolean apply(IBlockState p_apply_1_)
<V extends Comparable<V>> BlockStateHelper where(IProperty<V> property, Predicate <? extends V > is)

Fields & Constants (2)

blockstate
propertyPredicates

String literals (1)

" cannot support property "

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

BlockStateHelper.java62 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block.state.pattern;
2
3
import com.google.common.base.Predicate;
4
import com.google.common.collect.Maps;
5
import java.util.Map;
6
import java.util.Map.Entry;
7
import net.minecraft.block.Block;
8
import net.minecraft.block.properties.IProperty;
9
import net.minecraft.block.state.BlockState;
10
import net.minecraft.block.state.IBlockState;
11
12
public class BlockStateHelper implements Predicate<IBlockState>
13
{
14
    private final BlockState blockstate;
15
    private final Map<IProperty, Predicate> propertyPredicates = Maps.<IProperty, Predicate>newHashMap();
16
17
    private BlockStateHelper(BlockState blockStateIn)
18
    {
19
        this.blockstate = blockStateIn;
20
    }
21
22
    public static BlockStateHelper forBlock(Block blockIn)
23
    {
24
        return new BlockStateHelper(blockIn.getBlockState());
25
    }
26
27
    public boolean apply(IBlockState p_apply_1_)
28
    {
29
        if (p_apply_1_ != null && p_apply_1_.getBlock().equals(this.blockstate.getBlock()))
30
        {
31
            for (Entry<IProperty, Predicate> entry : this.propertyPredicates.entrySet())
32
            {
33
                Object object = p_apply_1_.getValue((IProperty)entry.getKey());
34
35
                if (!((Predicate)entry.getValue()).apply(object))
36
                {
37
                    return false;
38
                }
39
            }
40
41
            return true;
42
        }
43
        else
44
        {
45
            return false;
46
        }
47
    }
48
49
    public <V extends Comparable<V>> BlockStateHelper where(IProperty<V> property, Predicate <? extends V > is)
50
    {
51
        if (!this.blockstate.getProperties().contains(property))
52
        {
53
            throw new IllegalArgumentException(this.blockstate + " cannot support property " + property);
54
        }
55
        else
56
        {
57
            this.propertyPredicates.put(property, is);
58
            return this;
59
        }
60
    }
61
}
62

Deobfuscated MCP 1.8.9 source of BlockStateHelper from Marcelektro/MavenMCP-1.8.9 (net/minecraft/block/state/pattern/BlockStateHelper.java), stored verbatim.