Guest User

Untitled

a guest
Nov 25th, 2016
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. package net.trentv.gasesframework.client;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Collection;
  6. import java.util.HashMap;
  7. import java.util.List;
  8.  
  9. import org.lwjgl.util.vector.Vector3f;
  10.  
  11. import com.google.common.base.Function;
  12.  
  13. import net.minecraft.client.renderer.block.model.BakedQuad;
  14. import net.minecraft.client.renderer.block.model.BlockFaceUV;
  15. import net.minecraft.client.renderer.block.model.BlockPartFace;
  16. import net.minecraft.client.renderer.block.model.FaceBakery;
  17. import net.minecraft.client.renderer.block.model.IBakedModel;
  18. import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
  19. import net.minecraft.client.renderer.block.model.ItemOverrideList;
  20. import net.minecraft.client.renderer.block.model.ModelRotation;
  21. import net.minecraft.client.renderer.block.model.SimpleBakedModel;
  22. import net.minecraft.client.renderer.texture.TextureAtlasSprite;
  23. import net.minecraft.client.renderer.vertex.VertexFormat;
  24. import net.minecraft.util.EnumFacing;
  25. import net.minecraft.util.ResourceLocation;
  26. import net.minecraftforge.client.model.IModel;
  27. import net.minecraftforge.common.model.IModelState;
  28. import net.trentv.gasesframework.GasesFramework;
  29.  
  30. public class ModelBlockGas implements IModel
  31. {
  32. private FaceBakery bakery = new FaceBakery();
  33. private ResourceLocation texture = new ResourceLocation(GasesFramework.MODID, "block/gas_default");
  34.  
  35. @Override
  36. public Collection<ResourceLocation> getDependencies()
  37. {
  38. return new ArrayList<ResourceLocation>();
  39. }
  40.  
  41. @Override
  42. public Collection<ResourceLocation> getTextures()
  43. {
  44. ArrayList<ResourceLocation> a = new ArrayList<ResourceLocation>();
  45. a.add(texture);
  46. return a;
  47. }
  48.  
  49. @Override
  50. public IBakedModel bake(IModelState state, VertexFormat format, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
  51. {
  52. //facings in D-U-N-S-W-E order
  53. List<BakedQuad> allQuads = Arrays.asList(
  54. getQuad(new Vector3f(0,0,0), new Vector3f(16,0 ,16), EnumFacing.DOWN, bakedTextureGetter), //DOWN
  55. getQuad(new Vector3f(0,0,0), new Vector3f(16,16,16), EnumFacing.UP, bakedTextureGetter), //UP
  56. getQuad(new Vector3f(0,0,0), new Vector3f(16,16,16), EnumFacing.NORTH, bakedTextureGetter), //NORTH
  57. getQuad(new Vector3f(0,0,0), new Vector3f(16,16,16), EnumFacing.SOUTH, bakedTextureGetter), //SOUTH
  58. getQuad(new Vector3f(0,0,0), new Vector3f(16,16,16), EnumFacing.WEST, bakedTextureGetter), //WEST
  59. getQuad(new Vector3f(0,0,0), new Vector3f(16,16,16), EnumFacing.EAST, bakedTextureGetter) //EAST
  60. );
  61. HashMap<EnumFacing, List<BakedQuad>> faceQuads = new HashMap<EnumFacing, List<BakedQuad>>();
  62. for(int i = 0; i < EnumFacing.values().length; i++)
  63. {
  64. faceQuads.put(EnumFacing.VALUES[i], Arrays.asList(allQuads.get(i)));
  65. }
  66. SimpleBakedModel newModel = new SimpleBakedModel(allQuads, faceQuads, true, true, bakedTextureGetter.apply(texture), ItemCameraTransforms.DEFAULT, ItemOverrideList.NONE);
  67. return newModel;
  68. }
  69.  
  70. private BakedQuad getQuad(Vector3f from, Vector3f to, EnumFacing direction, Function<ResourceLocation, TextureAtlasSprite> bakedTextureGetter)
  71. {
  72. return bakery.makeBakedQuad(from, to, new BlockPartFace(null, 0, texture.toString(), new BlockFaceUV(new float[]{0,0,16,16}, 0)),
  73. bakedTextureGetter.apply(texture), direction, ModelRotation.X0_Y0, null, true, true);
  74. }
  75.  
  76. @Override
  77. public IModelState getDefaultState()
  78. {
  79. return null;
  80. }
  81. }
  82.  
  83.  
  84.  
  85.  
  86. package net.trentv.gasesframework.client;
  87.  
  88. import java.util.Arrays;
  89. import java.util.List;
  90.  
  91. import net.minecraft.client.resources.IResourceManager;
  92. import net.minecraft.util.ResourceLocation;
  93. import net.minecraftforge.client.model.ICustomModelLoader;
  94. import net.minecraftforge.client.model.IModel;
  95. import net.trentv.gasesframework.GasesFramework;
  96.  
  97. public class IGasesModelLoader implements ICustomModelLoader
  98. {
  99.  
  100. @Override
  101. public void onResourceManagerReload(IResourceManager resourceManager)
  102. {
  103.  
  104. }
  105.  
  106. @Override
  107. public boolean accepts(ResourceLocation modelLocation)
  108. {
  109. List<String> path = Arrays.asList("gas_smoke");
  110. if(modelLocation.getResourceDomain().equals(GasesFramework.MODID))
  111. {
  112. if(path.contains(modelLocation.getResourcePath()))
  113. {
  114. return true;
  115. }
  116. }
  117. return false;
  118. }
  119.  
  120. @Override
  121. public IModel loadModel(ResourceLocation modelLocation) throws Exception
  122. {
  123. if(modelLocation.getResourceDomain().equals(GasesFramework.MODID))
  124. {
  125. if(modelLocation.getResourcePath().contains("gas_"))
  126. {
  127. return new ModelBlockGas();
  128. }
  129. }
  130. return null;
  131. }
  132. }
  133.  
  134.  
  135.  
  136.  
  137.  
  138. In your registerRenderers clientproxy:
  139. ModelLoaderRegistry.registerLoader(new IGasesModelLoader());
Advertisement
Add Comment
Please, Sign In to add comment