使用自定义块边界渲染故障我的世界
Posted
技术标签:
【中文标题】使用自定义块边界渲染故障我的世界【英文标题】:Render glitch with custom block boundaries minecraft 【发布时间】:2016-05-25 22:02:53 【问题描述】:我正在为 Minecraft 创建一个模组。最近,我尝试制作一个自定义块,但遇到了两个问题。
我的主要问题是块渲染不正确。我希望该块的大小小于一个完整的块。我使用setBlockBounds()
成功更改了块边界,虽然 确实 使块渲染更小并使用更小的边界,但它会导致其他渲染问题。当我放置方块时,下面的地板变得不可见,我可以透过它看到下面的洞穴,它后面的方块,或者如果那里什么都没有的话。如何修复该块不渲染?截图如下:
此外,我对这个方块的目标是发出一种“光环”,让周围的玩家获得速度或其他药水效果。我有在街区周围寻找玩家并给予他们速度的基本代码,但我无法找到一种方法来在每个滴答声或每 X 个滴答声中激活此方法,以确保它以可靠的方式为框内的玩家提供速度.正常游戏中已经有一些方块可以做到这一点,所以它一定是可能的。我该怎么做?
【问题讨论】:
【参考方案1】:对于您的第一个问题,您需要覆盖 isOpaqueCube
以返回 false。您还需要为代码的其他部分覆盖isFullCube
,但这对于渲染并不重要。示例:
public class YourBlock
// ... existing code ...
/**
* Used to determine ambient occlusion and culling when rebuilding chunks for render
*/
@Override
public boolean isOpaqueCube(IBlockState state)
return false;
@Override
public boolean isFullCube(IBlockState state)
return false;
Here's some info on rendering that mentions this.
关于你的第二个问题,这更复杂。它通常是通过一个 tile 实体来实现的,尽管您也可以使用块更新(这要慢得多)。很好的例子是BlockBeacon
和TileEntityBeacon
(用于使用图块实体)和BlockFrostedIce
(用于块更新)。这是一些(可能已过时)info on tile entities。
这是一个(未经测试的)示例,每次使用磁贴实体勾选此更新:
public class YourBlock
// ... existing code ...
/**
* Returns a new instance of a block's tile entity class. Called on placing the block.
*/
@Override
public TileEntity createNewTileEntity(World worldIn, int meta)
return new TileEntityYourBlock();
/**
* Tile entity for your block.
*
* Tile entities normally store data, but they can also receive an update each
* tick, but to do so they must implement ITickable. So, don't forget the
* "implements ITickable".
*/
public class TileEntityYourBlock extends TileEntity implements ITickable
@Override
public void update()
// Your code to give potion effects to nearby players would go here
// If you only want to do it every so often, you can check like this:
if (this.worldObj.getTotalWorldTime() % 80 == 0)
// Only runs every 80 ticks (4 seconds)
// The following code isn't required to make a tile entity that gets ticked,
// but you'll want it if you want (EG) to be able to set the effect.
/**
* Example potion effect.
* May be null.
*/
private Potion effect;
public void setEffect(Potion potionEffect)
this.effect = potionEffect;
public Potion getEffect()
return this.effect;
@Override
public void readFromNBT(NBTTagCompound compound)
super.readFromNBT(compound);
int effectID = compound.getInteger("Effect")
this.effect = Potion.getPotionById(effectID);
public void writeToNBT(NBTTagCompound compound)
super.writeToNBT(compound);
int effectID = Potion.getIdFromPotion(this.effect);
compound.setInteger("Effect", effectID);
// This line needs to go in the main registration.
// The ID can be anything so long as it isn't used by another mod.
GameRegistry.registerTileEntity(TileEntityYourBlock.class, "YourBlock");
【讨论】:
以上是关于使用自定义块边界渲染故障我的世界的主要内容,如果未能解决你的问题,请参考以下文章