Skip to content
Permalink
Browse files

Ajout d'un rendu TileEntitySpecialRenderer avec un modèle techne

  • Loading branch information
robin4002 committed Oct 26, 2014
1 parent 8932e25 commit 565a278a26b1e0178fc2db90f9a0a06b8a955806
@@ -0,0 +1,95 @@
package fr.minecraftforgefrance.tutoriel.client;

import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;

public class ModelBlockTutoriel extends ModelBase
{
ModelRenderer bottomPlate;
ModelRenderer topPlate;
ModelRenderer rightPlate;
ModelRenderer leftPlate;
ModelRenderer backPlate;
ModelRenderer doorLeft;
ModelRenderer doorRight;
ModelRenderer leftHandle;
ModelRenderer rightHandle;

public ModelBlockTutoriel()
{
textureWidth = 64;
textureHeight = 64;

bottomPlate = new ModelRenderer(this, 0, 0);
bottomPlate.addBox(0F, 0F, 0F, 14, 1, 14);
bottomPlate.setRotationPoint(-7F, 23F, -7F);
bottomPlate.setTextureSize(64, 64);
setRotation(bottomPlate, 0F, 0F, 0F);
topPlate = new ModelRenderer(this, 0, 0);
topPlate.mirror = true;
topPlate.addBox(0F, 0F, 0F, 14, 1, 14);
topPlate.setRotationPoint(-7F, 10F, -7F);
topPlate.setTextureSize(64, 64);
setRotation(topPlate, 0F, 0F, 0F);
rightPlate = new ModelRenderer(this, 0, 16);
rightPlate.addBox(0F, 0F, 0F, 1, 12, 13);
rightPlate.setRotationPoint(-7F, 11F, -7F);
rightPlate.setTextureSize(64, 64);
setRotation(rightPlate, 0F, 0F, 0F);
leftPlate = new ModelRenderer(this, 0, 16);
leftPlate.mirror = true;
leftPlate.addBox(0F, 0F, 0F, 1, 12, 13);
leftPlate.setRotationPoint(6F, 11F, -7F);
leftPlate.setTextureSize(64, 64);
setRotation(leftPlate, 0F, 0F, 0F);
backPlate = new ModelRenderer(this, 29, 16);
backPlate.mirror = true;
backPlate.addBox(0F, 0F, 0F, 14, 12, 1);
backPlate.setRotationPoint(-7F, 11F, 6F);
backPlate.setTextureSize(64, 64);
setRotation(backPlate, 0F, 0F, 0F);
doorLeft = new ModelRenderer(this, 29, 30);
doorLeft.mirror = true;
doorLeft.addBox(-6F, -6F, 0F, 6, 12, 1);
doorLeft.setRotationPoint(6F, 17F, -6.8F);
doorLeft.setTextureSize(64, 64);
setRotation(doorLeft, 0F, 0F, 0F);
doorRight = new ModelRenderer(this, 29, 30);
doorRight.addBox(0F, -6F, 0F, 6, 12, 1);
doorRight.setRotationPoint(-6F, 17F, -6.8F);
doorRight.setTextureSize(64, 64);
setRotation(doorRight, 0F, 0F, 0F);
leftHandle = new ModelRenderer(this, 0, 44);
leftHandle.mirror = true;
leftHandle.addBox(-5F, -1.5F, -1F, 1, 3, 1);
leftHandle.setRotationPoint(6F, 17F, -6.8F);
leftHandle.setTextureSize(64, 64);
setRotation(leftHandle, 0F, 0F, 0F);
rightHandle = new ModelRenderer(this, 0, 44);
rightHandle.addBox(4F, -1.5F, -1F, 1, 3, 1);
rightHandle.setRotationPoint(-6F, 17F, -6.8F);
rightHandle.setTextureSize(64, 64);
setRotation(rightHandle, 0F, 0F, 0F);
}

public void renderAll()
{
bottomPlate.render(0.0625F);
topPlate.render(0.0625F);
rightPlate.render(0.0625F);
leftPlate.render(0.0625F);
backPlate.render(0.0625F);
doorLeft.render(0.0625F);
doorRight.render(0.0625F);
leftHandle.render(0.0625F);
rightHandle.render(0.0625F);
}

private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}
@@ -0,0 +1,48 @@
package fr.minecraftforgefrance.tutoriel.client;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import fr.minecraftforgefrance.tutoriel.common.ModTutoriel;
import fr.minecraftforgefrance.tutoriel.proxy.ClientProxy;

public class TESRInventoryRenderer implements ISimpleBlockRenderingHandler
{
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer)
{
if(block == ModTutoriel.blockTutoriel2 && metadata == 0)
{
GL11.glPushMatrix();
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(0.0F, -1.0F, 0.0F);
GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(TileEntityTutorielSpecialRenderer.texture);
TileEntityTutorielSpecialRenderer.model.renderAll();
GL11.glPopMatrix();
}
}

@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
{
return false;
}

@Override
public boolean shouldRender3DInInventory(int modelId)
{
return true;
}

@Override
public int getRenderId()
{
return ClientProxy.tesrRenderId;
}
}
@@ -0,0 +1,38 @@
package fr.minecraftforgefrance.tutoriel.client;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import fr.minecraftforgefrance.tutoriel.common.ModTutoriel;
import fr.minecraftforgefrance.tutoriel.common.TileEntityTutoriel;

