mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
Object
This commit is contained in:
parent
01479a82de
commit
d241a57d38
@ -1,10 +1,14 @@
|
|||||||
package com.volmit.iris.core.decrees;
|
package com.volmit.iris.core.decrees;
|
||||||
|
|
||||||
|
import com.volmit.iris.core.command.object.CommandIrisObjectUndo;
|
||||||
|
import com.volmit.iris.core.project.loader.IrisData;
|
||||||
import com.volmit.iris.core.service.WandSVC;
|
import com.volmit.iris.core.service.WandSVC;
|
||||||
|
import com.volmit.iris.engine.object.common.IObjectPlacer;
|
||||||
import com.volmit.iris.engine.object.objects.IrisObject;
|
import com.volmit.iris.engine.object.objects.IrisObject;
|
||||||
import com.volmit.iris.engine.object.objects.IrisObjectPlacement;
|
import com.volmit.iris.engine.object.objects.IrisObjectPlacement;
|
||||||
import com.volmit.iris.engine.object.objects.IrisObjectPlacementScaleInterpolator;
|
import com.volmit.iris.engine.object.objects.IrisObjectPlacementScaleInterpolator;
|
||||||
import com.volmit.iris.engine.object.objects.IrisObjectRotation;
|
import com.volmit.iris.engine.object.objects.IrisObjectRotation;
|
||||||
|
import com.volmit.iris.engine.object.tile.TileData;
|
||||||
import com.volmit.iris.util.data.Cuboid;
|
import com.volmit.iris.util.data.Cuboid;
|
||||||
import com.volmit.iris.util.decree.DecreeExecutor;
|
import com.volmit.iris.util.decree.DecreeExecutor;
|
||||||
import com.volmit.iris.util.decree.DecreeOrigin;
|
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||||
@ -12,12 +16,14 @@ 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.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.scheduling.Queue;
|
import com.volmit.iris.util.scheduling.Queue;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.*;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.block.BlockState;
|
||||||
import org.bukkit.Sound;
|
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.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
@ -174,7 +180,8 @@ public class DecObject implements DecreeExecutor {
|
|||||||
player().setItemInHand(WandSVC.createWand(g[0], g[1]));
|
player().setItemInHand(WandSVC.createWand(g[0], g[1]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static final Set<Material> skipBlocks = Set.of(Material.GRASS, Material.SNOW, Material.VINE, Material.TORCH, Material.DEAD_BUSH,
|
||||||
|
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")
|
||||||
@ -188,19 +195,111 @@ public class DecObject implements DecreeExecutor {
|
|||||||
@Param(description = "The scale interpolator to use", defaultValue = "none")
|
@Param(description = "The scale interpolator to use", defaultValue = "none")
|
||||||
IrisObjectPlacementScaleInterpolator interpolator
|
IrisObjectPlacementScaleInterpolator interpolator
|
||||||
){
|
){
|
||||||
double maxScale = getMaxScale(object);
|
double maxScale = Double.max(10 - object.getBlocks().size() / 10000d, 1);
|
||||||
if (scale < maxScale){
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
IrisObjectPlacement placement = new IrisObjectPlacement();
|
|
||||||
placement.setRotation(IrisObjectRotation.of(0, rotate, 0));
|
|
||||||
sender().playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
|
sender().playSound(Sound.BLOCK_ENCHANTMENT_TABLE_USE, 1f, 1.5f);
|
||||||
|
|
||||||
|
IrisObjectPlacement placement = new IrisObjectPlacement();
|
||||||
|
placement.setRotation(IrisObjectRotation.of(0, rotate, 0));
|
||||||
|
|
||||||
|
ItemStack wand = player().getInventory().getItemInMainHand();
|
||||||
|
Location block = player().getTargetBlock(skipBlocks, 256).getLocation().clone().add(0, 1, 0);
|
||||||
|
|
||||||
|
Map<Block, BlockData> futureChanges = new HashMap<>();
|
||||||
|
|
||||||
|
object = object.scaled(scale, interpolator);
|
||||||
|
object.place(block.getBlockX(), block.getBlockY() + (int) object.getCenter().getY(), block.getBlockZ(), createPlacer(block.getWorld(), futureChanges), placement, new RNG(), null);
|
||||||
|
|
||||||
|
CommandIrisObjectUndo.addChanges(player(), futureChanges);
|
||||||
|
|
||||||
|
if (edit) {
|
||||||
|
ItemStack newWand = WandSVC.createWand(block.clone().subtract(object.getCenter()).add(object.getW() - 1,
|
||||||
|
object.getH() + object.getCenter().clone().getY() - 1, object.getD() - 1), block.clone().subtract(object.getCenter().clone().setY(0)));
|
||||||
|
if (WandSVC.isWand(wand)) {
|
||||||
|
wand = newWand;
|
||||||
|
player().getInventory().setItemInMainHand(wand);
|
||||||
|
sender().sendMessage("Updated wand for " + "objects/" + object.getLoadKey() + ".iob");
|
||||||
|
} else {
|
||||||
|
int slot = WandSVC.findWand(player().getInventory());
|
||||||
|
if (slot == -1) {
|
||||||
|
player().getInventory().addItem(newWand);
|
||||||
|
sender().sendMessage("Given new wand for " + "objects/" + object.getLoadKey() + ".iob");
|
||||||
|
} else {
|
||||||
|
player().getInventory().setItem(slot, newWand);
|
||||||
|
sender().sendMessage("Updated wand for " + "objects/" + object.getLoadKey() + ".iob");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender().sendMessage("Placed " + "objects/" + object.getLoadKey() + ".iob");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getMaxScale(IrisObject object){
|
public static IObjectPlacer createPlacer(World world, Map<Block, BlockData> futureBlockChanges) {
|
||||||
return Double.max(10 - object.getBlocks().size() / 10000d, 1);
|
|
||||||
|
return new IObjectPlacer() {
|
||||||
|
@Override
|
||||||
|
public int getHighest(int x, int z, IrisData data) {
|
||||||
|
return world.getHighestBlockYAt(x, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getHighest(int x, int z, IrisData data, boolean ignoreFluid) {
|
||||||
|
return world.getHighestBlockYAt(x, z, ignoreFluid ? HeightMap.OCEAN_FLOOR : HeightMap.MOTION_BLOCKING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void set(int x, int y, int z, BlockData d) {
|
||||||
|
Block block = world.getBlockAt(x, y, z);
|
||||||
|
|
||||||
|
//Prevent blocks being set in or bellow bedrock
|
||||||
|
if (y <= world.getMinHeight() || block.getType() == Material.BEDROCK) return;
|
||||||
|
|
||||||
|
futureBlockChanges.put(block, block.getBlockData());
|
||||||
|
|
||||||
|
block.setBlockData(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockData get(int x, int y, int z) {
|
||||||
|
return world.getBlockAt(x, y, z).getBlockData();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPreventingDecay() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSolid(int x, int y, int z) {
|
||||||
|
return world.getBlockAt(x, y, z).getType().isSolid();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isUnderwater(int x, int z) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getFluidHeight() {
|
||||||
|
return 63;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDebugSmartBore() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTile(int xx, int yy, int zz, TileData<? extends TileState> tile) {
|
||||||
|
BlockState state = world.getBlockAt(xx, yy, zz).getState();
|
||||||
|
tile.toBukkitTry(state);
|
||||||
|
state.update();
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user