Hello,
Essentially, I just want to know why the code below does not work. All the blocks that get placed are ghost blocks that disappear when you restart the world or when you right click. Breaking the block in survival mode makes it immediately reset, so you effectively can't break it.
package memebassador.test.procedures;
/* imports omitted */
public class SetBlockTestProcedure {
public static boolean execute(LevelAccessor world, double x, double y, double z, boolean onGround) {
if (onGround) {
if (world.getBlockState(BlockPos.containing(x, y - 1, z)).canOcclude()) {
world.setBlock(BlockPos.containing(x, y, z), TestModBlocks.DROPPED_GUANO_STAGE_1.get().defaultBlockState(), 3);
TestMod.LOGGER.info(x);
TestMod.LOGGER.info(y);
TestMod.LOGGER.info(z);
}
return true;
}
return false;
}
}
And here is the code for the particle, if that is needed.
package memebassador.test.client.particle;
/* imports omitted */
@OnlyIn(Dist.CLIENT)
public class GuanoDropParticle extends TextureSheetParticle {
public static GuanoDropParticleProvider provider(SpriteSet spriteSet) {
return new GuanoDropParticleProvider(spriteSet);
}
public static class GuanoDropParticleProvider implements ParticleProvider<SimpleParticleType> {
private final SpriteSet spriteSet;
public GuanoDropParticleProvider(SpriteSet spriteSet) {
this.spriteSet = spriteSet;
}
public Particle createParticle(SimpleParticleType typeIn, ClientLevel worldIn, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
return new GuanoDropParticle(worldIn, x, y, z, xSpeed, ySpeed, zSpeed, this.spriteSet);
}
}
private final SpriteSet spriteSet;
protected GuanoDropParticle(ClientLevel world, double x, double y, double z, double vx, double vy, double vz, SpriteSet spriteSet) {
super(world, x, y, z);
this.spriteSet = spriteSet;
this.setSize(0.2f, 0.2f);
this.lifetime = 80;
this.gravity = 1f;
this.hasPhysics = true;
this.xd = vx * 0;
this.yd = vy * 0;
this.zd = vz * 0;
this.pickSprite(spriteSet);
}
@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.PARTICLE_SHEET_OPAQUE;
}
@Override
public void tick() {
super.tick();
Level world = this.level;
if (SetBlockTestProcedure.execute(world, x, y, z, onGround))
this.remove();
}
}
I will be up front and say that I am using MCreator to learn how to code for Minecraft. I have some programming experience but it's just less daunting using it for the time being. That said, if anything here looks stupid, it's probably because it's stupid.
Edit: I am stupid. Particles are client-side only. Using setBlock on the client side will literally never place any block server side, hence the ghost blocks. So what I would like to do here is only achievable with projectiles. Unless anyone has any proof of the contrary...