[1.7.2] Нужна помощь по блоку c моделью

47
0
[1.7.2] Нужна помощь по блоку с моделью

Есть поворот модели. Но при пере заходе на карту поворот убирается. как сохранить его.

Код:
package render;

import model.ModelMinersLampa;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
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.World;

import org.lwjgl.opengl.GL11;

public class RenderMinersLampa extends TileEntitySpecialRenderer {
    
    //The model of your block
    private final ModelMinersLampa model;
   
    public RenderMinersLampa() {
            model = new ModelMinersLampa();
    }
   

   
    @Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
        
        EntityMinersLampa myTile = (EntityMinersLampa) te;
           int direction = myTile.direction;


        
    //The PushMatrix tells the renderer to "start" doing something.
            GL11.glPushMatrix();
    //This is setting the initial location.
            GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);

            GL11.glRotatef(180, 0F, 0F, 1F);
            GL11.glRotatef(direction * 90, 0F, 1F, 0F);

            ResourceLocation textures = new ResourceLocation("minecrftgases", "textures/entity/minerslamp.png");

            Minecraft.getMinecraft().renderEngine.bindTexture(textures);

    //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                      
            GL11.glPushMatrix();

            
    //A reference to your Model file. Again, very important.
            model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    //Tell it to stop rendering for both the PushMatrix's
            GL11.glPopMatrix();
            GL11.glPopMatrix();
    }
    


    //Set the lighting stuff, so it changes it's brightness properly.      
    private void adjustLightFixture(World world, int i, int j, int k, Block block) {
            Tessellator tess = Tessellator.instance;
            float brightness = block.getBlockHardness(world, i, j, k);
            int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
            int modulousModifier = skyLight % 65536;
            int divModifier = skyLight / 65536;
            tess.setColorOpaque_F(brightness, brightness, brightness);
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
            
    }
}
 
1,990
18
105
Сохраняй direction через метадату. Просто setBlockMetadata(x,y,z,meta) из класса блока при установке.
P.S.
Код:
//The PushMatrix tells the renderer to "start" doing something.
            GL11.glPushMatrix();
Код:
//This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                      
            GL11.glPushMatrix();
Код:
//Tell it to stop rendering for both the PushMatrix's
            GL11.glPopMatrix();
            GL11.glPopMatrix();
Вот за такие комментарии можно и убить. Они абсолютно неверные.
Никакого старта и стопа тут нет. glPushMatrix сохраняет состояние текущей матрицы в стеке, далее ты можешь делать любые трансформации с матрицей (домножения на матрицу поворота\перемещения\скейла), потом сделать glPopMatrix, которая вернет тебе предыдущее состояние матрицы в стеке. Второй glPush тут никаким боком не сдался и не нужен. А ротейта там и подавно нет, по крайней мере в том месте, где стоит комментарий.
 
47
0
комментарии не мои взял с вики.
и можно по подробней setBlockMetadata(x,y,z,meta)
 
1,990
18
105
Ну я понял, что не твои.
В своем блоке переопределяешь метод onBlockPlaced (смотри в родительском классе и бери метод оттуда), желательно с аннотацией сверху @Override, чтобы ты точно переопределял нужный метод, и внутри определяешь поворот (это у тебя, думается, сделано) и записываешь число поворота в метадату:

Код:
world.setBlockMetadata(x, y, z, direction);

Координаты будут в аргументах метода, direction - поворот.
 
47
0
в общем вышел такой бред    
Код:
    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
    {
    if (entity == null)
    {
    return;
    }
    EntityMinersLampa tile = (EntityMinersLampa) world.getTileEntity(x, y, z);
    tile.direction = MathHelper.floor_double((double)(entity.rotationYaw * 4F / 360.0F) + 2.5D) & 3;
    int i = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
    ++i;
    i %= 4;
    i=i*90;
     world.setBlockMetadata(x, y, z, i);
    }
 
1,990
18
105
НЕТ.
Нет-нет-нет. Нельзя так. Метадата хранит 4 бита, числа <= 15, по сути.
Сохраняй без умножения на 90.
 
47
0
убрал эклипс всё равно ругается
The method setBlockMetadata(int, int, int, int) is undefined for the type World
 
