added rotation
This commit is contained in:
parent
315750475a
commit
e48413d111
@ -1,5 +1,6 @@
|
||||
package eu.mhsl.minecraft.pixelblocks;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.Direction;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -63,8 +64,8 @@ public class DataBase {
|
||||
PreparedStatement prep = conn.prepareStatement(
|
||||
"INSERT INTO pixelblocks(uuid, owner, " +
|
||||
"locationWorldName, locationX, locationY, locationZ, " +
|
||||
"entryLocationWorldName, entryLocationX, entryLocationY, entryLocationZ) " +
|
||||
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
|
||||
"entryLocationWorldName, entryLocationX, entryLocationY, entryLocationZ, direction) " +
|
||||
"VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"
|
||||
);
|
||||
prep.setString(1, pixelBlock.uuid.toString());
|
||||
prep.setString(2, pixelBlock.ownerUID.toString());
|
||||
@ -86,6 +87,8 @@ public class DataBase {
|
||||
prep.setDouble(10, Bukkit.getWorlds().getFirst().getSpawnLocation().getZ());
|
||||
}
|
||||
|
||||
prep.setString(11, pixelBlock.direction.toString());
|
||||
|
||||
prep.executeUpdate();
|
||||
prep.close();
|
||||
} catch (SQLException e) {
|
||||
@ -97,7 +100,7 @@ public class DataBase {
|
||||
PreparedStatement prep = conn.prepareStatement(
|
||||
"UPDATE pixelblocks " +
|
||||
"SET owner=?, locationWorldName=?, locationX=?, locationY=?, locationZ=?," +
|
||||
"entryLocationWorldName=?, entryLocationX=?, entryLocationY=?, entryLocationZ=? " +
|
||||
"entryLocationWorldName=?, entryLocationX=?, entryLocationY=?, entryLocationZ=?, direction=? " +
|
||||
"WHERE uuid=?;"
|
||||
);
|
||||
prep.setString(1, pixelBlock.ownerUID.toString());
|
||||
@ -120,6 +123,7 @@ public class DataBase {
|
||||
}
|
||||
|
||||
prep.setString(10, pixelBlock.uuid.toString());
|
||||
prep.setString(11, pixelBlock.direction.toString());
|
||||
|
||||
prep.executeUpdate();
|
||||
prep.close();
|
||||
@ -152,7 +156,8 @@ public class DataBase {
|
||||
"entryLocationWorldName CHAR(36), " +
|
||||
"entryLocationX DOUBLE, " +
|
||||
"entryLocationY DOUBLE, " +
|
||||
"entryLocationZ DOUBLE" +
|
||||
"entryLocationZ DOUBLE, " +
|
||||
"direction CHAR(36)" +
|
||||
");";
|
||||
|
||||
try (var statement = getStatement()) {
|
||||
@ -193,7 +198,7 @@ public class DataBase {
|
||||
UUID.fromString(pixelBlocksResult.getString("uuid"))
|
||||
);
|
||||
newPixelBlock.lastEntryLocation = newEntryLocation;
|
||||
newPixelBlock.place(newPixelBlockLocation);
|
||||
newPixelBlock.place(newPixelBlockLocation, Direction.valueOf(pixelBlocksResult.getString("direction")));
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.commands;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.Direction;
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -23,7 +24,7 @@ public class CreatePixelBlockCommand implements CommandExecutor {
|
||||
if(Arrays.stream(standardWorlds).toList().contains(playerWorld)) {
|
||||
Location playerLocation = p.getLocation();
|
||||
PixelBlock pixelBlock = new PixelBlock(playerLocation, p.getUniqueId(), UUID.randomUUID());
|
||||
pixelBlock.place(playerLocation);
|
||||
pixelBlock.place(playerLocation, Direction.POSITIVE_Z);
|
||||
} else {
|
||||
p.sendMessage("Du kannst nur in der Overworld oder im Nether Pixelblocks erstellen!");
|
||||
}
|
||||
|
@ -33,8 +33,9 @@ public class BlockPlaceListener implements Listener {
|
||||
}
|
||||
|
||||
PixelBlock pixelBlock = new PixelBlock(newBlockLocation, event.getPlayer().getUniqueId(), UUID.fromString(event.getItemInHand().getItemMeta().getItemName()));
|
||||
if(pixelBlock.place(newBlockLocation)) {
|
||||
if(pixelBlock.place(newBlockLocation, PixelBlock.vectorToDirection(event.getPlayer().getLocation().getDirection()))) {
|
||||
event.getPlayer().getInventory().remove(event.getItemInHand());
|
||||
System.out.println(event.getPlayer().getLocation().getDirection());
|
||||
} else {
|
||||
event.getPlayer().sendMessage("Hier wurde bereits ein Pixelblock plaziert.");
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.pixelblock;
|
||||
|
||||
public enum Direction {
|
||||
POSITIVE_X,
|
||||
POSITIVE_Z,
|
||||
NEGATIVE_X,
|
||||
NEGATIVE_Z
|
||||
}
|
@ -9,6 +9,7 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.codehaus.plexus.util.FileUtils;
|
||||
|
||||
import java.io.File;
|
||||
@ -16,6 +17,7 @@ import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static eu.mhsl.minecraft.pixelblocks.PixelBlocks.*;
|
||||
import static java.lang.Math.abs;
|
||||
|
||||
public class PixelBlock {
|
||||
public static List<PixelBlock> placedPixelBlocks = new ArrayList<>();
|
||||
@ -25,6 +27,7 @@ public class PixelBlock {
|
||||
public static boolean liveUpdate = true;
|
||||
|
||||
public Location pixelBlockLocation;
|
||||
public Direction direction;
|
||||
public ArrayList<Pixel> pixels = new ArrayList<>();
|
||||
public Interaction hitbox;
|
||||
public ItemDisplay barrier;
|
||||
@ -38,6 +41,7 @@ public class PixelBlock {
|
||||
this.uuid = blockUUID;
|
||||
|
||||
this.pixelBlockLocation = originLocation.toBlockLocation();
|
||||
this.direction = Direction.POSITIVE_Z;
|
||||
this.pixelBlockLocation.setYaw(0);
|
||||
this.pixelBlockLocation.setPitch(0);
|
||||
this.ownerUID = ownerUID;
|
||||
@ -76,6 +80,22 @@ public class PixelBlock {
|
||||
return plugin.getDataFolder().getPath() + pathSeparator + pixelBlock.uuid.toString();
|
||||
}
|
||||
|
||||
public static Direction vectorToDirection(Vector vector) {
|
||||
if(abs(vector.getX()) > abs(vector.getZ())) {
|
||||
if(vector.getX() >= 0) {
|
||||
return Direction.POSITIVE_X;
|
||||
} else {
|
||||
return Direction.NEGATIVE_X;
|
||||
}
|
||||
} else {
|
||||
if(vector.getZ() >= 0) {
|
||||
return Direction.POSITIVE_Z;
|
||||
} else {
|
||||
return Direction.NEGATIVE_Z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void createPixelWorld() {
|
||||
File file = new File(getWorldPathFromPixelblock(this));
|
||||
@ -327,8 +347,13 @@ public class PixelBlock {
|
||||
Location blockLocation = Objects.requireNonNull(Bukkit
|
||||
.getWorld(getWorldPathFromPixelblock(this)))
|
||||
.getSpawnLocation()
|
||||
.clone()
|
||||
.add(relativeLocation.x(), relativeLocation.y(), relativeLocation.z());
|
||||
.clone();
|
||||
switch (this.direction) {
|
||||
case POSITIVE_Z -> blockLocation.add(relativeLocation.x(), relativeLocation.y(), relativeLocation.z());
|
||||
case NEGATIVE_Z -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.x(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.z());
|
||||
case POSITIVE_X -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.z(), relativeLocation.y(), relativeLocation.x());
|
||||
case NEGATIVE_X -> blockLocation.add(relativeLocation.z(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.x());
|
||||
}
|
||||
BlockData block = blockLocation.getBlock().getBlockData();
|
||||
|
||||
if(block.getMaterial() != Material.AIR) {
|
||||
@ -407,13 +432,14 @@ public class PixelBlock {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean place(Location placeLocation) {
|
||||
public boolean place(Location placeLocation, Direction direction) {
|
||||
Location newLocation = placeLocation.toBlockLocation();
|
||||
newLocation.setPitch(0);
|
||||
newLocation.setYaw(0);
|
||||
|
||||
if(PixelBlock.getPixelBlockFromLocation(newLocation) == null || PixelBlock.getPixelBlockFromLocation(newLocation) == this) {
|
||||
this.pixelBlockLocation = newLocation;
|
||||
this.direction = direction;
|
||||
update();
|
||||
dataBase.savePixelBlock(this);
|
||||
placedPixelBlocks.add(this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user