Skip to content

Commit

Permalink
Merge pull request #374 from BentoBoxWorld/better_particles
Browse files Browse the repository at this point in the history
Gives better particles for the block identification.
  • Loading branch information
tastybento authored Mar 10, 2024
2 parents 1c6e1a5 + 21c5764 commit ed00dc5
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 30 deletions.
74 changes: 74 additions & 0 deletions src/main/java/world/bentobox/aoneblock/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.Set;

import org.bukkit.Color;
import org.bukkit.Difficulty;
import org.bukkit.GameMode;
import org.bukkit.block.Biome;
Expand Down Expand Up @@ -116,6 +117,18 @@ public class Settings implements WorldSettings {
@ConfigEntry(path = "world.starting-safety-duration")
private int startingSafetyDuration = 10;

@ConfigComment("Block identification appearance.")
@ConfigComment("Size of particles. Default is 0.7. Must be greater than 0.")
@ConfigEntry(path = "world.block-id.particle-size")
private Float particleSize = 0.7F;
@ConfigComment("Density of particles - Value from 0.1 to 1. Default is 0.5. Smaller values are more dense, higher are less.")
@ConfigEntry(path = "world.block-id.particle-density")
private Double particleDensity = 0.5D;
@ConfigComment("Color of particles")
@ConfigEntry(path = "world.block-id.particle-color")
private Color particleColor = Color.GREEN;


@ConfigComment("Clear blocks when spawning mobs.")
@ConfigComment("Mobs break blocks when they spawn is to prevent players from building a box around the magic block,")
@ConfigComment("having the mob spawn, and then die by suffocation, i.e., it's a cheat prevention.")
Expand Down Expand Up @@ -2080,4 +2093,65 @@ public int getStartingSafetyDuration() {
public void setStartingSafetyDuration(int startingSafetyDuration) {
this.startingSafetyDuration = startingSafetyDuration;
}

/**
* @return the particleSize
*/
public Float getParticleSize() {
if (particleSize == null) {
particleSize = 0.8F;
}
if (particleSize < 0F) {
particleSize = 0F;
}
return particleSize;
}


/**
* @param particleSize the particleSize to set
*/
public void setParticleSize(Float particleSize) {
this.particleSize = particleSize;
}

/**
* @return the particleColor
*/
public Color getParticleColor() {
if (particleColor == null) {
particleColor = Color.GREEN;
}
return particleColor;
}

/**
* @param particleColor the particleColor to set
*/
public void setParticleColor(Color particleColor) {
this.particleColor = particleColor;
}

/**
* @return the particleDensity
*/
public Double getParticleDensity() {
if (particleDensity == null) {
particleDensity = 0.5;
}
if (particleDensity < 0.1D) {
particleDensity = 0.1D;
}
if (particleDensity > 1D) {
particleDensity = 1D;
}
return particleDensity;
}

/**
* @param particleDensity the particleDensity to set
*/
public void setParticleDensity(Double particleDensity) {
this.particleDensity = particleDensity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import java.util.List;

import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.util.Vector;

import world.bentobox.aoneblock.listeners.BlockProtect;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
Expand All @@ -20,6 +20,7 @@
*/
public class IslandRespawnBlockCommand extends CompositeCommand
{

/**
* Instantiates a new Island respawn block command.
*
Expand Down Expand Up @@ -83,32 +84,14 @@ else if (Material.BEDROCK.equals(island.getCenter().getBlock().getType()) ||
}
else
{
// Spawn 6 particles where block is located.
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.5, 1.0, 0.5)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(1.0, 0.5, 0.5)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.5, 0.5, 1.0)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.5, 0.0, 0.5)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.0, 0.5, 0.5)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));
island.getWorld().spawnParticle(Particle.REDSTONE,
island.getCenter().add(new Vector(0.5, 0.5, 0.0)),
5, 0.1, 0, 0.1, 1,
new Particle.DustOptions(Color.fromBGR(0, 100, 0), 1));

for (double x = 0.0; x <= 1.0; x += 0.5) {
for (double y = 0.0; y <= 1.0; y += 0.5) {
for (double z = 0.0; z < 1.0; z += 0.5) {
island.getWorld().spawnParticle(Particle.REDSTONE, island.getCenter().add(new Vector(x, y, z)),
5, 0.1, 0, 0.1, 1, new Particle.DustOptions(BlockProtect.GREEN, 1));
}
}
}
user.sendMessage("aoneblock.commands.respawn-block.block-exist");
}

Expand Down
28 changes: 26 additions & 2 deletions src/main/java/world/bentobox/aoneblock/listeners/BlockProtect.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package world.bentobox.aoneblock.listeners;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.bukkit.Color;
Expand All @@ -24,6 +27,10 @@

public class BlockProtect implements Listener {

public static final Color GREEN = Color.fromBGR(0, 100, 0);
private static final List<Particle> PARTICLES = new ArrayList<>(List.of(Particle.REDSTONE));
private Iterator<Particle> particleIterator = Collections.emptyIterator();

private final AOneBlock addon;

/**
Expand All @@ -44,8 +51,25 @@ public void onBlockDamage(BlockDamageEvent e) {
}
Block block = e.getBlock();
Location l = block.getLocation();
addon.getIslands().getIslandAt(l).filter(i -> l.equals(i.getCenter())).ifPresent(i ->
block.getWorld().spawnParticle(Particle.REDSTONE, l.add(new Vector(0.5, 1.0, 0.5)), 5, 0.1, 0, 0.1, 1, new Particle.DustOptions(Color.fromBGR(0,100,0), 1)));
addon.getIslands().getIslandAt(l).map(Island::getCenter).filter(l::equals).ifPresent(this::showSparkles);
}

public void showSparkles(Location location) {
if (!particleIterator.hasNext()) {
Collections.shuffle(PARTICLES);
particleIterator = PARTICLES.iterator();
}
Particle p = particleIterator.next();
for (double x = -0.5; x <= 1.5; x += addon.getSettings().getParticleDensity()) {
for (double y = 0.0; y <= 1.5; y += addon.getSettings().getParticleDensity()) {
for (double z = -0.5; z < 1.5; z += addon.getSettings().getParticleDensity()) {
location.getWorld().spawnParticle(p, location.clone().add(new Vector(x, y, z)), 5,
0.1, 0, 0.1, 1, new Particle.DustOptions(addon.getSettings().getParticleColor(),
addon.getSettings().getParticleSize()));

}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -77,6 +78,7 @@ public void setUp() throws Exception {

// Location
when(location.getWorld()).thenReturn(world);
when(location.clone()).thenReturn(location);

// Block
when(block.getWorld()).thenReturn(world);
Expand Down Expand Up @@ -116,7 +118,7 @@ public void testOnBlockDamage() {
bp.onBlockDamage(blockDamageEvent);
verify(addon).inWorld(world);
verify(im).getIslandAt(location);
verify(world).spawnParticle(eq(Particle.REDSTONE), eq(null), eq(5),
verify(world, times(48)).spawnParticle(eq(Particle.REDSTONE), eq(null), eq(5),
eq(0.1D), eq(0D), eq(0.1D), eq(1D), any(Particle.DustOptions.class));
}

Expand Down

0 comments on commit ed00dc5

Please sign in to comment.