Jump to content

Recommended Posts

Posted (edited)

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...

Edited by Memebassador
Edit for server-side vs. client-side discovery.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.