This commit is contained in:
2024-07-06 21:53:11 +02:00
parent 47c6a01ce5
commit ccdff1ed64
7 changed files with 186 additions and 7 deletions

View File

@@ -3,15 +3,21 @@ package eu.mhsl.minecraft.pixelblocks.pixelblock;
import org.bukkit.Location;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.BlockDisplay;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.util.Transformation;
import java.util.Objects;
import java.util.UUID;
public class Pixel {
Location relativeLocation;
BlockData blockData;
double scale;
double offset;
public UUID uuid;
public Pixel(Location relativeLocation, BlockData blockData, double scale, double offset) {
this.relativeLocation = new Location(
relativeLocation.getWorld(),
@@ -41,5 +47,12 @@ public class Pixel {
Transformation transform = bd.getTransformation();
transform.getScale().set(scale);
bd.setTransformation(transform);
this.uuid = bd.getUniqueId();
}
public void remove() {
Entity pixelEntity = this.relativeLocation.getWorld().getEntity(this.uuid);
if(pixelEntity != null) pixelEntity.remove();
}
}

View File

@@ -5,31 +5,62 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Interaction;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class PixelBlock {
double pixelsPerBlock;
ArrayList<Pixel> pixels = new ArrayList<>();
public static List<PixelBlock> placedBlocks = new ArrayList<>();
public PixelBlock(Location originLocation, double pixelsPerBlock) {
public Location pixelBlockLocation;
double pixelsPerBlock;
public ArrayList<Pixel> pixels = new ArrayList<>();
public Interaction hitbox;
public static float hitboxOffset = 0.005F;
public Location lastEntryLocation;
public UUID owner;
public PixelBlock(Location originLocation, UUID owner, double pixelsPerBlock) {
PixelBlock.placedBlocks.add(this);
this.pixelBlockLocation = originLocation.toBlockLocation();
this.pixelBlockLocation.setYaw(0);
this.pixelBlockLocation.setPitch(0);
this.pixelsPerBlock = pixelsPerBlock;
this.owner = owner;
for (int x = 0; x < pixelsPerBlock; x++) {
for (int y = 0; y < pixelsPerBlock; y++) {
for (int z = 0; z < pixelsPerBlock; z++) {
Location relativeLocation = new Location(originLocation.getWorld(), x, y, z);
Location blockLocation = originLocation.toBlockLocation().clone().add(relativeLocation);
Location blockLocation = pixelBlockLocation.clone().add(relativeLocation);
BlockData block = blockLocation.getBlock().getBlockData();
if(block.getMaterial() != Material.AIR) {
Pixel newPixel = new Pixel(relativeLocation, block, (1/pixelsPerBlock)-0.0001, 0.00005);
Pixel newPixel = new Pixel(relativeLocation, block, (1/pixelsPerBlock)-0.0001, 0.00005*pixelsPerBlock);
pixels.add(newPixel);
}
}
}
}
pixelBlockLocation.getBlock().setType(Material.GLASS);
// BlockDisplay bd = (BlockDisplay) spawnLocation.getWorld().spawnEntity(
// spawnLocation,
// EntityType.BLOCK_DISPLAY
// );
hitbox = (Interaction) pixelBlockLocation.getWorld().spawnEntity(
pixelBlockLocation.clone().add(0.5, -hitboxOffset, 0.5),
EntityType.INTERACTION
);
hitbox.setInteractionHeight(1F + 2*hitboxOffset);
hitbox.setInteractionWidth(1F + 2*hitboxOffset);
}
public void place(Location placeLocation) {
@@ -39,4 +70,11 @@ public class PixelBlock {
}
});
}
public void remove() {
this.pixels.forEach(Pixel::remove);
hitbox.remove();
pixelBlockLocation.getBlock().setType(Material.AIR);
placedBlocks.remove(this);
}
}