我创建了一个在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();
}
}
如果您需要查看我的更多代码,我可以将其上传。
答案 0 :(得分:0)
由于包含连接状态的未初始化布尔数组,游戏在加载世界时崩溃。
所以初始化它。像这样:
public static boolean[] neighbourBlockWires = new boolean[6];
虽然我真的不认为它应该是static
,除非你希望世界上的每根电线以完全相同的方式呈现。