starts creating pixelblocks
This commit is contained in:
parent
69f8a05bed
commit
47e0176600
.idea/modules
src/main
4
.idea/modules/PixelBlocks.main.iml
generated
4
.idea/modules/PixelBlocks.main.iml
generated
@ -11,8 +11,4 @@
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -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
|
||||
|
@ -1,4 +1,4 @@
|
||||
package commands;
|
||||
package eu.mhsl.minecraft.pixelblocks.commands;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package listeners;
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package listeners;
|
||||
|
||||
import com.destroystokyo.paper.event.player.PlayerJumpEvent;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.BlockDisplay;
|
||||
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());
|
||||
});
|
||||
|
||||
}
|
||||
}
|
@ -4,3 +4,4 @@ main: eu.mhsl.minecraft.pixelblocks.PixelBlocks
|
||||
api-version: '1.21'
|
||||
commands:
|
||||
chess:
|
||||
createpixelblock:
|
||||
|
Loading…
x
Reference in New Issue
Block a user