Salut.
Tout fonctionne à peu près cependant je rencontre un problème.
Mon bloc tourne comme je le souhaitais dans la direction voulue mais lorsque je quitte et reviens sur ma partie solo, tous les blocs sont orientés dans le même sens. Et aussi le rendu dans l’inventaire m’affiche une case plate rose et noire. (Dernier problème réglé, j’avais oublié de modifier le return -1)
Classe Principale:
package fr.eterlia.mod.common;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import fr.eterlia.mod.proxy.CommonProxy;
@Mod(modid = "modeterlia", name = "Eterlia", version = "2.0.0")
public class ModEterlia {
@Instance("modeterlia")
public static ModEterlia instance;
public static final String eterlia = "modeterlia";
@SidedProxy(clientSide = "fr.eterlia.mod.proxy.ClientProxy", serverSide = "fr.eterlia.mod.proxy.CommonProxy")
public static CommonProxy proxy;
public static Block beton;
public static Block lanterne;
public static Block terre;
public static Block chaise;
public static Block table;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
}
@EventHandler
public void init(FMLInitializationEvent event)
{
proxy.registerRender();
beton = new BlockEterlia(Material.rock).setBlockName("beton").setBlockTextureName("modeterlia:beton").setResistance(5.0F).setHardness(3.0F).setCreativeTab(CreativeTabs.tabBlock);
lanterne = new BlockEterlia(Material.glass).setLightLevel(4.0F).setBlockName("lanterne").setBlockTextureName("modeterlia:lanterne").setResistance(5.0F).setHardness(3.0F).setCreativeTab(CreativeTabs.tabBlock);
terre = new BlockEterlia(Material.ground).setBlockName("terre").setBlockTextureName("modeterlia:terre").setResistance(5.0F).setHardness(3.0F).setCreativeTab(CreativeTabs.tabBlock);
chaise = new BlockEterliaChaise(Material.wood).setBlockName("chaise").setBlockTextureName("modeterlia:chaise").setResistance(5.0F).setHardness(3.0F).setCreativeTab(CreativeTabs.tabBlock);
table = new BlockEterliaTable(Material.wood).setBlockName("table").setBlockTextureName("modeterlia:wood").setResistance(5.0F).setHardness(3.0F).setCreativeTab(CreativeTabs.tabBlock);
GameRegistry.registerBlock(beton, "beton");
GameRegistry.registerBlock(lanterne, "lanterne");
GameRegistry.registerBlock(terre, "terre");
GameRegistry.registerBlock(chaise, "chaise");
GameRegistry.registerBlock(table, "table");
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
}
}
Mon bloc:
| |
| package fr.eterlia.mod.common; |
| |
| 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.IBlockAccess; |
| import net.minecraft.world.World; |
| import cpw.mods.fml.relauncher.Side; |
| import cpw.mods.fml.relauncher.SideOnly; |
| import fr.eterlia.mod.proxy.ClientProxy; |
| |
| public class BlockEterliaChaise extends Block { |
| public BlockEterliaChaise(Material rock) { |
| super(Material.iron); |
| } |
| |
| public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, |
| int z) { |
| this.setBlockBounds(0.2F, 0.0F, 0.2F, 0.8F, 1.0F, 0.8F); |
| } |
| |
| public TileEntity createTileEntity(World world, int metadata) { |
| return new TileEntityChaise(); |
| } |
| |
| public boolean hasTileEntity(int metadata) { |
| return true; |
| } |
| |
| public boolean renderAsNormalBlock() { |
| return false; |
| } |
| |
| public boolean isOpaqueCube() { |
| return false; |
| } |
| |
| @SideOnly(Side.CLIENT) |
| public int getRenderType() { |
| return ClientProxy.tesrRenderId; |
| } |
| |
| |
| |
| |
| 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.getTileEntity(x, y, z); |
| if (te != null && te instanceof TileEntityChaise) { |
| ((TileEntityChaise) te).setDirection((byte) direction); |
| world.markBlockForUpdate(x, y, z); |
| } |
| } |
| } |
Client proxy:
| package fr.eterlia.mod.proxy; |
| |
| import cpw.mods.fml.client.registry.ClientRegistry; |
| import cpw.mods.fml.client.registry.RenderingRegistry; |
| import fr.eterlia.mod.common.TileEntityChaiseSpecialRenderer; |
| import fr.eterlia.mod.common.TileEntityChaise; |
| import fr.eterlia.mod.common.TileEntityTable; |
| import fr.eterlia.mod.common.TileEntityTableSpecialRenderer; |
| |
| public class ClientProxy extends CommonProxy { |
| |
| public static int tesrRenderId; |
| @Override |
| public void registerRender() |
| { |
| System.out.println("méthode côté client"); |
| ClientRegistry.bindTileEntitySpecialRenderer(TileEntityChaise.class, new TileEntityChaiseSpecialRenderer()); |
| ClientRegistry.bindTileEntitySpecialRenderer(TileEntityTable.class, new TileEntityTableSpecialRenderer()); |
| |
| tesrRenderId = RenderingRegistry.getNextAvailableRenderId(); |
| RenderingRegistry.registerBlockHandler(new TESRInventoryRenderer()); |
| |
| } |
| |
| } |
| |
Mon modèle:
| |
| |
| |
| |
| |
| |
| package fr.eterlia.mod.common; |
| |
| import net.minecraft.client.model.ModelBase; |
| import net.minecraft.client.model.ModelRenderer; |
| |
| public class ModelChaise extends ModelBase |
| { |
| |
| ModelRenderer pied1; |
| ModelRenderer pied2; |
| ModelRenderer pied3; |
| ModelRenderer pied4; |
| ModelRenderer plateau; |
| ModelRenderer dossier; |
| |
| public ModelChaise() |
| { |
| textureWidth = 64; |
| textureHeight = 32; |
| |
| pied1 = new ModelRenderer(this, 0, 0); |
| pied1.addBox(0F, 0F, 0F, 1, 8, 1); |
| pied1.setRotationPoint(-5F, 16F, -5F); |
| pied1.setTextureSize(64, 32); |
| pied1.mirror = true; |
| setRotation(pied1, 0F, 0F, 0F); |
| pied2 = new ModelRenderer(this, 0, 0); |
| pied2.addBox(0F, 0F, 0F, 1, 8, 1); |
| pied2.setRotationPoint(4F, 16F, -5F); |
| pied2.setTextureSize(64, 32); |
| pied2.mirror = true; |
| setRotation(pied2, 0F, 0F, 0F); |
| pied3 = new ModelRenderer(this, 0, 0); |
| pied3.addBox(0F, 0F, 0F, 1, 8, 1); |
| pied3.setRotationPoint(-5F, 16F, 4F); |
| pied3.setTextureSize(64, 32); |
| pied3.mirror = true; |
| setRotation(pied3, 0F, 0F, 0F); |
| pied4 = new ModelRenderer(this, 0, 0); |
| pied4.addBox(0F, 0F, 0F, 1, 8, 1); |
| pied4.setRotationPoint(4F, 16F, 4F); |
| pied4.setTextureSize(64, 32); |
| pied4.mirror = true; |
| setRotation(pied4, 0F, 0F, 0F); |
| plateau = new ModelRenderer(this, 0, 9); |
| plateau.addBox(0F, 0F, 0F, 10, 1, 10); |
| plateau.setRotationPoint(-5F, 16F, -5F); |
| plateau.setTextureSize(64, 32); |
| plateau.mirror = true; |
| setRotation(plateau, 0F, 0F, 0F); |
| dossier = new ModelRenderer(this, 4, 0); |
| dossier.addBox(0F, 0F, -9F, 10, 8, 1); |
| dossier.setRotationPoint(-5F, 8F, 4F); |
| dossier.setTextureSize(64, 32); |
| dossier.mirror = true; |
| setRotation(dossier, 0F, 0F, 0F); |
| } |
| |
| public void renderAll() |
| { |
| pied1.render(0.0625F); |
| pied2.render(0.0625F); |
| pied3.render(0.0625F); |
| pied4.render(0.0625F); |
| plateau.render(0.0625F); |
| dossier.render(0.0625F); |
| } |
| |
| private void setRotation(ModelRenderer model, float x, float y, float z) |
| { |
| model.rotateAngleX = x; |
| model.rotateAngleY = y; |
| model.rotateAngleZ = z; |
| } |
| |
| } |
| |
Mon TileEntity:
| |
| package fr.eterlia.mod.common; |
| |
| import net.minecraft.nbt.NBTTagCompound; |
| import net.minecraft.network.Packet; |
| import net.minecraft.tileentity.TileEntity; |
| |
| public class TileEntityChaise 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; |
| } |
| } |
| |
Mon TESR:
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| package fr.eterlia.mod.common; |
| |
| import net.minecraft.block.Block; |
| import net.minecraft.client.renderer.OpenGlHelper; |
| import net.minecraft.client.renderer.Tessellator; |
| import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; |
| import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; |
| import net.minecraft.entity.Entity; |
| import net.minecraft.tileentity.TileEntity; |
| import net.minecraft.util.ResourceLocation; |
| import net.minecraft.world.IBlockAccess; |
| import net.minecraft.world.World; |
| import org.lwjgl.opengl.GL11; |
| |
| public class TileEntityChaiseSpecialRenderer extends TileEntitySpecialRenderer { |
| |
| public TileEntityChaiseSpecialRenderer() { |
| this.func_147497_a(TileEntityRendererDispatcher.instance); |
| } |
| |
| public static ModelChaise model = new ModelChaise(); |
| |
| public static ResourceLocation texture = new ResourceLocation("modeterlia", |
| "textures/blocks/chaise.png"); |
| |
| @Override |
| public void renderTileEntityAt(TileEntity tile, double x, double y, |
| double z, float partialRenderTick) { |
| |
| this.renderTileEntityEterliaAt((TileEntityChaise) tile, x, y, z, |
| partialRenderTick); |
| |
| } |
| |
| private void renderTileEntityEterliaAt(TileEntityChaise 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(), 0.0F, 1.0F, 0.0F); |
| |
| this.bindTexture(texture); |
| model.renderAll(); |
| GL11.glPopMatrix(); |
| } |
| } |