BlockStateBase .java

net.minecraft.block.state.BlockStateBase (class): members: MAP_ENTRY_TO_STRING, cyclePropertyValue, cycleProperty, COMMA_JOINER, toString. imports: Joiner.

net.minecraft.block.stateclass71 linescommon2.2 KB

Implements

API Surface (4)

String apply(Entry<IProperty, Comparable> p_apply_1_)
<T extends Comparable<T>> IBlockState cycleProperty(IProperty<T> property)
<T> T cyclePropertyValue(Collection<T> values, T currentValue)
String toString()

Fields & Constants (2)

COMMA_JOINER
MAP_ENTRY_TO_STRING

String literals (1)

"<NULL>"

Code Graph: Dependencies (3)

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

Full Source

BlockStateBase.java71 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.block.state;
2
3
import com.google.common.base.Function;
4
import com.google.common.base.Joiner;
5
import com.google.common.collect.Iterables;
6
import java.util.Collection;
7
import java.util.Iterator;
8
import java.util.Map.Entry;
9
import net.minecraft.block.Block;
10
import net.minecraft.block.properties.IProperty;
11
12
public abstract class BlockStateBase implements IBlockState
13
{
14
    private static final Joiner COMMA_JOINER = Joiner.on(',');
15
    private static final Function<Entry<IProperty, Comparable>, String> MAP_ENTRY_TO_STRING = new Function<Entry<IProperty, Comparable>, String>()
16
    {
17
        public String apply(Entry<IProperty, Comparable> p_apply_1_)
18
        {
19
            if (p_apply_1_ == null)
20
            {
21
                return "<NULL>";
22
            }
23
            else
24
            {
25
                IProperty iproperty = (IProperty)p_apply_1_.getKey();
26
                return iproperty.getName() + "=" + iproperty.getName((Comparable)p_apply_1_.getValue());
27
            }
28
        }
29
    };
30
31
    public <T extends Comparable<T>> IBlockState cycleProperty(IProperty<T> property)
32
    {
33
        return this.withProperty(property, cyclePropertyValue(property.getAllowedValues(), this.getValue(property)));
34
    }
35
36
    protected static <T> T cyclePropertyValue(Collection<T> values, T currentValue)
37
    {
38
        Iterator<T> iterator = values.iterator();
39
40
        while (iterator.hasNext())
41
        {
42
            if (iterator.next().equals(currentValue))
43
            {
44
                if (iterator.hasNext())
45
                {
46
                    return (T)iterator.next();
47
                }
48
49
                return (T)values.iterator().next();
50
            }
51
        }
52
53
        return (T)iterator.next();
54
    }
55
56
    public String toString()
57
    {
58
        StringBuilder stringbuilder = new StringBuilder();
59
        stringbuilder.append(Block.blockRegistry.getNameForObject(this.getBlock()));
60
61
        if (!this.getProperties().isEmpty())
62
        {
63
            stringbuilder.append("[");
64
            COMMA_JOINER.appendTo(stringbuilder, Iterables.transform(this.getProperties().entrySet(), MAP_ENTRY_TO_STRING));
65
            stringbuilder.append("]");
66
        }
67
68
        return stringbuilder.toString();
69
    }
70
}
71

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