1,990
18
105
А, это. Ну я же ориентировочно дал название метода, поищи там подобный. Попробуй
setBlockMetadataWithNotify, 5 переменная там - флаг, при true обновляет блок сразу.
 
47
0
все равно не работает пока ни чего не нашёл на других форумах
 
1,990
18
105
Ругается? Или просто не работает?
И ещё. В рендерере не надо вытаскивать direction из тайла. Делай так:
Код:
 @Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
           int direction = te.worldObj.getBlockMetadata(x, y, z);
 
47
0
The field TileEntity.worldObj is not visible
на
int direction = te.worldObj.getBlockMetadata(x, y, z);

Minerslamp
Код:
package net.minecrftgases.blocks;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
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;
import render.EntityMinersLampa;
import render.RenderMinersLampa;

public class Minerslamp extends BlockContainer {


    public Minerslamp()
    {
        super(Material.glass);
        this.setLightLevel(1.0F);
        setBlockBounds(0.125F, 0.0F, 0.0F, 0.875F, 1.0F, 0.875F);
    }

    
    
    
    @Override
    //Make sure you set this as your TileEntity class relevant for the block!
    public TileEntity createNewTileEntity(World var1, int var2) {
            return new EntityMinersLampa();
    }
   
    //You don't want the normal render type, or it wont render properly.
    @Override
    public int getRenderType() {
            return -1;
    }
   
    //It's not an opaque cube, so you need this.
    @Override
    public boolean isOpaqueCube() {
            return false;
    }
   
    //It's not a normal block, so you need this too.
    public boolean renderAsNormalBlock() {
            return false;
    }
   
    //This is the icon to use for showing the block in your hand.
    public void registerIcons(IIconRegister icon) {
            blockIcon = icon.registerIcon("textures/items/itemIco");
    }
    
    @Override
    public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack)
    {
    if (entity == null)
    {
    return;
    }
    EntityMinersLampa tile = (EntityMinersLampa) world.getTileEntity(x, y, z);
    tile.direction = MathHelper.floor_double((double)(entity.rotationYaw * 4F / 360.0F) + 2.5D) & 3;
    int i = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3;
     world.setBlockMetadataWithNotify(x, y, z, i, 2);
    }
  
}

RenderMinersLampa
Код:
package render;

import model.ModelMinersLampa;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
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.World;

import org.lwjgl.opengl.GL11;

public class RenderMinersLampa extends TileEntitySpecialRenderer {
    
    //The model of your block
    private final ModelMinersLampa model;
   
    public RenderMinersLampa() {
            model = new ModelMinersLampa();
    }
   

   
    @Override
    public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) {
        
         int direction = te.worldObj.getBlockMetadata(x, y, z);


        
    //The PushMatrix tells the renderer to "start" doing something.
            GL11.glPushMatrix();
    //This is setting the initial location.
            GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);

            GL11.glRotatef(180, 0F, 0F, 1F);
            GL11.glRotatef(direction * 90, 0F, 1F, 0F);

            ResourceLocation textures = new ResourceLocation("minecrftgases", "textures/entity/minerslamp.png");

            Minecraft.getMinecraft().renderEngine.bindTexture(textures);

    //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again!                      
            GL11.glPushMatrix();

            
    //A reference to your Model file. Again, very important.
            model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
    //Tell it to stop rendering for both the PushMatrix's
            GL11.glPopMatrix();
            GL11.glPopMatrix();
    }
    


    //Set the lighting stuff, so it changes it's brightness properly.      
    private void adjustLightFixture(World world, int i, int j, int k, Block block) {
            Tessellator tess = Tessellator.instance;
            float brightness = block.getBlockHardness(world, i, j, k);
            int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0);
            int modulousModifier = skyLight % 65536;
            int divModifier = skyLight / 65536;
            tess.setColorOpaque_F(brightness, brightness, brightness);
            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit,  (float) modulousModifier,  divModifier);
            
    }
}

Код:
package render;

import net.minecraft.tileentity.TileEntity;

public class EntityMinersLampa extends TileEntity {
    public int direction;

}
 
1,990
18
105
Код:
getWorldObj()

вместо worldObj.
Блин, мог бы и сам залезть в класс да посмотреть приватность полей и взять с геттера.
 
Сверху