12 avr. 2014, 19:32

Ok merci de t’a reponce ! 🙂
J’ai réussie en faire le rendu, tout fonctionne bien sauf quand je veut faire tourné le bloc en fonction de la position du joueur.
Voila tout met classe:

Class du bloc:


package modCrafttech.common;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import modCrafttech.proxy.CraftechClientProxy;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;

public class BlockSculpture extends Block
{
public BlockSculpture(int id)
{
super(id, Material.rock);
}

public TileEntity createTileEntity(World world, int metadata)
{
if(metadata == 0)
return new TileEntitySculpture();
else if(metadata == 2)
return new TileEntityTutorial2();
else
return null;

}

public boolean hasTileEntity(int metadata)
{
if(metadata == 0 || metadata == 2)
return true;
else
return false;
}
public boolean renderAsNormalBlock()
{
return false;
}

public boolean isOpaqueCube()
{
return false;
}

@SideOnly(Side.CLIENT)
public int getRenderType()
{
return CraftechClientProxy.renderInventoryTESRId;
}
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack)
{
int direction = MathHelper.floor_double((double)(living.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
TileEntity te = world.getBlockTileEntity(x, y, z);
if(te != null && stack.getItemDamage() == 2 && te instanceof TileEntityTutorial2)
{
((TileEntityTutorial2)te).setDirection((byte)direction);
world.markBlockForUpdate(x, y, z);
}
}
}

Class Tile Entity:

package modCrafttech.common;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;

public class TileEntitySculpture extends TileEntity
{
public byte direction;

public void readFromNBT(NBTTagCompound nbtTag)
{
super.readFromNBT(nbtTag);
direction = nbtTag.getByte("direction");
}

public void writeToNBT(NBTTagCompound nbtTag)
{
super.writeToNBT(nbtTag);
for(int i = 0; i < 5; i++)
{
nbtTag.setByte("direction", direction);
}
}

public void setDirection(byte direct)
{
direction = direct;
}

public byte getDirection()
{
return direction;
}

public Packet getDescriptionPacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeToNBT(nbttagcompound);
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 4, nbttagcompound);
}

public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
{
this.readFromNBT(pkt.data);
}
}

Class de l’autre Tile Entity:

package modCrafttech.common;

import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.tileentity.TileEntity;

public class TileEntityTutorial2 extends TileEntity
{
public byte direction;

public void readFromNBT(NBTTagCompound nbtTag)
{
super.readFromNBT(nbtTag);
direction = nbtTag.getByte("direction");
}

public void writeToNBT(NBTTagCompound nbtTag)
{
super.writeToNBT(nbtTag);
nbtTag.setByte("direction", direction);
}

public void setDirection(byte direct)
{
direction = direct;
}

public byte getDirection()
{
return direction;
}
public Packet getDescriptionPacket()
{
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeToNBT(nbttagcompound);
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 4, nbttagcompound);
}

public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt)
{
this.readFromNBT(pkt.data);
}
}

Class du Tile entity special render :

package modCraftech.client;

import org.lwjgl.opengl.GL11;

import modCrafttech.common.TileEntitySculpture;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

public class TileEntitySculptureSpecialRender extends TileEntitySpecialRenderer implements IInventoryRenderer {
private final ModelBariquade model = new ModelBariquade();
public static final ResourceLocation textureLocation = new ResourceLocation("craftech", "textures/blocks/Bariquade.png");

public TileEntitySculptureSpecialRender()
{
this.setTileEntityRenderer(TileEntityRenderer.instance);
}

@Override
public void renderInventory(double x, double y, double z)
{
this.renderTileEntitySculptureAt(null, x, y, z, 0.0F);
}

@Override
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float tick)
{
this.renderTileEntitySculptureAt((TileEntitySculpture)te, x, y, z, tick);
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5F, y + 1.5F, z + 0.5F);
this.bindTexture(textureLocation);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
this.model.render(0.0625F);
GL11.glPopMatrix();
}
public void renderTileEntitySculptureAt(TileEntitySculpture te, double x, double y, double z, float tick)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5F, y + 1.5F, z + 0.5F);
this.bindTexture(textureLocation);
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
this.model.render(0.0625F);
if(te != null)
{
GL11.glRotatef(90F * te.getDirection(), 0.0F, 1.0F, 0.0F);
}

GL11.glPopMatrix();
}
}

Merci d’avance pour vos reponces
Cordialement Sidney