public class TileEntityTutorielSpecialRenderer extends TileEntitySpecialRenderer
{
public static ModelBlockTutoriel model = new ModelBlockTutoriel();
public static ResourceLocation texture = new ResourceLocation(ModTutoriel.MODID, "textures/models/blocks/model_block_tutoriel.png");

public TileEntityTutorielSpecialRenderer()
{
this.func_147497_a(TileEntityRendererDispatcher.instance);
}

@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialRenderTick)
{
this.renderTileEntityTutorielAt((TileEntityTutoriel)tile, x, y, z, partialRenderTick);
}

private void renderTileEntityTutorielAt(TileEntityTutoriel tile, double x, double y, double z, float partialRenderTick)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5D, y + 1.5D, z + 0.5D);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef((90F * tile.getDirection()) + 180F, 0.0F, 1.0F, 0.0F);
this.bindTexture(texture);
model.renderAll();
GL11.glPopMatrix();
}
}
@@ -1,18 +1,27 @@
package fr.minecraftforgefrance.tutoriel.common;

import fr.minecraftforgefrance.tutoriel.proxy.ClientProxy;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class BlockTutoriel2 extends Block
{
protected BlockTutoriel2(Material material)
{
super(material);
}

public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
{
this.setBlockBounds(0.06F, 0.0F, 0.06F, 0.94F, 0.88F, 0.94F);
}

@Override
public boolean hasTileEntity(int metadata)
@@ -25,27 +34,59 @@ public TileEntity createTileEntity(World world, int metadata)
{
return new TileEntityTutoriel();
}

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)

public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
{
if(stack.getItemDamage() == 0)
{
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityTutoriel)
{
int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
((TileEntityTutoriel)tile).setDirection((byte)direction);
}
}
}

@Override
public boolean rotateBlock(World world, int x, int y, int z, ForgeDirection axis)
{
if(!world.isRemote)
if((axis == ForgeDirection.UP || axis == ForgeDirection.DOWN) && !world.isRemote && world.getBlockMetadata(x, y, z) == 0)
{
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileEntityTutoriel)
{
TileEntityTutoriel tileTuto = (TileEntityTutoriel)tile;
if(side == 0)
{
tileTuto.decrease();
}
else if(side == 1)
byte direction = tileTuto.getDirection();
direction++;
if(direction > 3)
{
tileTuto.increase();
direction = 0;
}
player.addChatMessage(new ChatComponentTranslation("tile.tutoriel2.number", tileTuto.getNumber()));
tileTuto.setDirection(direction);
return true;
}
}
return false;
}

public ForgeDirection[] getValidRotations(World world, int x, int y, int z)
{
return world.getBlockMetadata(x, y, z) == 0 ? new ForgeDirection[] {ForgeDirection.UP, ForgeDirection.DOWN} : ForgeDirection.VALID_DIRECTIONS;
}

public boolean isOpaqueCube()
{
return false;
}

public boolean renderAsNormalBlock()
{
return false;
}

public int getRenderType()
{
return ClientProxy.tesrRenderId;
}
}
@@ -1,38 +1,50 @@
package fr.minecraftforgefrance.tutoriel.common;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileEntityTutoriel extends TileEntity
{
private int number;
private byte direction;

@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.number = compound.getInteger("Number");
this.direction = compound.getByte("Direction");
}

@Override
public void writeToNBT(NBTTagCompound compound)
{
super.writeToNBT(compound);
compound.setInteger("Number", this.number);
compound.setByte("Direction", this.direction);
}

public void increase()
public byte getDirection()
{
this.number++;
return direction;
}

public void decrease()
public void setDirection(byte direction)
{
this.number--;
this.direction = direction;
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
}

public int getNumber()
public Packet getDescriptionPacket()
{
return number;
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeToNBT(nbttagcompound);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, nbttagcompound);
}

public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt)
{
this.readFromNBT(pkt.func_148857_g());
this.worldObj.markBlockRangeForRenderUpdate(this.xCoord, this.yCoord, this.zCoord, this.xCoord, this.yCoord, this.zCoord);
}
}
@@ -1,16 +1,27 @@
package fr.minecraftforgefrance.tutoriel.proxy;

import net.minecraft.client.model.ModelBiped;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import fr.minecraftforgefrance.tutoriel.client.RenderMobTutoriel;
import fr.minecraftforgefrance.tutoriel.client.TESRInventoryRenderer;
import fr.minecraftforgefrance.tutoriel.client.TileEntityTutorielSpecialRenderer;
import fr.minecraftforgefrance.tutoriel.common.EntityMobTutoriel;
import fr.minecraftforgefrance.tutoriel.common.TileEntityTutoriel;

public class ClientProxy extends CommonProxy
{
public static int tesrRenderId;
@Override
public void registerRender()
{
System.out.println("méthode côté client");
RenderingRegistry.registerEntityRenderingHandler(EntityMobTutoriel.class, new RenderMobTutoriel(new ModelBiped(), 0.5F));

tesrRenderId = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new TESRInventoryRenderer());


ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTutoriel.class, new TileEntityTutorielSpecialRenderer());
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 565a278

Please sign in to comment.
You can’t perform that action at this time.