From 7878b05030ae6eca5a146c2561c13f5511f7584d Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 21 Sep 2021 17:57:55 +0200 Subject: [PATCH 1/9] Run raw commands for entity spawns --- .../com/volmit/iris/engine/object/IrisEntity.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEntity.java b/src/main/java/com/volmit/iris/engine/object/IrisEntity.java index 0e6254a2e..658a5afa3 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEntity.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEntity.java @@ -176,6 +176,10 @@ public class IrisEntity extends IrisRegistrant { @RegistryListResource(IrisScript.class) private KList postSpawnScripts = new KList<>(); + @ArrayType(min = 1, type = String.class) + @Desc("Run raw commands when this entity is spawned. Use {x}, {y}, and {z} for location. /summon pig {x} {y} {z}") + private KList rawCommands = new KList<>(); + public Entity spawn(Engine gen, Location at) { return spawn(gen, at, new RNG(at.hashCode())); } @@ -357,6 +361,17 @@ public class IrisEntity extends IrisRegistrant { } } + if (rawCommands.isNotEmpty()) { + synchronized (this) { + for (String rawCommand : rawCommands) { + rawCommand.replaceAll("\\Q{x}\\E", String.valueOf(at.getBlockX())); + rawCommand.replaceAll("\\Q{y}\\E", String.valueOf(at.getBlockY())); + rawCommand.replaceAll("\\Q{z}\\E", String.valueOf(at.getBlockZ())); + Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), rawCommand); + } + } + } + Location finalAt1 = at; J.s(() -> { From 940a65cac07cdb6723ef0f01815b5ca59ee054ed Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 21 Sep 2021 17:31:58 +0200 Subject: [PATCH 2/9] Revert "fixes" This reverts commit 8539bc5ade86d04824a6bcbd8ab95f3190da846a. --- src/main/java/com/volmit/iris/core/commands/CommandWhat.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/commands/CommandWhat.java b/src/main/java/com/volmit/iris/core/commands/CommandWhat.java index 9c3650ba0..884621c93 100644 --- a/src/main/java/com/volmit/iris/core/commands/CommandWhat.java +++ b/src/main/java/com/volmit/iris/core/commands/CommandWhat.java @@ -39,7 +39,7 @@ import org.bukkit.block.data.BlockData; import java.util.concurrent.atomic.AtomicInteger; -@Decree(name = "what", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris What?", aliases = "w") +@Decree(name = "what", origin = DecreeOrigin.PLAYER, studio = true, description = "Iris What?") public class CommandWhat implements DecreeExecutor { @Decree(description = "What is in my hand?", origin = DecreeOrigin.PLAYER) public void hand() { @@ -62,7 +62,7 @@ public class CommandWhat implements DecreeExecutor { } } - @Decree(description = "What biome am i in?", origin = DecreeOrigin.PLAYER, aliases = "b") + @Decree(description = "What biome am i in?", origin = DecreeOrigin.PLAYER) public void biome() { try { IrisBiome b = engine().getBiome(player().getLocation().getBlockX(), player().getLocation().getBlockY(), player().getLocation().getBlockZ()); From b73f9798e41bf922b4d5b151d4db917084409593 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 21 Sep 2021 19:45:32 +0200 Subject: [PATCH 3/9] Introduction if IrisCommands --- .../iris/engine/object/IrisCommand.java | 48 +++++++++++++++++++ .../volmit/iris/engine/object/IrisEntity.java | 14 ++---- 2 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/volmit/iris/engine/object/IrisCommand.java diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCommand.java b/src/main/java/com/volmit/iris/engine/object/IrisCommand.java new file mode 100644 index 000000000..88d6285a1 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisCommand.java @@ -0,0 +1,48 @@ +package com.volmit.iris.engine.object; + +import com.volmit.iris.Iris; +import com.volmit.iris.engine.object.annotations.Desc; +import com.volmit.iris.engine.object.annotations.RegistryListResource; +import com.volmit.iris.engine.object.annotations.Snippet; +import com.volmit.iris.util.collection.KList; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; +import org.bukkit.Bukkit; +import org.bukkit.Location; + +@Snippet("command") +@Accessors(chain = true) +@NoArgsConstructor +@Desc("Represents a color") +@Data +public class IrisCommand { + + @Desc("List of commands. Iris replaces {x} {y} and {z} with the location of the entity spawn") + private KList commands = new KList<>(); + + @Desc("The delay for running the command. Instant by default") + private long delay = 0; + + @Desc("If this should be repeated (indefinitely, cannot be cancelled). This does not persist with server-restarts, so it only repeats when the chunk is generated.") + private boolean repeat = false; + + @Desc("The delay between repeats, in server ticks (by default 100, so 5 seconds)") + private long repeatDelay = 100; + + + public void run(Location at) { + for (String command : commands) { + command = (command.startsWith("/") ? command.replaceFirst("/", "") : command) + .replaceAll("\\Q{x}\\E", String.valueOf(at.getBlockX())) + .replaceAll("\\Q{y}\\E", String.valueOf(at.getBlockY())) + .replaceAll("\\Q{z}\\E", String.valueOf(at.getBlockZ())); + final String finalCommand = command; + if (repeat) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(Iris.instance, () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalCommand), delay, repeatDelay); + } else { + Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () -> Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), finalCommand), delay); + } + } + } +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEntity.java b/src/main/java/com/volmit/iris/engine/object/IrisEntity.java index 658a5afa3..ca7f2ce62 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEntity.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEntity.java @@ -176,9 +176,9 @@ public class IrisEntity extends IrisRegistrant { @RegistryListResource(IrisScript.class) private KList postSpawnScripts = new KList<>(); - @ArrayType(min = 1, type = String.class) + @ArrayType(min = 1, type = IrisCommand.class) @Desc("Run raw commands when this entity is spawned. Use {x}, {y}, and {z} for location. /summon pig {x} {y} {z}") - private KList rawCommands = new KList<>(); + private KList rawCommands = new KList<>(); public Entity spawn(Engine gen, Location at) { return spawn(gen, at, new RNG(at.hashCode())); @@ -362,14 +362,8 @@ public class IrisEntity extends IrisRegistrant { } if (rawCommands.isNotEmpty()) { - synchronized (this) { - for (String rawCommand : rawCommands) { - rawCommand.replaceAll("\\Q{x}\\E", String.valueOf(at.getBlockX())); - rawCommand.replaceAll("\\Q{y}\\E", String.valueOf(at.getBlockY())); - rawCommand.replaceAll("\\Q{z}\\E", String.valueOf(at.getBlockZ())); - Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), rawCommand); - } - } + final Location fat = at; + rawCommands.forEach(r -> r.run(fat)); } Location finalAt1 = at; From 587af255a6e58e01a50aa971744812ef936c257c Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 21 Sep 2021 19:53:24 +0200 Subject: [PATCH 4/9] fix --- src/main/java/com/volmit/iris/engine/object/IrisCommand.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCommand.java b/src/main/java/com/volmit/iris/engine/object/IrisCommand.java index 88d6285a1..af1a6bc07 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisCommand.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisCommand.java @@ -1,6 +1,7 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; +import com.volmit.iris.engine.object.annotations.ArrayType; import com.volmit.iris.engine.object.annotations.Desc; import com.volmit.iris.engine.object.annotations.RegistryListResource; import com.volmit.iris.engine.object.annotations.Snippet; @@ -18,6 +19,7 @@ import org.bukkit.Location; @Data public class IrisCommand { + @ArrayType(min = 1, type = String.class) @Desc("List of commands. Iris replaces {x} {y} and {z} with the location of the entity spawn") private KList commands = new KList<>(); From 0a85521028e1c3bbffd67cbd68fd7bce768eef06 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 21 Sep 2021 20:17:31 +0200 Subject: [PATCH 5/9] OK I'm really guessing at this point --- .../com/volmit/iris/core/service/WandSVC.java | 4 -- .../volmit/iris/engine/object/IrisObject.java | 50 ++++++------------- .../engine/object/IrisObjectPlacement.java | 4 ++ 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/service/WandSVC.java b/src/main/java/com/volmit/iris/core/service/WandSVC.java index 494a8c48e..a05153244 100644 --- a/src/main/java/com/volmit/iris/core/service/WandSVC.java +++ b/src/main/java/com/volmit/iris/core/service/WandSVC.java @@ -57,10 +57,6 @@ public class WandSVC implements IrisService { private static ItemStack wand; private static ItemStack dust; - public static void pasteSchematic(IrisObject s, Location at) { - s.place(at); - } - /** * Creates an Iris Object from the 2 coordinates selected with a wand * diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index a4cfec435..b466fe4e7 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -71,7 +71,6 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; -@SuppressWarnings("DefaultAnnotationParam") @Accessors(chain = true) @EqualsAndHashCode(callSuper = false) public class IrisObject extends IrisRegistrant { @@ -487,23 +486,11 @@ public class IrisObject extends IrisRegistrant { } } - public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { - return place(x, -1, z, placer, config, rng, rdata); + public void place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { + place(x, yv, z, placer, config, rng, null, null, rdata); } - public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, CarveResult c, IrisData rdata) { - return place(x, -1, z, placer, config, rng, null, c, rdata); - } - - public int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { - return place(x, yv, z, placer, config, rng, null, null, rdata); - } - - public int place(Location loc, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { - return place(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), placer, config, rng, rdata); - } - - public int place(int x, int yv, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, Consumer listener, CarveResult c, IrisData rdata) { + public void place(int x, int yv, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, Consumer listener, CarveResult c, IrisData rdata) { IObjectPlacer placer = (config.getHeightmap() != null) ? new HeightmapObjectPlacer(oplacer.getEngine() == null ? IrisContext.get().getEngine() : oplacer.getEngine(), rng, x, yv, z, config, oplacer) : oplacer; if (config.isSmartBore()) { @@ -619,25 +606,25 @@ public class IrisObject extends IrisRegistrant { } if (bail) { - return -1; + return; } if (yv < 0) { if (!config.isUnderwater() && !config.isOnwater() && placer.isUnderwater(x, z)) { - return -1; + return; } } if (c != null && Math.max(0, h + yrand + ty) + 1 >= c.getHeight()) { - return -1; + return; } if (config.isUnderwater() && y + rty + ty >= placer.getFluidHeight()) { - return -1; + return; } if (!config.getClamp().canPlace(y + rty + ty, y - rty + ty)) { - return -1; + return; } if (config.isBore()) { @@ -865,7 +852,12 @@ public class IrisObject extends IrisRegistrant { } } - return y; + if (config.getRawCommands().isNotEmpty()) { + Location l = new Location(rdata.getEngine().getWorld().realWorld(), x, y, z); + for (IrisCommand rawCommand : config.getRawCommands()) { + rawCommand.run(l); + } + } } public IrisObject rotateCopy(IrisObjectRotation rt) { @@ -892,20 +884,6 @@ public class IrisObject extends IrisRegistrant { states = dx; } - public void place(Location at) { - for (BlockVector i : getBlocks().keySet()) { - Block b = at.clone().add(0, getCenter().getY(), 0).add(i).getBlock(); - b.setBlockData(Objects.requireNonNull(getBlocks().get(i)), false); - - if (getStates().containsKey(i)) { - Iris.info(Objects.requireNonNull(states.get(i)).toString()); - BlockState st = b.getState(); - Objects.requireNonNull(getStates().get(i)).toBukkitTry(st); - st.update(); - } - } - } - public void placeCenterY(Location at) { for (BlockVector i : getBlocks().keySet()) { Block b = at.clone().add(getCenter().getX(), getCenter().getY(), getCenter().getZ()).add(i).getBlock(); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index 923054d9b..ad79c6a14 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -126,6 +126,10 @@ public class IrisObjectPlacement { @Desc("This object / these objects override the following trees when they grow...") @ArrayType(min = 1, type = IrisTree.class) private KList trees = new KList<>(); + @Desc("Run raw commands at the location of this object") + @ArrayType(min = 1, type = IrisCommand.class) + private KList rawCommands = new KList<>(); + private transient AtomicCache cache = new AtomicCache<>(); public IrisObjectPlacement toPlacement(String... place) { From 54eff0e27f3f33f6d08e5cf6eace53358c1bdc0c Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 21 Sep 2021 20:27:08 +0200 Subject: [PATCH 6/9] Good enough --- .../volmit/iris/engine/object/IrisEffect.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java index 9a7e01c25..ac2040957 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java @@ -21,12 +21,8 @@ package com.volmit.iris.engine.object; import com.volmit.iris.Iris; import com.volmit.iris.engine.data.cache.AtomicCache; import com.volmit.iris.engine.framework.Engine; -import com.volmit.iris.engine.object.annotations.DependsOn; -import com.volmit.iris.engine.object.annotations.Desc; -import com.volmit.iris.engine.object.annotations.MaxNumber; -import com.volmit.iris.engine.object.annotations.MinNumber; -import com.volmit.iris.engine.object.annotations.Required; -import com.volmit.iris.engine.object.annotations.Snippet; +import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.scheduling.ChronoLatch; import com.volmit.iris.util.scheduling.J; @@ -151,6 +147,9 @@ public class IrisEffect { @MinNumber(1) @Desc("The chance is 1 in CHANCE per interval") private int chance = 50; + @ArrayType(min = 1, type = IrisCommand.class) + @Desc("Run commands, at the exact location of the player") + private KList rawCommands = new KList<>(); public boolean canTick() { return latch.aquire(() -> new ChronoLatch(interval)).flip(); @@ -221,6 +220,14 @@ public class IrisEffect { } } + if (rawCommands.isNotEmpty()) { + Location part = p.getLocation().clone(); + + for (IrisCommand rawCommand : rawCommands) { + rawCommand.run(part); + } + } + if (potionStrength > -1) { if (p.hasPotionEffect(getRealType())) { PotionEffect e = p.getPotionEffect(getRealType()); From 16795871c37f622d0e0a11d09214d2c71c2d9af3 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 21 Sep 2021 20:44:31 +0200 Subject: [PATCH 7/9] Run commands in effects --- .../volmit/iris/engine/object/IrisEffect.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java index ac2040957..ed7c45449 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java @@ -150,6 +150,33 @@ public class IrisEffect { @ArrayType(min = 1, type = IrisCommand.class) @Desc("Run commands, at the exact location of the player") private KList rawCommands = new KList<>(); + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetX = 0; + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetY = 0; + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetZ = 0; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altX from -altX to altX") + private boolean commandRandomAltX = true; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altY from -altY to altY") + private boolean commandRandomAltY = false; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altZ from -altZ to altZ") + private boolean commandRandomAltZ = true; + @DependsOn({"rawCommands"}) + @Desc("Randomize location for all separate commands (true), or run all on the same location (false)") + private boolean commandAllRandomLocations = true; public boolean canTick() { return latch.aquire(() -> new ChronoLatch(interval)).flip(); @@ -221,10 +248,18 @@ public class IrisEffect { } if (rawCommands.isNotEmpty()) { - Location part = p.getLocation().clone(); - + Location part = p.getLocation().clone().add( + commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, + commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, + commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); for (IrisCommand rawCommand : rawCommands) { rawCommand.run(part); + if (commandAllRandomLocations) { + part = p.getLocation().clone().add( + commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, + commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, + commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); + } } } From 8070b211ab2f1d324bb7373c1c13c965c77475c8 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Tue, 21 Sep 2021 20:17:31 +0200 Subject: [PATCH 8/9] Revert "OK I'm really guessing at this point" This reverts commit 0a85521028e1c3bbffd67cbd68fd7bce768eef06. --- .../com/volmit/iris/core/service/WandSVC.java | 4 ++ .../volmit/iris/engine/object/IrisObject.java | 50 +++++++++++++------ .../engine/object/IrisObjectPlacement.java | 4 -- 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/volmit/iris/core/service/WandSVC.java b/src/main/java/com/volmit/iris/core/service/WandSVC.java index a05153244..494a8c48e 100644 --- a/src/main/java/com/volmit/iris/core/service/WandSVC.java +++ b/src/main/java/com/volmit/iris/core/service/WandSVC.java @@ -57,6 +57,10 @@ public class WandSVC implements IrisService { private static ItemStack wand; private static ItemStack dust; + public static void pasteSchematic(IrisObject s, Location at) { + s.place(at); + } + /** * Creates an Iris Object from the 2 coordinates selected with a wand * diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObject.java b/src/main/java/com/volmit/iris/engine/object/IrisObject.java index b466fe4e7..a4cfec435 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObject.java @@ -71,6 +71,7 @@ import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; +@SuppressWarnings("DefaultAnnotationParam") @Accessors(chain = true) @EqualsAndHashCode(callSuper = false) public class IrisObject extends IrisRegistrant { @@ -486,11 +487,23 @@ public class IrisObject extends IrisRegistrant { } } - public void place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { - place(x, yv, z, placer, config, rng, null, null, rdata); + public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { + return place(x, -1, z, placer, config, rng, rdata); } - public void place(int x, int yv, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, Consumer listener, CarveResult c, IrisData rdata) { + public int place(int x, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, CarveResult c, IrisData rdata) { + return place(x, -1, z, placer, config, rng, null, c, rdata); + } + + public int place(int x, int yv, int z, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { + return place(x, yv, z, placer, config, rng, null, null, rdata); + } + + public int place(Location loc, IObjectPlacer placer, IrisObjectPlacement config, RNG rng, IrisData rdata) { + return place(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), placer, config, rng, rdata); + } + + public int place(int x, int yv, int z, IObjectPlacer oplacer, IrisObjectPlacement config, RNG rng, Consumer listener, CarveResult c, IrisData rdata) { IObjectPlacer placer = (config.getHeightmap() != null) ? new HeightmapObjectPlacer(oplacer.getEngine() == null ? IrisContext.get().getEngine() : oplacer.getEngine(), rng, x, yv, z, config, oplacer) : oplacer; if (config.isSmartBore()) { @@ -606,25 +619,25 @@ public class IrisObject extends IrisRegistrant { } if (bail) { - return; + return -1; } if (yv < 0) { if (!config.isUnderwater() && !config.isOnwater() && placer.isUnderwater(x, z)) { - return; + return -1; } } if (c != null && Math.max(0, h + yrand + ty) + 1 >= c.getHeight()) { - return; + return -1; } if (config.isUnderwater() && y + rty + ty >= placer.getFluidHeight()) { - return; + return -1; } if (!config.getClamp().canPlace(y + rty + ty, y - rty + ty)) { - return; + return -1; } if (config.isBore()) { @@ -852,12 +865,7 @@ public class IrisObject extends IrisRegistrant { } } - if (config.getRawCommands().isNotEmpty()) { - Location l = new Location(rdata.getEngine().getWorld().realWorld(), x, y, z); - for (IrisCommand rawCommand : config.getRawCommands()) { - rawCommand.run(l); - } - } + return y; } public IrisObject rotateCopy(IrisObjectRotation rt) { @@ -884,6 +892,20 @@ public class IrisObject extends IrisRegistrant { states = dx; } + public void place(Location at) { + for (BlockVector i : getBlocks().keySet()) { + Block b = at.clone().add(0, getCenter().getY(), 0).add(i).getBlock(); + b.setBlockData(Objects.requireNonNull(getBlocks().get(i)), false); + + if (getStates().containsKey(i)) { + Iris.info(Objects.requireNonNull(states.get(i)).toString()); + BlockState st = b.getState(); + Objects.requireNonNull(getStates().get(i)).toBukkitTry(st); + st.update(); + } + } + } + public void placeCenterY(Location at) { for (BlockVector i : getBlocks().keySet()) { Block b = at.clone().add(getCenter().getX(), getCenter().getY(), getCenter().getZ()).add(i).getBlock(); diff --git a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java index ad79c6a14..923054d9b 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisObjectPlacement.java @@ -126,10 +126,6 @@ public class IrisObjectPlacement { @Desc("This object / these objects override the following trees when they grow...") @ArrayType(min = 1, type = IrisTree.class) private KList trees = new KList<>(); - @Desc("Run raw commands at the location of this object") - @ArrayType(min = 1, type = IrisCommand.class) - private KList rawCommands = new KList<>(); - private transient AtomicCache cache = new AtomicCache<>(); public IrisObjectPlacement toPlacement(String... place) { From d56a63e712db087c29f02f3f62ccd2048c2f0667 Mon Sep 17 00:00:00 2001 From: CocoTheOwner Date: Thu, 23 Sep 2021 12:23:11 +0200 Subject: [PATCH 9/9] Requested patches --- .../iris/engine/object/IrisCommand.java | 2 +- .../engine/object/IrisCommandRegistry.java | 66 +++++++++++++++++++ .../volmit/iris/engine/object/IrisEffect.java | 50 ++------------ 3 files changed, 73 insertions(+), 45 deletions(-) create mode 100644 src/main/java/com/volmit/iris/engine/object/IrisCommandRegistry.java diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCommand.java b/src/main/java/com/volmit/iris/engine/object/IrisCommand.java index af1a6bc07..008fe5d51 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisCommand.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisCommand.java @@ -15,7 +15,7 @@ import org.bukkit.Location; @Snippet("command") @Accessors(chain = true) @NoArgsConstructor -@Desc("Represents a color") +@Desc("Represents a set of Iris commands") @Data public class IrisCommand { diff --git a/src/main/java/com/volmit/iris/engine/object/IrisCommandRegistry.java b/src/main/java/com/volmit/iris/engine/object/IrisCommandRegistry.java new file mode 100644 index 000000000..dc77a1f17 --- /dev/null +++ b/src/main/java/com/volmit/iris/engine/object/IrisCommandRegistry.java @@ -0,0 +1,66 @@ +package com.volmit.iris.engine.object; + +import com.volmit.iris.engine.object.annotations.*; +import com.volmit.iris.util.collection.KList; +import com.volmit.iris.util.math.RNG; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +@Snippet("command-registry") +@Accessors(chain = true) +@NoArgsConstructor +@Desc("Represents a casting location for a command") +@Data +public class IrisCommandRegistry { + @ArrayType(min = 1, type = IrisCommand.class) + @Desc("Run commands, at the exact location of the player") + private KList rawCommands = new KList<>(); + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetX = 0; + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetY = 0; + @DependsOn({"rawCommands"}) + @MinNumber(-8) + @MaxNumber(8) + @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") + private double commandOffsetZ = 0; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altX from -altX to altX") + private boolean commandRandomAltX = true; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altY from -altY to altY") + private boolean commandRandomAltY = false; + @DependsOn({"rawCommands"}) + @Desc("Randomize the altZ from -altZ to altZ") + private boolean commandRandomAltZ = true; + @DependsOn({"rawCommands"}) + @Desc("Randomize location for all separate commands (true), or run all on the same location (false)") + private boolean commandAllRandomLocations = true; + + public void run(Player p) { + if (rawCommands.isNotEmpty()) { + Location part = p.getLocation().clone().add( + commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, + commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, + commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); + for (IrisCommand rawCommand : rawCommands) { + rawCommand.run(part); + if (commandAllRandomLocations) { + part = p.getLocation().clone().add( + commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, + commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, + commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); + } + } + } + } +} diff --git a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java index ed7c45449..8175c19f3 100644 --- a/src/main/java/com/volmit/iris/engine/object/IrisEffect.java +++ b/src/main/java/com/volmit/iris/engine/object/IrisEffect.java @@ -147,36 +147,10 @@ public class IrisEffect { @MinNumber(1) @Desc("The chance is 1 in CHANCE per interval") private int chance = 50; - @ArrayType(min = 1, type = IrisCommand.class) - @Desc("Run commands, at the exact location of the player") - private KList rawCommands = new KList<>(); - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt x, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetX = 0; - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt y, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetY = 0; - @DependsOn({"rawCommands"}) - @MinNumber(-8) - @MaxNumber(8) - @Desc("The alt z, usually represents motion if the particle count is zero. Otherwise an offset.") - private double commandOffsetZ = 0; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altX from -altX to altX") - private boolean commandRandomAltX = true; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altY from -altY to altY") - private boolean commandRandomAltY = false; - @DependsOn({"rawCommands"}) - @Desc("Randomize the altZ from -altZ to altZ") - private boolean commandRandomAltZ = true; - @DependsOn({"rawCommands"}) - @Desc("Randomize location for all separate commands (true), or run all on the same location (false)") - private boolean commandAllRandomLocations = true; + @ArrayType(min = 1, type = IrisCommandRegistry.class) + @Desc("Run commands, with configurable location parameters") + private IrisCommandRegistry commandRegistry = null; + public boolean canTick() { return latch.aquire(() -> new ChronoLatch(interval)).flip(); @@ -247,20 +221,8 @@ public class IrisEffect { } } - if (rawCommands.isNotEmpty()) { - Location part = p.getLocation().clone().add( - commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, - commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, - commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); - for (IrisCommand rawCommand : rawCommands) { - rawCommand.run(part); - if (commandAllRandomLocations) { - part = p.getLocation().clone().add( - commandRandomAltX ? RNG.r.d(-commandOffsetX, commandOffsetX) : commandOffsetX, - commandRandomAltY ? RNG.r.d(-commandOffsetY, commandOffsetY) : commandOffsetY, - commandRandomAltZ ? RNG.r.d(-commandOffsetZ, commandOffsetZ) : commandOffsetZ); - } - } + if (commandRegistry != null) { + commandRegistry.run(p); } if (potionStrength > -1) {