How to make a sphere in MCreator

Started by LaTortiia on

Topic category: Help with Minecraft modding (Java Edition)

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to make a sphere in MCreator

Hey! So I've been wondering if any of you knows how to code a sphere using either MCreator Procedures or Minecraft Commands.

My goal is to make a sphere or air after my nuclear bomb explodes in order to make a crater, but I really don't know how to do it nor have I seen anyone do it, so I don't know if it's even possible to do it.

Has anyone done it? How can it be done?

 

Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
making a sphere shaped hole…
Fri, 02/12/2021 - 10:05

making a sphere shaped hole requires lots of math. you should google circle/sphere algorithms and try to implement it in your explosion procedure.

i made it using lots of code.

https://cdn.discordapp.com/attachments/599250311852458006/809726552870354966/unknown.png

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
By any means can you send me…
Fri, 02/12/2021 - 17:37

By any means can you send me a screenshot of the code you used?

Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
something like this: public…
Sat, 02/13/2021 - 01:58

something like this:

public class SphereExplosion {
	protected World world;
	private int centerX;
	private int centerY;
	private int centerZ;
	private int radius;
	private int tX;
	private int tY;
	private int tZ;
	private int tR;
	private boolean mobGriefing;
	private float fireChance;
	private int tick;

	public SphereExplosion(World worldIn, int x, int y, int z, int radiusIn, float fireChanceIn, boolean soundIn) {
		this.world = worldIn;
		this.centerX = x;
		this.centerY = y;
		this.centerZ = z;
		this.radius = radiusIn;
		this.fireChance = fireChanceIn;
		this.sound = soundIn;
		this.tY = radiusIn;
	}

	protected void onUpdate() {
		if (!this.shouldExecute()) {
			return;
		}
		
		super.onUpdate();
		
		if (this.sound && this.tick % 2 == 1) {
			this.world.playSound(null, this.centerX, this.centerY, this.centerZ, SoundEvents.ENTITY_GENERIC_EXPLODE, 
			  SoundCategory.BLOCKS, 10.0F, (1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.2F) * 0.7F);
		}
		
		this.doOnTick(this.tick);
		
		for (int i = 0; i < 10000;) {
			BlockPos posList[] = {
				new BlockPos(this.centerX + this.tX, this.centerY + this.tY, this.centerZ + this.tZ),
				new BlockPos(this.centerX - this.tX, this.centerY + this.tY, this.centerZ + this.tZ),
				new BlockPos(this.centerX + this.tX, this.centerY + this.tY, this.centerZ - this.tZ),
				new BlockPos(this.centerX - this.tX, this.centerY + this.tY, this.centerZ - this.tZ),
				new BlockPos(this.centerX + this.tZ, this.centerY + this.tY, this.centerZ + this.tX),
				new BlockPos(this.centerX + this.tZ, this.centerY + this.tY, this.centerZ - this.tX),
				new BlockPos(this.centerX - this.tZ, this.centerY + this.tY, this.centerZ + this.tX),
				new BlockPos(this.centerX - this.tZ, this.centerY + this.tY, this.centerZ - this.tX),
				new BlockPos(this.centerX + this.tX - 1, this.centerY + this.tY, this.centerZ + this.tZ),
				new BlockPos(this.centerX - this.tX + 1, this.centerY + this.tY, this.centerZ + this.tZ),
				new BlockPos(this.centerX + this.tX - 1, this.centerY + this.tY, this.centerZ - this.tZ),
				new BlockPos(this.centerX - this.tX + 1, this.centerY + this.tY, this.centerZ - this.tZ),
				new BlockPos(this.centerX + this.tZ, this.centerY + this.tY, this.centerZ + this.tX - 1),
				new BlockPos(this.centerX + this.tZ, this.centerY + this.tY, this.centerZ - this.tX + 1),
				new BlockPos(this.centerX - this.tZ, this.centerY + this.tY, this.centerZ + this.tX - 1),
				new BlockPos(this.centerX - this.tZ, this.centerY + this.tY, this.centerZ - this.tX + 1)
			};
			for (BlockPos pos : posList) {
				IBlockState blockstate = this.world.getBlockState(pos);
				if (!this.world.isAirBlock(pos) && blockstate.getBlockHardness(this.world, pos) >= 0.0F) {
					if (this.mobGriefing) {
						blockstate.getBlock().dropBlockAsItemWithChance(this.world, pos, blockstate, 0.5F / this.radius, 0);
						this.world.setBlockToAir(pos);
					}
					if (this.particles) {
						((WorldServer) this.world).spawnParticle(EnumParticleTypes.EXPLOSION_LARGE, pos.getX(), pos.getY(), pos.getZ(), 1,
								1.0D, 1.0D, 1.0D, 3.0D, new int[0]);
						((WorldServer) this.world).spawnParticle(EnumParticleTypes.SMOKE_LARGE, pos.getX(), pos.getY(), pos.getZ(), 1, 1.0D,
								1.0D, 1.0D, 0.0D, new int[0]);
					}
					i++;
				}
			}
			int i1 = (int) Math.round(Math.sqrt(this.radius * this.radius - this.tR * this.tR));
			this.tY--;
			if (this.centerY + this.tY >= 255) {
				continue;
			}
			if (this.tY < -i1 || this.centerY + this.tY < 0) {
				this.tY = i1;
				this.tZ++;
				this.tX = (int) Math.round(Math.sqrt(this.tR * this.tR - this.tZ * this.tZ));
			}
			if (this.tZ > (int) Math.round(this.tR / 1.41421356D)) {
				this.tZ = 0;
				this.tX = ++this.tR;
			}
			if (this.tR > this.radius) {
				if (this.mobGriefing && this.fireChance > 0.01f) {
					ProcedureAoeCommand.set(this.world, (double)this.centerX, (double)this.centerY, (double)this.centerZ, 0d, (double)this.radius*1.1d)
					  .setFire(this.fireChance);
				}
				this.setDead();
				return;
			}
		}
		
		this.tick++;
	}
	
	// some other methods ...
}

but you'll have to modify it to fit your needs. you'll need to tie it to some object that ticks like an entity.

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Undertood, thank you a lot!
Sat, 02/13/2021 - 15:03

Undertood, thank you a lot!

Joined Aug 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I know I'm probably asking…
Sat, 02/13/2021 - 16:58

I know I'm probably asking too much and being annoying, I don't have much experience with custom code, could you explain me which parameters I should modify in order to make this work please

For example, how to increase/decrease the radius, how, as you said, tie it to a block and how to set it up in general.

You are the very first person I've seen that's able to do a sphere in MCreator so I'd like to get as much info I can on this as possible!

Again, thanks a lot for your help!!!

Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it would be quite difficult…
Sun, 02/14/2021 - 04:34

it would be quite difficult if you don't know how to code.

i would recommend you create a living entity element in mcreator, lock and edit the element code, change the class to extend Entity instead of LivingEntity, remove the unnecessary code that handles entity rendering and living entity methods, implement that piece of code into entity class, override the setLocationAndAngles method to also set the center point at the x, y, z, and set radius the same as rotaionYaw. this way you can just call the "spawn entity with position and rotation" code block in other mcreator procedures to create the explosion.