working pixelblocks

This commit is contained in:
Lars Neuhaus 2024-07-06 13:36:22 +02:00
parent 47e0176600
commit de14aaa79d
3 changed files with 17 additions and 9 deletions

View File

@ -13,10 +13,8 @@ public class CreatePixelBlockCommand implements CommandExecutor {
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(sender instanceof Player p) { if(sender instanceof Player p) {
Location playerLocation = p.getLocation(); Location playerLocation = p.getLocation();
PixelBlock pixelBlock = new PixelBlock(playerLocation, 2); PixelBlock pixelBlock = new PixelBlock(playerLocation, 16);
pixelBlock.place(playerLocation); pixelBlock.place(playerLocation);
// Pixel pixel = new Pixel(new Location(p.getWorld(), 0, 0, 0), Material.COMMAND_BLOCK.createBlockData(), 0.5);
// pixel.spawn(playerLocation);
} }
return true; return true;

View File

@ -12,13 +12,22 @@ public class Pixel {
double scale; double scale;
public Pixel(Location relativeLocation, BlockData blockData, double scale) { public Pixel(Location relativeLocation, BlockData blockData, double scale) {
this.relativeLocation = relativeLocation; this.relativeLocation = new Location(
relativeLocation.getWorld(),
relativeLocation.x(),
relativeLocation.y(),
relativeLocation.z()
);
this.blockData = blockData; this.blockData = blockData;
this.scale = scale; this.scale = scale;
} }
public void spawn(Location spawnLocation) { public void spawn(Location spawnBlockLocation) {
spawnLocation.add(relativeLocation.x()*scale, relativeLocation.y()*scale, relativeLocation.z()*scale); double positionX = spawnBlockLocation.x()+relativeLocation.x()*scale;
double positionY = spawnBlockLocation.y()+relativeLocation.y()*scale;
double positionZ = spawnBlockLocation.z()+relativeLocation.z()*scale;
Location spawnLocation = new Location(spawnBlockLocation.getWorld(), positionX, positionY, positionZ);
BlockDisplay bd; BlockDisplay bd;
bd = (BlockDisplay) spawnLocation.getWorld().spawnEntity( bd = (BlockDisplay) spawnLocation.getWorld().spawnEntity(

View File

@ -2,6 +2,7 @@ package eu.mhsl.minecraft.pixelblocks.pixelblock;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import java.util.ArrayList; import java.util.ArrayList;
@ -17,10 +18,10 @@ public class PixelBlock {
for (int z = 0; z < pixelsPerBlock; z++) { for (int z = 0; z < pixelsPerBlock; z++) {
Location relativeLocation = new Location(originLocation.getWorld(), x, y, z); Location relativeLocation = new Location(originLocation.getWorld(), x, y, z);
Location blockLocation = originLocation.toBlockLocation().clone().add(relativeLocation); Location blockLocation = originLocation.toBlockLocation().clone().add(relativeLocation);
Material block = blockLocation.getBlock().getType(); BlockData block = blockLocation.getBlock().getBlockData();
if(block != Material.AIR) { if(block.getMaterial() != Material.AIR) {
Pixel newPixel = new Pixel(relativeLocation, block.createBlockData(), (1/pixelsPerBlock)); Pixel newPixel = new Pixel(relativeLocation, block, (1/pixelsPerBlock));
pixels.add(newPixel); pixels.add(newPixel);
} }
} }