Advertisement
Guest User

blockTente

a guest
Aug 13th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.21 KB | None | 0 0
  1.  
  2.  
  3. /**La déclaration dans mon ModID.java */
  4.  
  5. public static int rt1 = 0; // Le render
  6. public static final Block tenteVerte = new tb1(2022).setUnlocalizedName("tenteVerte"); // La déclaration
  7.  
  8. //-----------------------------------------------------------------------------------------
  9.  
  10. /**La classe tb1 (abréviation personnelle, j'aime crypter mes sources moi-même comme je peux :D*/
  11.  
  12. package ageOfDoom.common;
  13.  
  14. import java.util.Iterator;
  15.  
  16. import net.minecraft.block.Block;
  17.  
  18. import net.minecraft.block.BlockContainer;
  19. import net.minecraft.block.material.Material;
  20. import net.minecraft.creativetab.CreativeTabs;
  21. import net.minecraft.entity.Entity;
  22. import net.minecraft.entity.player.EntityPlayer;
  23. import net.minecraft.entity.player.EnumStatus;
  24. import net.minecraft.tileentity.TileEntity;
  25. import net.minecraft.util.ChunkCoordinates;
  26. import net.minecraft.world.World;
  27. import net.minecraft.world.biome.BiomeGenBase;
  28.  
  29.  
  30. public final class tb1 extends BlockContainer{ // The rendered block needs to extend BlockContainer
  31.  
  32.  
  33. public static final int[][] footBlockToHeadBlockMap = new int[][] {{0, 1}, { -1, 0}, {0, -1}, {1, 0}};
  34. public tb1(int id)
  35. {
  36.  
  37. // Most of this is standard block stuffs
  38. super(id, Material.wood);
  39. this.setHardness(1.0F);
  40. this.setStepSound(this.soundWoodFootstep);
  41. this.setCreativeTab(CreativeTabs.tabBlock);
  42. this.setUnlocalizedName("tenteVerte");
  43. this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.0625F, 1.0F);
  44. }
  45.  
  46. public static boolean isBlockHeadOfBed(int par0)
  47. {
  48. return (par0 & 8) != 0;
  49. }
  50.  
  51. /**
  52. * Return whether or not the bed is occupied.
  53. */
  54. public static boolean isBedOccupied(int par0)
  55. {
  56. return (par0 & 4) != 0;
  57. }
  58. public static int getDirection(int par0)
  59. {
  60. return par0 & 3;
  61. }
  62. @Override
  63. public TileEntity createNewTileEntity(World world){
  64. return new ttb1(); // This is a method required by BlockContainer, it just returns a new instance of the tile
  65. }
  66. @Override
  67. public boolean renderAsNormalBlock(){
  68. return false; // You need this for this to render properly, return false as it will probably not be a block
  69. }
  70. @Override
  71. public boolean isOpaqueCube(){
  72. return false; // This is also required for it to render properly
  73. }
  74. @Override
  75. public int getRenderType(){
  76. return ModAOD.rt1; // You return the integer in the SimpleMod class that you defined as the render ID
  77. }
  78. @Override
  79. public int getRenderBlockPass(){
  80. return 1; // Always return 1 it is needed as well for correct rendering
  81. }
  82. }
  83.  
  84. //---------------------------------------------------------------------
  85.  
  86. /** La classe ttb1 (la TileEntity en gros)*/
  87. package ageOfDoom.common;
  88.  
  89. import net.minecraft.tileentity.TileEntity;
  90.  
  91. public final class ttb1 extends TileEntity{
  92. // Nothing special will go in here just yet
  93. }
  94. //---------------------------------------------------------------------
  95.  
  96. /**Voici ce que j'ai mis dans mon ClientProxy*/
  97.  
  98. public static int renderTenteID;
  99.  
  100. @Override
  101. public void initRender()
  102. {
  103.  
  104. ModAOD.rt1 = RenderingRegistry.getNextAvailableRenderId(); // Set the value of the render ID
  105. MinecraftForgeClient.registerItemRenderer(ModAOD.tenteVerte.blockID, new ibtr()); // Bind the Item renderer to the itemID
  106. ClientRegistry.bindTileEntitySpecialRenderer(ttb1.class, new tesrb1()); // Bind the TESR to the tile clas
  107. GameRegistry.registerTileEntity(ttb1.class, "ttb1"); // register the tile class
  108.  
  109. }
  110.  
  111. //-----------------------------------------------------------------
  112. /**Alors ici c'est le... TESR (?) j'ai pas trop suivi ce à quoi ça correspondait, c'était des codes anglais sans tutoriel expliqué ^^*/
  113.  
  114. package ageOfDoom.common;
  115.  
  116. import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
  117. import net.minecraft.tileentity.TileEntity;
  118.  
  119. import org.lwjgl.opengl.GL11;
  120.  
  121. import ageOfDoom.blocks.render.model.ModelTent;
  122.  
  123.  
  124. import cpw.mods.fml.client.FMLClientHandler;
  125.  
  126. public final class tesrb1 extends TileEntitySpecialRenderer{ // You need to extend TileEntitySpecial Renderer for this to work
  127. private final ModelTent model; // Keep an instance of the model
  128. public tesrb1(){
  129. this.model = new ModelTent(); // Instantate the instance of the model in the constructor
  130. }
  131. public void renderAModelAt(tesrb1 tileentity1, double d, double d1, double d2, float f)
  132. {
  133. GL11.glPushMatrix();
  134. GL11.glTranslatef((float)d + 0.5F, (float)d1 + 0.5F, (float)d2 + 0.5F);
  135. bindTextureByName("Ageofdoom:tenteVerte");
  136. GL11.glPushMatrix();
  137. GL11.glPopMatrix();
  138. GL11.glPopMatrix();
  139. }
  140.  
  141. @Override
  142. public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float scale){
  143. FMLClientHandler.instance().getClient();/*.func_110577_a(new ResourceLocation("AgeofDoom:tenteVerte.png"));*/ // This will bind the texture of the barrel, please follow a ResourceLocation tutorial on what to do with the resources
  144. GL11.glPushMatrix(); // Always call GL11.glPushMatrix() first, it will submit the matrix that is modified back into position
  145. GL11.glDisable(GL11.GL_LIGHTING); // You don't need this but it is recomended, try commenting this out and see what it does for you. It just enables a lighter feel for the texture
  146. GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); // This will translate the block to the specific coordinate so it can render right, you always wanna adjust by 0.5F, 1.5F, 0.5F
  147. GL11.glScalef(1.0F, -1.0F, -1.0F); // This is the scale of the block, normally it will be 1.0F, -1.0F, -1.0F
  148. GL11.glRotatef(0.0F, 0.0F, 0.0F, 0.0F); // This can be ignored if you want to just have it as is, but this will allow you to rotate the block, more on this will come in the tile tutorial
  149. bindTextureByName("/mods/ageofdoom/textures/blocks/tenteVerte.png");
  150. model.render(); // Call the model render function
  151. GL11.glEnable(GL11.GL_LIGHTING); // Remember to enable it Lighting here if you disabled it above
  152. GL11.glPopMatrix(); // Always call GL11.glPopMatrix() last because it will pop the matrix out for modification
  153. }
  154. }
  155.  
  156. //---------------------------------------------------------------------------------
  157. /**Et pour finir le rendu dans l'inventaire!*/
  158.  
  159. package ageOfDoom.common;
  160.  
  161. import net.minecraft.block.Block;
  162. import net.minecraft.item.ItemStack;
  163. import net.minecraftforge.client.IItemRenderer;
  164.  
  165. import org.lwjgl.opengl.GL11;
  166.  
  167. import ageOfDoom.blocks.render.model.ModelTent;
  168.  
  169.  
  170. import cpw.mods.fml.client.FMLClientHandler;
  171.  
  172. public final class ibtr implements IItemRenderer{ // This class needs to implement IItemRenderer
  173. private final ModelTent model; // Instance of teh ModelBarrel
  174. public ibtr(){
  175. this.model = new ModelTent(); // Populate the instance in the constructor
  176. }
  177. @Override
  178. public boolean handleRenderType(ItemStack item, ItemRenderType type){
  179. return true; // Always return true
  180. }
  181.  
  182. @Override
  183. public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper){
  184. return true; // Always return true
  185. }
  186.  
  187.  
  188. @Override
  189. public void renderItem(ItemRenderType type, ItemStack item, Object... data) { // You probably wanna switch the type so you can determine the seperate renders for Entity, Inventory, Equipped
  190. switch(type)
  191. {
  192. case ENTITY:
  193. renderTente(0.5F, -0.5F, 0.5F, 1.0F);
  194. break; // Remember to break or return out of a switch block or it will call all up till a new break / return
  195. case EQUIPPED:
  196. renderTente(0.5F, -0.5F, 0.5F, 1.0F);
  197. break;
  198. case INVENTORY:
  199. renderTente(0.5F, -0.5F, 0.5F, 1.0F);
  200. break;
  201. default: // Don't forget a default case
  202. break;
  203. }
  204. }
  205. // All the code follows the same suit as the TESRBlockBarrel class did except for the binding of the texture is farther in the stack
  206. private void renderTente(float x, float y, float z, float scale){
  207. GL11.glPushMatrix();
  208. GL11.glDisable(GL11.GL_LIGHTING);
  209. GL11.glScalef(scale, scale, scale);
  210. GL11.glTranslatef(x, y, z);
  211. GL11.glRotatef(0.0F, 0.0F, 0.0F, 0.0F);
  212. //FMLClientHandler.instance().getClient().renderEngine.func_110577_a(new ResourceLocation("Ageofdoom:tenteVerte.png"));
  213. model.render();
  214. GL11.glEnable(GL11.GL_LIGHTING);
  215. GL11.glPopMatrix();
  216. }
  217. }
  218.  
  219.  
  220. /**Pour finir voici mon Model*/
  221.  
  222. package ageOfDoom.blocks.render.model;
  223.  
  224. import net.minecraft.client.model.ModelBase;
  225. import net.minecraft.client.model.ModelRenderer;
  226. import net.minecraft.entity.Entity;
  227.  
  228. public class ModelTent extends ModelBase
  229. {
  230. //fields
  231. ModelRenderer Shape1;
  232. ModelRenderer Shape2;
  233. ModelRenderer Shape31;
  234. ModelRenderer Shape3;
  235. ModelRenderer Shape4;
  236. ModelRenderer Shape5;
  237. ModelRenderer Shape6;
  238. ModelRenderer Shape7;
  239. ModelRenderer Shape8;
  240. ModelRenderer Shape9;
  241. ModelRenderer Shape10;
  242.  
  243. public ModelTent()
  244. {
  245. textureWidth = 256;
  246. textureHeight = 128;
  247.  
  248. Shape1 = new ModelRenderer(this, 0, 0);
  249. Shape1.addBox(0F, 0F, 0F, 17, 1, 48);
  250. Shape1.setRotationPoint(-32F, 23F, -24F);
  251. Shape1.setTextureSize(256, 128);
  252.  
  253. setRotation(Shape1, 0F, 0F, -0.7064006F);
  254. Shape2 = new ModelRenderer(this, 0, 0);
  255. Shape2.addBox(0F, 0F, 0F, 17, 1, 48);
  256. Shape2.setRotationPoint(20.5F, 13F, -24F);
  257. Shape2.setTextureSize(256, 128);
  258.  
  259. setRotation(Shape2, 0F, 0F, 0.7064046F);
  260. Shape31 = new ModelRenderer(this, 0, 49);
  261. Shape31.addBox(0F, 0F, 0F, 17, 1, 48);
  262. Shape31.setRotationPoint(11F, 1.5F, -24F);
  263. Shape31.setTextureSize(256, 128);
  264.  
  265. setRotation(Shape31, 0F, 0F, 0.8552113F);
  266. Shape3 = new ModelRenderer(this, 0, 49);
  267. Shape3.addBox(0F, 0F, 0F, 17, 1, 48);
  268. Shape3.setRotationPoint(-21.5F, 14.5F, -24F);
  269. Shape3.setTextureSize(256, 128);
  270. setRotation(Shape3, 0F, 0F, -0.8552113F);
  271.  
  272. Shape4 = new ModelRenderer(this, 0, 49);
  273. Shape4.addBox(0F, 0F, 0F, 17, 1, 48);
  274. Shape4.setRotationPoint(-11F, 2.5F, -24F);
  275. Shape4.setTextureSize(256, 128);
  276. setRotation(Shape4, 0F, 0F, -0.837758F);
  277.  
  278. Shape5 = new ModelRenderer(this, 0, 49);
  279. Shape5.addBox(0F, 0F, 0F, 17, 1, 48);
  280. Shape5.setRotationPoint(0.5F, -10.5F, -24F);
  281. Shape5.setTextureSize(256, 128);
  282. setRotation(Shape5, 0F, 0F, 0.8518859F);
  283.  
  284. Shape6 = new ModelRenderer(this, 130, 0);
  285. Shape6.addBox(0F, 0F, 0F, 2, 10, 2);
  286. Shape6.setRotationPoint(-30.73333F, 16F, -23F);
  287. Shape6.setTextureSize(256, 128);
  288. setRotation(Shape6, 0F, 0F, 0F);
  289.  
  290. Shape7 = new ModelRenderer(this, 130, 0);
  291. Shape7.addBox(0F, 0F, 0F, 2, 10, 2);
  292. Shape7.setRotationPoint(30.46667F, 16F, -23F);
  293. Shape7.setTextureSize(256, 128);
  294. setRotation(Shape7, 0F, 0F, 0F);
  295.  
  296. Shape8 = new ModelRenderer(this, 130, 0);
  297. Shape8.addBox(0F, 0F, 0F, 2, 10, 2);
  298. Shape8.setRotationPoint(-30.7F, 16F, 21F);
  299. Shape8.setTextureSize(256, 128);
  300. setRotation(Shape8, 0F, 0F, 0F);
  301.  
  302. Shape9 = new ModelRenderer(this, 130, 0);
  303. Shape9.addBox(0F, 0F, 0F, 2, 10, 2);
  304. Shape9.setRotationPoint(30F, 16F, 21F);
  305. Shape9.setTextureSize(256, 128);
  306. setRotation(Shape9, 0F, 0F, 0F);
  307.  
  308. Shape10 = new ModelRenderer(this, 130, 12);
  309. Shape10.addBox(0F, 0F, 0F, 16, 3, 32);
  310. Shape10.setRotationPoint(-8F, 21F, -16F);
  311. Shape10.setTextureSize(256, 128);
  312. setRotation(Shape10, 0F, 0F, 0F);
  313. }
  314.  
  315. public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
  316. {
  317. super.render(entity, f, f1, f2, f3, f4, f5);
  318. setRotationAngles(f, f1, f2, f3, f4, f5);
  319. Shape1.render(f5);
  320. Shape2.render(f5);
  321. Shape31.render(f5);
  322. Shape3.render(f5);
  323. Shape4.render(f5);
  324. Shape5.render(f5);
  325. Shape6.render(f5);
  326. Shape7.render(f5);
  327. Shape8.render(f5);
  328. Shape9.render(f5);
  329. Shape10.render(f5);
  330. }
  331.  
  332. public void render()
  333. {
  334. float f5 = 0.0625F;
  335. Shape1.render(f5);
  336. Shape2.render(f5);
  337. Shape31.render(f5);
  338. Shape3.render(f5);
  339. Shape4.render(f5);
  340. Shape5.render(f5);
  341. Shape6.render(f5);
  342. Shape7.render(f5);
  343. Shape8.render(f5);
  344. Shape9.render(f5);
  345. Shape10.render(f5);
  346. }
  347.  
  348. private void setRotation(ModelRenderer model, float x, float y, float z)
  349. {
  350. model.rotateAngleX = x;
  351. model.rotateAngleY = y;
  352. model.rotateAngleZ = z;
  353. }
  354.  
  355. public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5)
  356. {
  357. super.setRotationAngles(f, f1, f2, f3, f4, f5, null);
  358. }
  359.  
  360. }
  361.  
  362. // Voilà, désolé, c'était très mal rangé \:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement