MC百科社群
标题:
1.12.2关于粒子效果生成的问题
[打印本页]
作者:
QQ酱121421
时间:
前天 20:38
标题:
1.12.2关于粒子效果生成的问题
本帖最后由 QQ酱121421 于 2024-12-20 21:48 编辑
骨粉粒子效果问题
我直接调用:
net.minecraft.item.ItemDye.spawnBonemealParticles(world, pos, 15);
复制代码
或者复制spawnBonemealParticles()方法:
for (int i = 0; i < 15; ++i) {
double x = (double) ((float)pos.getX() + rand.nextFloat());
double y = (double) ((float)pos.getY() + rand.nextFloat());
double z = (double) ((float)pos.getZ() + rand.nextFloat());
double d0 = rand.nextGaussian() * 0.02D;
double d1 = rand.nextGaussian() * 0.02D;
double d2 = rand.nextGaussian() * 0.02D;
world.spawnParticle(
EnumParticleTypes.VILLAGER_HAPPY,
x, y, z,
d0, d1, d2
);
}
复制代码
两种方法来生成骨粉的粒子效果,
但是都没有骨粉的粒子出现
.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
关于自定义粒子
我的自定义
粒子贴图错误
, 显示的是原版的那一大张粒子合集图
主类注册粒子贴图:
@SubscribeEvent
public static void onTextureStitchPre(net.minecraftforge.client.event.TextureStitchEvent.Pre event) {
event.getMap().registerSprite(new ResourceLocation(MODID, "particle/cherry_particle"));
}
复制代码
粒子类:
public class CherryParticle extends Particle {
private static Random random = new Random();
private static double[] axis = new double[]{0.03D, 0.04D, 0.05D, 0.06D, 0.07D};
public CherryParticle(World world, double x, double y, double z) {
super(world, x, y, z);
// 获取粒子贴图
Texture texture = new Texture();
// 设置粒子贴图
this.particleTexture = texture;
this.particleTextureIndexX = 1;
this.particleTextureIndexY = 1;
// 设置粒子生命周期
this.isExpired = false;
this.particleAge = 0;
this.particleMaxAge = (20 * 10); // 粒子生命周期 / 10s
// 粒子运动
this.motionX = axis[random.nextInt(axis.length)];
this.motionY = 0;
this.motionZ = axis[random.nextInt(axis.length)];
// 粒子不可以被碰撞
this.canCollide = false;
}
//生成粒子效果方法
public static void spawnParticle(World world, BlockPos pos) {
IBlockState downBlockState = world.getBlockState(pos.down());
Block downBlock = downBlockState.getBlock();
if (!downBlock.isFullCube(downBlockState) && random.nextInt(8) == 0) {
double x = pos.getX() + (Math.random() * 1);
double y = pos.getY() - 0.01;
double z = pos.getZ() + (Math.random() * 1);
CherryParticle particle = new CherryParticle(world, x, y, z);
net.minecraft.client.Minecraft.getMinecraft().effectRenderer.addEffect(particle);
}
}
//粒子更新逻辑
private double fall = 0.09;
@Override
public void onUpdate() {
this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;
this.motionY = -fall;
if (this.particleAge % 5 == 0 && fall >= 0.01)
/*更新下落速度*/fall -= 0.002;
//移动
this.move(this.motionX, this.motionY, this.motionZ);
expiredParticle();
}
//检查移除
public void expiredParticle() {
BlockPos pos = new BlockPos(this.posX, this.posY, this.posZ);
IBlockState posBlockState = this.world.getBlockState(pos);
Block posBlock = posBlockState.getBlock();
// 粒子生命周期结束 || (当前位置方块是完整方块 && 当前位置方块不是樱花树叶)
if (this.particleAge++ >= this.particleMaxAge || (posBlock.isFullCube(posBlockState) && posBlock != BlockBase.CHERRY_LEAVES))
/*移除粒子*/this.setExpired();
}
//材质
class Texture extends TextureAtlasSprite {
public Texture() {
super("suikecherry:particle/cherry_particle");
this.width = 3;
this.height = 3;
this.initSprite(3, 3, 0, 0, false);
}
}
}
复制代码
以上实现的效果:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
顺便问一下怎么识别玩家是否是创造模式, 我从别人源码复制的
if (!player.capabilities.isCreativeMode)
复制代码
会报错:
错误: capabilities
在 Entity 中是 private 访问控制
if (!player.capabilities.isCreativeMode)
^
错误: 找不到符号
if (!player.capabilities.isCreativeMode)
^
符号: 变量 isCreativeMode
位置: 类型为CapabilityDispatcher的变量 capabilities
复制代码
欢迎光临 MC百科社群 (https://bbs.mcmod.cn/)
MC百科
|最大的MineCraft中文模组百科