Patch object handlers

This commit is contained in:
CocoTheOwner 2021-08-19 12:37:30 +02:00
parent ce60c048f8
commit 2e661cb2f8

View File

@ -1,7 +1,6 @@
package com.volmit.iris.core.decrees; package com.volmit.iris.core.decrees;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.core.command.object.CommandIrisObjectUndo;
import com.volmit.iris.core.project.loader.IrisData; import com.volmit.iris.core.project.loader.IrisData;
import com.volmit.iris.core.service.ObjectSVC; import com.volmit.iris.core.service.ObjectSVC;
import com.volmit.iris.core.service.StudioSVC; import com.volmit.iris.core.service.StudioSVC;
@ -18,18 +17,16 @@ import com.volmit.iris.util.decree.DecreeExecutor;
import com.volmit.iris.util.decree.DecreeOrigin; import com.volmit.iris.util.decree.DecreeOrigin;
import com.volmit.iris.util.decree.annotations.Decree; import com.volmit.iris.util.decree.annotations.Decree;
import com.volmit.iris.util.decree.annotations.Param; import com.volmit.iris.util.decree.annotations.Param;
import com.volmit.iris.util.decree.specialhandlers.ObjectHandler;
import com.volmit.iris.util.format.C; import com.volmit.iris.util.format.C;
import com.volmit.iris.util.math.Direction; import com.volmit.iris.util.math.Direction;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.matter.Matter;
import com.volmit.iris.util.matter.WorldMatter;
import com.volmit.iris.util.scheduling.Queue; import com.volmit.iris.util.scheduling.Queue;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.TileState; import org.bukkit.block.TileState;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.File; import java.io.File;
@ -43,13 +40,14 @@ public class DecObject implements DecreeExecutor {
@Decree(description = "Check the composition of an object") @Decree(description = "Check the composition of an object")
public void analyze( public void analyze(
@Param(description = "The object to analyze") @Param(description = "The object to analyze", customHandler = ObjectHandler.class)
IrisObject object String object
) { ) {
sender().sendMessage("Object Size: " + object.getW() + " * " + object.getH() + " * " + object.getD() + ""); IrisObject o = IrisData.loadAnyObject(object);
sender().sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(object.getBlocks().size())); sender().sendMessage("Object Size: " + o.getW() + " * " + o.getH() + " * " + o.getD() + "");
sender().sendMessage("Blocks Used: " + NumberFormat.getIntegerInstance().format(o.getBlocks().size()));
Queue<BlockData> queue = object.getBlocks().enqueueValues(); Queue<BlockData> queue = o.getBlocks().enqueueValues();
Map<Material, Set<BlockData>> unsorted = new HashMap<>(); Map<Material, Set<BlockData>> unsorted = new HashMap<>();
Map<BlockData, Integer> amounts = new HashMap<>(); Map<BlockData, Integer> amounts = new HashMap<>();
Map<Material, Integer> materials = new HashMap<>(); Map<Material, Integer> materials = new HashMap<>();
@ -192,19 +190,21 @@ public class DecObject implements DecreeExecutor {
Material.POPPY, Material.DANDELION); Material.POPPY, Material.DANDELION);
@Decree(description = "Paste an object") @Decree(description = "Paste an object")
public void paste( public void paste(
@Param(description = "The object to paste") @Param(description = "The object to paste", customHandler = ObjectHandler.class)
IrisObject object, String object,
@Param(description = "Whether or not to edit the object (need to hold wand)", defaultValue = "false") @Param(description = "Whether or not to edit the object (need to hold wand)", defaultValue = "false")
boolean edit, boolean edit,
@Param(description = "The amount of degrees to rotate by", defaultValue = "0") @Param(description = "The amount of degrees to rotate by", defaultValue = "0")
int rotate, int rotate,
@Param(description = "The factor by which to scale the object placement", defaultValue = "1") @Param(description = "The factor by which to scale the object placement", defaultValue = "1")
double scale, double scale
@Param(description = "The scale interpolator to use", defaultValue = "none") // ,
IrisObjectPlacementScaleInterpolator interpolator // @Param(description = "The scale interpolator to use", defaultValue = "none")
// IrisObjectPlacementScaleInterpolator interpolator
){ ){
double maxScale = Double.max(10 - object.getBlocks().size() / 10000d, 1); IrisObject o = IrisData.loadAnyObject(object);
if (scale < maxScale){ double maxScale = Double.max(10 - o.getBlocks().size() / 10000d, 1);
if (scale > maxScale){
sender().sendMessage(C.YELLOW + "Indicated scale exceeds maximum. Downscaled to maximum: " + maxScale); sender().sendMessage(C.YELLOW + "Indicated scale exceeds maximum. Downscaled to maximum: " + maxScale);
scale = maxScale; scale = maxScale;
} }
@ -219,30 +219,30 @@ public class DecObject implements DecreeExecutor {
Map<Block, BlockData> futureChanges = new HashMap<>(); Map<Block, BlockData> futureChanges = new HashMap<>();
object = object.scaled(scale, interpolator); o = o.scaled(scale, IrisObjectPlacementScaleInterpolator.TRICUBIC);
object.place(block.getBlockX(), block.getBlockY() + (int) object.getCenter().getY(), block.getBlockZ(), createPlacer(block.getWorld(), futureChanges), placement, new RNG(), null); o.place(block.getBlockX(), block.getBlockY() + (int) o.getCenter().getY(), block.getBlockZ(), createPlacer(block.getWorld(), futureChanges), placement, new RNG(), null);
Iris.service(ObjectSVC.class).addChanges(futureChanges); Iris.service(ObjectSVC.class).addChanges(futureChanges);
if (edit) { if (edit) {
ItemStack newWand = WandSVC.createWand(block.clone().subtract(object.getCenter()).add(object.getW() - 1, ItemStack newWand = WandSVC.createWand(block.clone().subtract(o.getCenter()).add(o.getW() - 1,
object.getH() + object.getCenter().clone().getY() - 1, object.getD() - 1), block.clone().subtract(object.getCenter().clone().setY(0))); o.getH() + o.getCenter().clone().getY() - 1, o.getD() - 1), block.clone().subtract(o.getCenter().clone().setY(0)));
if (WandSVC.isWand(wand)) { if (WandSVC.isWand(wand)) {
wand = newWand; wand = newWand;
player().getInventory().setItemInMainHand(wand); player().getInventory().setItemInMainHand(wand);
sender().sendMessage("Updated wand for " + "objects/" + object.getLoadKey() + ".iob"); sender().sendMessage("Updated wand for " + "objects/" + o.getLoadKey() + ".iob ");
} else { } else {
int slot = WandSVC.findWand(player().getInventory()); int slot = WandSVC.findWand(player().getInventory());
if (slot == -1) { if (slot == -1) {
player().getInventory().addItem(newWand); player().getInventory().addItem(newWand);
sender().sendMessage("Given new wand for " + "objects/" + object.getLoadKey() + ".iob"); sender().sendMessage("Given new wand for " + "objects/" + o.getLoadKey() + ".iob ");
} else { } else {
player().getInventory().setItem(slot, newWand); player().getInventory().setItem(slot, newWand);
sender().sendMessage("Updated wand for " + "objects/" + object.getLoadKey() + ".iob"); sender().sendMessage("Updated wand for " + "objects/" + o.getLoadKey() + ".iob ");
} }
} }
} else { } else {
sender().sendMessage("Placed " + "objects/" + object.getLoadKey() + ".iob"); sender().sendMessage("Placed " + "objects/" + o.getLoadKey() + ".iob ");
} }
} }