【问题标题】:Rendering block depending on block state/passing variable between classes根据类之间的块状态/传递变量渲染块
【发布时间】:2014-09-06 02:05:21
【问题描述】:

我创建了一个线块,在 Techne 中自定义渲染。我想要发生的是根据是否连接了另一根电线来显示/隐藏部分电线。这在理论上有效,并且在我手动输入连接状态时有效。现在我实际上正在尝试获取由于包含连接状态的未初始化布尔数组而导致游戏在加载世界时崩溃的数据。如果有人可以帮助我将数据从块类获取到渲染类,那就太好了。

方块类

package foodTech.blocks;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import foodTech.tileEntities.TileEntityCable;

public class BlockCable extends BlockContainer
{
    /**
     * Contains 6 values for each face of a cable block
     * up, down, north, south, east, west
     */
    public static boolean[] neighbourBlockWires;

    public BlockCable(Material material)
    {
        super(material);
        float pixel = 1F/16F;
        this.setBlockBounds(12*pixel/2, 12*pixel/2, 12*pixel/2, 1-12*pixel/2, 1-12*pixel/2, 1-12*pixel/2);
        this.useNeighborBrightness = true;
    }

    public int getRenderType()
    {
        return -1;
    }

    public boolean isOpaqueCube()
    {
        return false;
    }

    public boolean renderAsNormalBlock()
    {
        return false;
    }

    public TileEntity createNewTileEntity(World world, int var2) 
    {
        return new TileEntityCable();
    }

     private void getConnectedWires(int x, int y, int z, World world)
     {
         boolean[] neighbourBlockWires = {false, false, false, false, false, false};

         if (world.getBlock(x, y+1, z).equals(this)) neighbourBlockWires[0] = true;
         if (world.getBlock(x, y-1, z).equals(this)) neighbourBlockWires[1] = true;
         if (world.getBlock(x+1, y, z).equals(this)) neighbourBlockWires[2] = true;
         if (world.getBlock(x-1, y, z).equals(this)) neighbourBlockWires[3] = true;
         if (world.getBlock(x, y, z+1).equals(this)) neighbourBlockWires[4] = true;
         if (world.getBlock(x, y, z-1).equals(this)) neighbourBlockWires[5] = true;

         BlockCable.neighbourBlockWires = neighbourBlockWires;
     }

     public void onNeighborBlockChange(World world, int x, int y, int z, Block block)
     {
         getConnectedWires(x, y, z, world);
     }

     public void updateTick(World world, int x, int y, int z, Random rand)
     {
         getConnectedWires(x, y, z, world);
     }

     public void onBlockAdded(World world, int x, int y, int z)
     {
         getConnectedWires(x, y, z, world);
     }
}

渲染类

package foodTech.tileEntities.render;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;

import org.lwjgl.opengl.GL11;

import foodTech.blocks.BlockCable;
import foodTech.tileEntities.models.ModelCable;

public class RenderCable extends TileEntitySpecialRenderer 
{
    ResourceLocation textureOff = (new ResourceLocation("roboguy99:textures/models/cableOff.png"));
    ResourceLocation textureOn = (new ResourceLocation("roboguy99:textures/models/cableOn.png"));

    public ModelCable modelCable;
    private boolean[] neighbourBlockWires = {true, false, false, false, false, false};

    public RenderCable()
    {
        this.modelCable = new ModelCable(this.neighbourBlockWires);
    }

    public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float scale) 
    {
        GL11.glPushMatrix();
            GL11.glTranslatef((float) x + 0.5F, (float) y - 0.5F, (float) z + 0.5F);

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

            this.neighbourBlockWires = BlockCable.neighbourBlockWires;
            this.modelCable = new ModelCable(this.neighbourBlockWires);

            this.modelCable.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

            GL11.glTranslatef((float) x - 0.5F, (float) y + 0.5F, (float) z - 0.5F);
        GL11.glPopMatrix();
    }
}

如果您需要查看我的更多代码,我可以上传。

【问题讨论】:

    标签: java arrays class initialization minecraft


    【解决方案1】:

    由于包含连接状态的未初始化布尔数组,游戏在加载世界时崩溃。

    所以初始化它。像这样:

    public static boolean[] neighbourBlockWires = new boolean[6];
    

    虽然我真的不认为它应该是static,除非你希望世界上的每一根电线都以完全相同的方式呈现。

    【讨论】:

    • 我把它放在渲染类中,但在同一个地方得到了同样的错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    相关资源
    最近更新 更多