使用自定义块边界 minecraft 渲染故障
Render glitch with custom block boundaries minecraft
我正在为 Minecraft 创建 mod。最近,我尝试制作一个自定义块,但遇到了两个问题。
我的主要问题是块渲染不正确。我希望块的大小小于整个块。我使用 setBlockBounds()
成功更改了块边界,虽然 did 使块渲染更小并使用更小的边界,但它会导致其他渲染问题。当我放置方块时,下面的地板变得不可见,我可以透过它看到下面的洞穴,它后面的方块,或者如果那里什么都没有的话就是虚空。如何修复该块不渲染?这是屏幕截图:
此外,我对这个方块的目标是发射一个 "aura" 给周围的玩家速度或其他药水效果。我有在街区周围寻找玩家并给他们速度的基本代码,但我找不到一种方法来激活这个方法,每次滴答声或每 X 次滴答声,以确保它以可靠的方式给盒子内的玩家速度.正常游戏中已经有一些方块可以做到这一点,所以这一定是可能的。我该怎么做?
对于您的第一期,您需要将 isOpaqueCube
覆盖为 return 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.
关于你的第二个问题,比较复杂。它通常通过图块实体实现,但您也可以使用块更新(速度要慢得多)。 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");
我正在为 Minecraft 创建 mod。最近,我尝试制作一个自定义块,但遇到了两个问题。
我的主要问题是块渲染不正确。我希望块的大小小于整个块。我使用 setBlockBounds()
成功更改了块边界,虽然 did 使块渲染更小并使用更小的边界,但它会导致其他渲染问题。当我放置方块时,下面的地板变得不可见,我可以透过它看到下面的洞穴,它后面的方块,或者如果那里什么都没有的话就是虚空。如何修复该块不渲染?这是屏幕截图:
此外,我对这个方块的目标是发射一个 "aura" 给周围的玩家速度或其他药水效果。我有在街区周围寻找玩家并给他们速度的基本代码,但我找不到一种方法来激活这个方法,每次滴答声或每 X 次滴答声,以确保它以可靠的方式给盒子内的玩家速度.正常游戏中已经有一些方块可以做到这一点,所以这一定是可能的。我该怎么做?
对于您的第一期,您需要将 isOpaqueCube
覆盖为 return 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.
关于你的第二个问题,比较复杂。它通常通过图块实体实现,但您也可以使用块更新(速度要慢得多)。 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");