| 1 | package net.minecraft.client.renderer;
|
| 2 |
|
| 3 | import com.google.common.collect.Maps;
|
| 4 | import java.util.Map;
|
| 5 | import java.util.Map.Entry;
|
| 6 | import net.minecraft.block.Block;
|
| 7 | import net.minecraft.block.BlockBed;
|
| 8 | import net.minecraft.block.BlockCactus;
|
| 9 | import net.minecraft.block.BlockColored;
|
| 10 | import net.minecraft.block.BlockCommandBlock;
|
| 11 | import net.minecraft.block.BlockDirt;
|
| 12 | import net.minecraft.block.BlockDispenser;
|
| 13 | import net.minecraft.block.BlockDoor;
|
| 14 | import net.minecraft.block.BlockDoublePlant;
|
| 15 | import net.minecraft.block.BlockDropper;
|
| 16 | import net.minecraft.block.BlockFenceGate;
|
| 17 | import net.minecraft.block.BlockFire;
|
| 18 | import net.minecraft.block.BlockFlowerPot;
|
| 19 | import net.minecraft.block.BlockHopper;
|
| 20 | import net.minecraft.block.BlockJukebox;
|
| 21 | import net.minecraft.block.BlockLeaves;
|
| 22 | import net.minecraft.block.BlockNewLeaf;
|
| 23 | import net.minecraft.block.BlockNewLog;
|
| 24 | import net.minecraft.block.BlockOldLeaf;
|
| 25 | import net.minecraft.block.BlockOldLog;
|
| 26 | import net.minecraft.block.BlockPlanks;
|
| 27 | import net.minecraft.block.BlockPrismarine;
|
| 28 | import net.minecraft.block.BlockQuartz;
|
| 29 | import net.minecraft.block.BlockRedSandstone;
|
| 30 | import net.minecraft.block.BlockRedstoneWire;
|
| 31 | import net.minecraft.block.BlockReed;
|
| 32 | import net.minecraft.block.BlockSand;
|
| 33 | import net.minecraft.block.BlockSandStone;
|
| 34 | import net.minecraft.block.BlockSapling;
|
| 35 | import net.minecraft.block.BlockSilverfish;
|
| 36 | import net.minecraft.block.BlockStem;
|
| 37 | import net.minecraft.block.BlockStone;
|
| 38 | import net.minecraft.block.BlockStoneBrick;
|
| 39 | import net.minecraft.block.BlockStoneSlab;
|
| 40 | import net.minecraft.block.BlockStoneSlabNew;
|
| 41 | import net.minecraft.block.BlockTNT;
|
| 42 | import net.minecraft.block.BlockTallGrass;
|
| 43 | import net.minecraft.block.BlockTripWire;
|
| 44 | import net.minecraft.block.BlockWall;
|
| 45 | import net.minecraft.block.properties.IProperty;
|
| 46 | import net.minecraft.block.state.IBlockState;
|
| 47 | import net.minecraft.client.renderer.block.statemap.BlockStateMapper;
|
| 48 | import net.minecraft.client.renderer.block.statemap.IStateMapper;
|
| 49 | import net.minecraft.client.renderer.block.statemap.StateMap;
|
| 50 | import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
| 51 | import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
| 52 | import net.minecraft.client.resources.model.IBakedModel;
|
| 53 | import net.minecraft.client.resources.model.ModelManager;
|
| 54 | import net.minecraft.client.resources.model.ModelResourceLocation;
|
| 55 | import net.minecraft.init.Blocks;
|
| 56 | import net.minecraft.util.EnumFacing;
|
| 57 | import net.minecraft.util.ResourceLocation;
|
| 58 |
|
| 59 | public class BlockModelShapes
|
| 60 | {
|
| 61 | private final Map<IBlockState, IBakedModel> bakedModelStore = Maps.<IBlockState, IBakedModel>newIdentityHashMap();
|
| 62 | private final BlockStateMapper blockStateMapper = new BlockStateMapper();
|
| 63 | private final ModelManager modelManager;
|
| 64 |
|
| 65 | public BlockModelShapes(ModelManager manager)
|
| 66 | {
|
| 67 | this.modelManager = manager;
|
| 68 | this.registerAllBlocks();
|
| 69 | }
|
| 70 |
|
| 71 | public BlockStateMapper getBlockStateMapper()
|
| 72 | {
|
| 73 | return this.blockStateMapper;
|
| 74 | }
|
| 75 |
|
| 76 | public TextureAtlasSprite getTexture(IBlockState state)
|
| 77 | {
|
| 78 | Block block = state.getBlock();
|
| 79 | IBakedModel ibakedmodel = this.getModelForState(state);
|
| 80 |
|
| 81 | if (ibakedmodel == null || ibakedmodel == this.modelManager.getMissingModel())
|
| 82 | {
|
| 83 | if (block == Blocks.wall_sign || block == Blocks.standing_sign || block == Blocks.chest || block == Blocks.trapped_chest || block == Blocks.standing_banner || block == Blocks.wall_banner)
|
| 84 | {
|
| 85 | return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/planks_oak");
|
| 86 | }
|
| 87 |
|
| 88 | if (block == Blocks.ender_chest)
|
| 89 | {
|
| 90 | return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/obsidian");
|
| 91 | }
|
| 92 |
|
| 93 | if (block == Blocks.flowing_lava || block == Blocks.lava)
|
| 94 | {
|
| 95 | return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/lava_still");
|
| 96 | }
|
| 97 |
|
| 98 | if (block == Blocks.flowing_water || block == Blocks.water)
|
| 99 | {
|
| 100 | return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/water_still");
|
| 101 | }
|
| 102 |
|
| 103 | if (block == Blocks.skull)
|
| 104 | {
|
| 105 | return this.modelManager.getTextureMap().getAtlasSprite("minecraft:blocks/soul_sand");
|
| 106 | }
|
| 107 |
|
| 108 | if (block == Blocks.barrier)
|
| 109 | {
|
| 110 | return this.modelManager.getTextureMap().getAtlasSprite("minecraft:items/barrier");
|
| 111 | }
|
| 112 | }
|
| 113 |
|
| 114 | if (ibakedmodel == null)
|
| 115 | {
|
| 116 | ibakedmodel = this.modelManager.getMissingModel();
|
| 117 | }
|
| 118 |
|
| 119 | return ibakedmodel.getParticleTexture();
|
| 120 | }
|
| 121 |
|
| 122 | public IBakedModel getModelForState(IBlockState state)
|
| 123 | {
|
| 124 | IBakedModel ibakedmodel = (IBakedModel)this.bakedModelStore.get(state);
|
| 125 |
|
| 126 | if (ibakedmodel == null)
|
| 127 | {
|
| 128 | ibakedmodel = this.modelManager.getMissingModel();
|
| 129 | }
|
| 130 |
|
| 131 | return ibakedmodel;
|
| 132 | }
|
| 133 |
|
| 134 | public ModelManager getModelManager()
|
| 135 | {
|
| 136 | return this.modelManager;
|
| 137 | }
|
| 138 |
|
| 139 | public void reloadModels()
|
| 140 | {
|
| 141 | this.bakedModelStore.clear();
|
| 142 |
|
| 143 | for (Entry<IBlockState, ModelResourceLocation> entry : this.blockStateMapper.putAllStateModelLocations().entrySet())
|
| 144 | {
|
| 145 | this.bakedModelStore.put(entry.getKey(), this.modelManager.getModel((ModelResourceLocation)entry.getValue()));
|
| 146 | }
|
| 147 | }
|
| 148 |
|
| 149 | public void registerBlockWithStateMapper(Block assoc, IStateMapper stateMapper)
|
| 150 | {
|
| 151 | this.blockStateMapper.registerBlockStateMapper(assoc, stateMapper);
|
| 152 | }
|
| 153 |
|
| 154 | public void registerBuiltInBlocks(Block... builtIns)
|
| 155 | {
|
| 156 | this.blockStateMapper.registerBuiltInBlocks(builtIns);
|
| 157 | }
|
| 158 |
|
| 159 | private void registerAllBlocks()
|
| 160 | {
|
| 161 | this.registerBuiltInBlocks(new Block[] {Blocks.air, Blocks.flowing_water, Blocks.water, Blocks.flowing_lava, Blocks.lava, Blocks.piston_extension, Blocks.chest, Blocks.ender_chest, Blocks.trapped_chest, Blocks.standing_sign, Blocks.skull, Blocks.end_portal, Blocks.barrier, Blocks.wall_sign, Blocks.wall_banner, Blocks.standing_banner});
|
| 162 | this.registerBlockWithStateMapper(Blocks.stone, (new StateMap.Builder()).withName(BlockStone.VARIANT).build());
|
| 163 | this.registerBlockWithStateMapper(Blocks.prismarine, (new StateMap.Builder()).withName(BlockPrismarine.VARIANT).build());
|
| 164 | this.registerBlockWithStateMapper(Blocks.leaves, (new StateMap.Builder()).withName(BlockOldLeaf.VARIANT).withSuffix("_leaves").ignore(new IProperty[] {BlockLeaves.CHECK_DECAY, BlockLeaves.DECAYABLE}).build());
|
| 165 | this.registerBlockWithStateMapper(Blocks.leaves2, (new StateMap.Builder()).withName(BlockNewLeaf.VARIANT).withSuffix("_leaves").ignore(new IProperty[] {BlockLeaves.CHECK_DECAY, BlockLeaves.DECAYABLE}).build());
|
| 166 | this.registerBlockWithStateMapper(Blocks.cactus, (new StateMap.Builder()).ignore(new IProperty[] {BlockCactus.AGE}).build());
|
| 167 | this.registerBlockWithStateMapper(Blocks.reeds, (new StateMap.Builder()).ignore(new IProperty[] {BlockReed.AGE}).build());
|
| 168 | this.registerBlockWithStateMapper(Blocks.jukebox, (new StateMap.Builder()).ignore(new IProperty[] {BlockJukebox.HAS_RECORD}).build());
|
| 169 | this.registerBlockWithStateMapper(Blocks.command_block, (new StateMap.Builder()).ignore(new IProperty[] {BlockCommandBlock.TRIGGERED}).build());
|
| 170 | this.registerBlockWithStateMapper(Blocks.cobblestone_wall, (new StateMap.Builder()).withName(BlockWall.VARIANT).withSuffix("_wall").build());
|
| 171 | this.registerBlockWithStateMapper(Blocks.double_plant, (new StateMap.Builder()).withName(BlockDoublePlant.VARIANT).ignore(new IProperty[] {BlockDoublePlant.FACING}).build());
|
| 172 | this.registerBlockWithStateMapper(Blocks.oak_fence_gate, (new StateMap.Builder()).ignore(new IProperty[] {BlockFenceGate.POWERED}).build());
|
| 173 | this.registerBlockWithStateMapper(Blocks.spruce_fence_gate, (new StateMap.Builder()).ignore(new IProperty[] {BlockFenceGate.POWERED}).build());
|
| 174 | this.registerBlockWithStateMapper(Blocks.birch_fence_gate, (new StateMap.Builder()).ignore(new IProperty[] {BlockFenceGate.POWERED}).build());
|
| 175 | this.registerBlockWithStateMapper(Blocks.jungle_fence_gate, (new StateMap.Builder()).ignore(new IProperty[] {BlockFenceGate.POWERED}).build());
|
| 176 | this.registerBlockWithStateMapper(Blocks.dark_oak_fence_gate, (new StateMap.Builder()).ignore(new IProperty[] {BlockFenceGate.POWERED}).build());
|
| 177 | this.registerBlockWithStateMapper(Blocks.acacia_fence_gate, (new StateMap.Builder()).ignore(new IProperty[] {BlockFenceGate.POWERED}).build());
|
| 178 | this.registerBlockWithStateMapper(Blocks.tripwire, (new StateMap.Builder()).ignore(new IProperty[] {BlockTripWire.DISARMED, BlockTripWire.POWERED}).build());
|
| 179 | this.registerBlockWithStateMapper(Blocks.double_wooden_slab, (new StateMap.Builder()).withName(BlockPlanks.VARIANT).withSuffix("_double_slab").build());
|
| 180 | this.registerBlockWithStateMapper(Blocks.wooden_slab, (new StateMap.Builder()).withName(BlockPlanks.VARIANT).withSuffix("_slab").build());
|
| 181 | this.registerBlockWithStateMapper(Blocks.tnt, (new StateMap.Builder()).ignore(new IProperty[] {BlockTNT.EXPLODE}).build());
|
| 182 | this.registerBlockWithStateMapper(Blocks.fire, (new StateMap.Builder()).ignore(new IProperty[] {BlockFire.AGE}).build());
|
| 183 | this.registerBlockWithStateMapper(Blocks.redstone_wire, (new StateMap.Builder()).ignore(new IProperty[] {BlockRedstoneWire.POWER}).build());
|
| 184 | this.registerBlockWithStateMapper(Blocks.oak_door, (new StateMap.Builder()).ignore(new IProperty[] {BlockDoor.POWERED}).build());
|
| 185 | this.registerBlockWithStateMapper(Blocks.spruce_door, (new StateMap.Builder()).ignore(new IProperty[] {BlockDoor.POWERED}).build());
|
| 186 | this.registerBlockWithStateMapper(Blocks.birch_door, (new StateMap.Builder()).ignore(new IProperty[] {BlockDoor.POWERED}).build());
|
| 187 | this.registerBlockWithStateMapper(Blocks.jungle_door, (new StateMap.Builder()).ignore(new IProperty[] {BlockDoor.POWERED}).build());
|
| 188 | this.registerBlockWithStateMapper(Blocks.acacia_door, (new StateMap.Builder()).ignore(new IProperty[] {BlockDoor.POWERED}).build());
|
| 189 | this.registerBlockWithStateMapper(Blocks.dark_oak_door, (new StateMap.Builder()).ignore(new IProperty[] {BlockDoor.POWERED}).build());
|
| 190 | this.registerBlockWithStateMapper(Blocks.iron_door, (new StateMap.Builder()).ignore(new IProperty[] {BlockDoor.POWERED}).build());
|
| 191 | this.registerBlockWithStateMapper(Blocks.wool, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_wool").build());
|
| 192 | this.registerBlockWithStateMapper(Blocks.carpet, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_carpet").build());
|
| 193 | this.registerBlockWithStateMapper(Blocks.stained_hardened_clay, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_stained_hardened_clay").build());
|
| 194 | this.registerBlockWithStateMapper(Blocks.stained_glass_pane, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_stained_glass_pane").build());
|
| 195 | this.registerBlockWithStateMapper(Blocks.stained_glass, (new StateMap.Builder()).withName(BlockColored.COLOR).withSuffix("_stained_glass").build());
|
| 196 | this.registerBlockWithStateMapper(Blocks.sandstone, (new StateMap.Builder()).withName(BlockSandStone.TYPE).build());
|
| 197 | this.registerBlockWithStateMapper(Blocks.red_sandstone, (new StateMap.Builder()).withName(BlockRedSandstone.TYPE).build());
|
| 198 | this.registerBlockWithStateMapper(Blocks.tallgrass, (new StateMap.Builder()).withName(BlockTallGrass.TYPE).build());
|
| 199 | this.registerBlockWithStateMapper(Blocks.bed, (new StateMap.Builder()).ignore(new IProperty[] {BlockBed.OCCUPIED}).build());
|
| 200 | this.registerBlockWithStateMapper(Blocks.yellow_flower, (new StateMap.Builder()).withName(Blocks.yellow_flower.getTypeProperty()).build());
|
| 201 | this.registerBlockWithStateMapper(Blocks.red_flower, (new StateMap.Builder()).withName(Blocks.red_flower.getTypeProperty()).build());
|
| 202 | this.registerBlockWithStateMapper(Blocks.stone_slab, (new StateMap.Builder()).withName(BlockStoneSlab.VARIANT).withSuffix("_slab").build());
|
| 203 | this.registerBlockWithStateMapper(Blocks.stone_slab2, (new StateMap.Builder()).withName(BlockStoneSlabNew.VARIANT).withSuffix("_slab").build());
|
| 204 | this.registerBlockWithStateMapper(Blocks.monster_egg, (new StateMap.Builder()).withName(BlockSilverfish.VARIANT).withSuffix("_monster_egg").build());
|
| 205 | this.registerBlockWithStateMapper(Blocks.stonebrick, (new StateMap.Builder()).withName(BlockStoneBrick.VARIANT).build());
|
| 206 | this.registerBlockWithStateMapper(Blocks.dispenser, (new StateMap.Builder()).ignore(new IProperty[] {BlockDispenser.TRIGGERED}).build());
|
| 207 | this.registerBlockWithStateMapper(Blocks.dropper, (new StateMap.Builder()).ignore(new IProperty[] {BlockDropper.TRIGGERED}).build());
|
| 208 | this.registerBlockWithStateMapper(Blocks.log, (new StateMap.Builder()).withName(BlockOldLog.VARIANT).withSuffix("_log").build());
|
| 209 | this.registerBlockWithStateMapper(Blocks.log2, (new StateMap.Builder()).withName(BlockNewLog.VARIANT).withSuffix("_log").build());
|
| 210 | this.registerBlockWithStateMapper(Blocks.planks, (new StateMap.Builder()).withName(BlockPlanks.VARIANT).withSuffix("_planks").build());
|
| 211 | this.registerBlockWithStateMapper(Blocks.sapling, (new StateMap.Builder()).withName(BlockSapling.TYPE).withSuffix("_sapling").build());
|
| 212 | this.registerBlockWithStateMapper(Blocks.sand, (new StateMap.Builder()).withName(BlockSand.VARIANT).build());
|
| 213 | this.registerBlockWithStateMapper(Blocks.hopper, (new StateMap.Builder()).ignore(new IProperty[] {BlockHopper.ENABLED}).build());
|
| 214 | this.registerBlockWithStateMapper(Blocks.flower_pot, (new StateMap.Builder()).ignore(new IProperty[] {BlockFlowerPot.LEGACY_DATA}).build());
|
| 215 | this.registerBlockWithStateMapper(Blocks.quartz_block, new StateMapperBase()
|
| 216 | {
|
| 217 | protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
| 218 | {
|
| 219 | BlockQuartz.EnumType blockquartz$enumtype = (BlockQuartz.EnumType)state.getValue(BlockQuartz.VARIANT);
|
| 220 |
|
| 221 | switch (blockquartz$enumtype)
|
| 222 | {
|
| 223 | case DEFAULT:
|
| 224 | default:
|
| 225 | return new ModelResourceLocation("quartz_block", "normal");
|
| 226 |
|
| 227 | case CHISELED:
|
| 228 | return new ModelResourceLocation("chiseled_quartz_block", "normal");
|
| 229 |
|
| 230 | case LINES_Y:
|
| 231 | return new ModelResourceLocation("quartz_column", "axis=y");
|
| 232 |
|
| 233 | case LINES_X:
|
| 234 | return new ModelResourceLocation("quartz_column", "axis=x");
|
| 235 |
|
| 236 | case LINES_Z:
|
| 237 | return new ModelResourceLocation("quartz_column", "axis=z");
|
| 238 | }
|
| 239 | }
|
| 240 | });
|
| 241 | this.registerBlockWithStateMapper(Blocks.deadbush, new StateMapperBase()
|
| 242 | {
|
| 243 | protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
| 244 | {
|
| 245 | return new ModelResourceLocation("dead_bush", "normal");
|
| 246 | }
|
| 247 | });
|
| 248 | this.registerBlockWithStateMapper(Blocks.pumpkin_stem, new StateMapperBase()
|
| 249 | {
|
| 250 | protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
| 251 | {
|
| 252 | Map<IProperty, Comparable> map = Maps.<IProperty, Comparable>newLinkedHashMap(state.getProperties());
|
| 253 |
|
| 254 | if (state.getValue(BlockStem.FACING) != EnumFacing.UP)
|
| 255 | {
|
| 256 | map.remove(BlockStem.AGE);
|
| 257 | }
|
| 258 |
|
| 259 | return new ModelResourceLocation((ResourceLocation)Block.blockRegistry.getNameForObject(state.getBlock()), this.getPropertyString(map));
|
| 260 | }
|
| 261 | });
|
| 262 | this.registerBlockWithStateMapper(Blocks.melon_stem, new StateMapperBase()
|
| 263 | {
|
| 264 | protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
| 265 | {
|
| 266 | Map<IProperty, Comparable> map = Maps.<IProperty, Comparable>newLinkedHashMap(state.getProperties());
|
| 267 |
|
| 268 | if (state.getValue(BlockStem.FACING) != EnumFacing.UP)
|
| 269 | {
|
| 270 | map.remove(BlockStem.AGE);
|
| 271 | }
|
| 272 |
|
| 273 | return new ModelResourceLocation((ResourceLocation)Block.blockRegistry.getNameForObject(state.getBlock()), this.getPropertyString(map));
|
| 274 | }
|
| 275 | });
|
| 276 | this.registerBlockWithStateMapper(Blocks.dirt, new StateMapperBase()
|
| 277 | {
|
| 278 | protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
| 279 | {
|
| 280 | Map<IProperty, Comparable> map = Maps.<IProperty, Comparable>newLinkedHashMap(state.getProperties());
|
| 281 | String s = BlockDirt.VARIANT.getName((BlockDirt.DirtType)map.remove(BlockDirt.VARIANT));
|
| 282 |
|
| 283 | if (BlockDirt.DirtType.PODZOL != state.getValue(BlockDirt.VARIANT))
|
| 284 | {
|
| 285 | map.remove(BlockDirt.SNOWY);
|
| 286 | }
|
| 287 |
|
| 288 | return new ModelResourceLocation(s, this.getPropertyString(map));
|
| 289 | }
|
| 290 | });
|
| 291 | this.registerBlockWithStateMapper(Blocks.double_stone_slab, new StateMapperBase()
|
| 292 | {
|
| 293 | protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
| 294 | {
|
| 295 | Map<IProperty, Comparable> map = Maps.<IProperty, Comparable>newLinkedHashMap(state.getProperties());
|
| 296 | String s = BlockStoneSlab.VARIANT.getName((BlockStoneSlab.EnumType)map.remove(BlockStoneSlab.VARIANT));
|
| 297 | map.remove(BlockStoneSlab.SEAMLESS);
|
| 298 | String s1 = ((Boolean)state.getValue(BlockStoneSlab.SEAMLESS)).booleanValue() ? "all" : "normal";
|
| 299 | return new ModelResourceLocation(s + "_double_slab", s1);
|
| 300 | }
|
| 301 | });
|
| 302 | this.registerBlockWithStateMapper(Blocks.double_stone_slab2, new StateMapperBase()
|
| 303 | {
|
| 304 | protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
| 305 | {
|
| 306 | Map<IProperty, Comparable> map = Maps.<IProperty, Comparable>newLinkedHashMap(state.getProperties());
|
| 307 | String s = BlockStoneSlabNew.VARIANT.getName((BlockStoneSlabNew.EnumType)map.remove(BlockStoneSlabNew.VARIANT));
|
| 308 | map.remove(BlockStoneSlab.SEAMLESS);
|
| 309 | String s1 = ((Boolean)state.getValue(BlockStoneSlabNew.SEAMLESS)).booleanValue() ? "all" : "normal";
|
| 310 | return new ModelResourceLocation(s + "_double_slab", s1);
|
| 311 | }
|
| 312 | });
|
| 313 | }
|
| 314 | }
|
| 315 |
|