starts creating pixelblocks
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
package eu.mhsl.minecraft.pixelblocks;
|
||||
|
||||
import commands.ChessCommand;
|
||||
import listeners.PlayerJumpListener;
|
||||
import eu.mhsl.minecraft.pixelblocks.commands.ChessCommand;
|
||||
import eu.mhsl.minecraft.pixelblocks.commands.CreatePixelBlockCommand;
|
||||
import eu.mhsl.minecraft.pixelblocks.listeners.PlayerJumpListener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -15,6 +16,7 @@ public final class PixelBlocks extends JavaPlugin {
|
||||
this.getLogger().info("Hello World");
|
||||
getServer().getPluginManager().registerEvents(new PlayerJumpListener(), this);
|
||||
Objects.requireNonNull(getCommand("chess")).setExecutor(new ChessCommand());
|
||||
Objects.requireNonNull(getCommand("createpixelblock")).setExecutor(new CreatePixelBlockCommand());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,56 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.commands;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.BlockDisplay;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Transformation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ChessCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(sender instanceof Player p) {
|
||||
Location playerLocation = p.getLocation().toBlockLocation();
|
||||
double scale = (double) 1/16;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int finalI = i+1;
|
||||
for (int j = 0; j < 16; j++) {
|
||||
int finalJ = j+1;
|
||||
|
||||
double blockPositionX = playerLocation.x()+i*scale;
|
||||
double blockPositionY = playerLocation.y();
|
||||
double blockPositionZ = playerLocation.z()+j*scale;
|
||||
|
||||
BlockDisplay bd;
|
||||
bd = (BlockDisplay) p.getWorld().spawnEntity(
|
||||
new Location(p.getWorld(), blockPositionX, blockPositionY, blockPositionZ),
|
||||
EntityType.BLOCK_DISPLAY
|
||||
);
|
||||
|
||||
if(finalI % 2 == 0 && finalJ % 2 == 0) {
|
||||
bd.setBlock(Material.BLACK_CONCRETE.createBlockData());
|
||||
} else if(finalI % 2 != 0 && finalJ % 2 != 0) {
|
||||
bd.setBlock(Material.BLACK_CONCRETE.createBlockData());
|
||||
} else {
|
||||
bd.setBlock(Material.WHITE_CONCRETE.createBlockData());
|
||||
}
|
||||
|
||||
Transformation transform = bd.getTransformation();
|
||||
transform.getScale().set(scale);
|
||||
bd.setTransformation(transform);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
sender.sendMessage("This command is only for real Players!");
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.commands;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CreatePixelBlockCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if(sender instanceof Player p) {
|
||||
Location playerLocation = p.getLocation();
|
||||
PixelBlock pixelBlock = new PixelBlock(playerLocation, 2);
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
@EventHandler
|
||||
static void onPlayerJoin(PlayerJoinEvent event) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class PlayerJumpListener implements Listener {
|
||||
@EventHandler
|
||||
static void onPlayerJump(PlayerJumpEvent event) {
|
||||
// event.getPlayer().getWorld().spawn(event.getPlayer().getLocation(), BlockDisplay.class, blockDisplay -> {
|
||||
// blockDisplay.setBlock(Material.OAK_LOG.createBlockData());
|
||||
// });
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
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.EntityType;
|
||||
import org.bukkit.util.Transformation;
|
||||
|
||||
public class Pixel {
|
||||
Location relativeLocation;
|
||||
BlockData blockData;
|
||||
double scale;
|
||||
|
||||
public Pixel(Location relativeLocation, BlockData blockData, double scale) {
|
||||
this.relativeLocation = relativeLocation;
|
||||
this.blockData = blockData;
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
public void spawn(Location spawnLocation) {
|
||||
spawnLocation.add(relativeLocation.x()*scale, relativeLocation.y()*scale, relativeLocation.z()*scale);
|
||||
|
||||
BlockDisplay bd;
|
||||
bd = (BlockDisplay) spawnLocation.getWorld().spawnEntity(
|
||||
spawnLocation,
|
||||
EntityType.BLOCK_DISPLAY
|
||||
);
|
||||
|
||||
bd.setBlock(blockData);
|
||||
|
||||
Transformation transform = bd.getTransformation();
|
||||
transform.getScale().set(scale);
|
||||
bd.setTransformation(transform);
|
||||
|
||||
System.out.println(spawnLocation.x());
|
||||
System.out.println(spawnLocation.y());
|
||||
System.out.println(spawnLocation.z());
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.pixelblock;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PixelBlock {
|
||||
double pixelsPerBlock;
|
||||
ArrayList<Pixel> pixels = new ArrayList<>();
|
||||
|
||||
public PixelBlock(Location originLocation, double pixelsPerBlock) {
|
||||
this.pixelsPerBlock = pixelsPerBlock;
|
||||
|
||||
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);
|
||||
Material block = blockLocation.getBlock().getType();
|
||||
|
||||
if(block != Material.AIR) {
|
||||
Pixel newPixel = new Pixel(relativeLocation, block.createBlockData(), (1/pixelsPerBlock));
|
||||
pixels.add(newPixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void place(Location placeLocation) {
|
||||
placeLocation = placeLocation.toBlockLocation();
|
||||
for(Pixel pixel : pixels) {
|
||||
pixel.spawn(placeLocation);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user