| 1 | package net.minecraft.client.renderer.block.statemap;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.google.common.collect.Maps;
|
| 5 | import java.util.Collections;
|
| 6 | import java.util.List;
|
| 7 | import java.util.Map;
|
| 8 | import net.minecraft.block.Block;
|
| 9 | import net.minecraft.block.properties.IProperty;
|
| 10 | import net.minecraft.block.state.IBlockState;
|
| 11 | import net.minecraft.client.resources.model.ModelResourceLocation;
|
| 12 | import net.minecraft.util.ResourceLocation;
|
| 13 |
|
| 14 | public class StateMap extends StateMapperBase
|
| 15 | {
|
| 16 | private final IProperty<?> name;
|
| 17 | private final String suffix;
|
| 18 | private final List < IProperty<? >> ignored;
|
| 19 |
|
| 20 | private StateMap(IProperty<?> name, String suffix, List < IProperty<? >> ignored)
|
| 21 | {
|
| 22 | this.name = name;
|
| 23 | this.suffix = suffix;
|
| 24 | this.ignored = ignored;
|
| 25 | }
|
| 26 |
|
| 27 | protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
| 28 | {
|
| 29 | Map<IProperty, Comparable> map = Maps.<IProperty, Comparable>newLinkedHashMap(state.getProperties());
|
| 30 | String s;
|
| 31 |
|
| 32 | if (this.name == null)
|
| 33 | {
|
| 34 | s = ((ResourceLocation)Block.blockRegistry.getNameForObject(state.getBlock())).toString();
|
| 35 | }
|
| 36 | else
|
| 37 | {
|
| 38 | s = ((IProperty)this.name).getName((Comparable)map.remove(this.name));
|
| 39 | }
|
| 40 |
|
| 41 | if (this.suffix != null)
|
| 42 | {
|
| 43 | s = s + this.suffix;
|
| 44 | }
|
| 45 |
|
| 46 | for (IProperty<?> iproperty : this.ignored)
|
| 47 | {
|
| 48 | map.remove(iproperty);
|
| 49 | }
|
| 50 |
|
| 51 | return new ModelResourceLocation(s, this.getPropertyString(map));
|
| 52 | }
|
| 53 |
|
| 54 | public static class Builder
|
| 55 | {
|
| 56 | private IProperty<?> name;
|
| 57 | private String suffix;
|
| 58 | private final List < IProperty<? >> ignored = Lists. < IProperty<? >> newArrayList();
|
| 59 |
|
| 60 | public StateMap.Builder withName(IProperty<?> builderPropertyIn)
|
| 61 | {
|
| 62 | this.name = builderPropertyIn;
|
| 63 | return this;
|
| 64 | }
|
| 65 |
|
| 66 | public StateMap.Builder withSuffix(String builderSuffixIn)
|
| 67 | {
|
| 68 | this.suffix = builderSuffixIn;
|
| 69 | return this;
|
| 70 | }
|
| 71 |
|
| 72 | public StateMap.Builder ignore(IProperty<?>... p_178442_1_)
|
| 73 | {
|
| 74 | Collections.addAll(this.ignored, p_178442_1_);
|
| 75 | return this;
|
| 76 | }
|
| 77 |
|
| 78 | public StateMap build()
|
| 79 | {
|
| 80 | return new StateMap(this.name, this.suffix, this.ignored);
|
| 81 | }
|
| 82 | }
|
| 83 | }
|
| 84 |
|