fixed banner rotation and double bed issues,

added DestroyPixelBlocksCommand
This commit is contained in:
2025-07-14 19:32:22 +02:00
parent 36dd0535c3
commit 7a41145b8c
6 changed files with 59 additions and 8 deletions

View File

@ -4,6 +4,7 @@ import co.aikar.taskchain.BukkitTaskChainFactory;
import co.aikar.taskchain.TaskChain;
import co.aikar.taskchain.TaskChainFactory;
import eu.mhsl.minecraft.pixelblocks.commands.CreatePixelBlockCommand;
import eu.mhsl.minecraft.pixelblocks.commands.DestroyPixelBlocksCommand;
import eu.mhsl.minecraft.pixelblocks.commands.ExitWorldCommand;
import eu.mhsl.minecraft.pixelblocks.commands.GivePixelBlockCommand;
import eu.mhsl.minecraft.pixelblocks.listeners.*;
@ -85,6 +86,7 @@ public final class Main extends JavaPlugin {
Objects.requireNonNull(getCommand("createpixelblock")).setExecutor(new CreatePixelBlockCommand());
Objects.requireNonNull(getCommand("givepixelblock")).setExecutor(new GivePixelBlockCommand());
Objects.requireNonNull(getCommand("exitworld")).setExecutor(new ExitWorldCommand());
Objects.requireNonNull(getCommand("destroypixelblocks")).setExecutor(new DestroyPixelBlocksCommand());
Bukkit.addRecipe(PixelBlockItem.getRecipe());
}

View File

@ -0,0 +1,19 @@
package eu.mhsl.minecraft.pixelblocks.commands;
import eu.mhsl.minecraft.pixelblocks.Main;
import org.bukkit.Bukkit;
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 DestroyPixelBlocksCommand implements CommandExecutor {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if(sender instanceof Player p) {
Main.pixelBlocks.forEach(pixelBlock -> pixelBlock.destroy(Bukkit.getPlayer(pixelBlock.getOwnerUUID())));
}
return true;
}
}

View File

@ -1,12 +1,14 @@
package eu.mhsl.minecraft.pixelblocks.listeners;
import eu.mhsl.minecraft.pixelblocks.utils.EventCanceling;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockExplodeEvent;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
public class PreventIllegalBlocksListener implements Listener {
@EventHandler
@ -19,6 +21,13 @@ public class PreventIllegalBlocksListener implements Listener {
EventCanceling.cancelIfInPixelWorld(event, event.getLocation().getWorld());
}
@EventHandler
public void onItemFrame(HangingPlaceEvent event) {
if(event.getItemStack() == null || event.getPlayer() == null) return;
if(!(event.getItemStack().getType().equals(Material.ITEM_FRAME) || event.getItemStack().getType().equals(Material.GLOW_ITEM_FRAME))) return;
EventCanceling.cancelIfInPixelWorld(event, event.getPlayer().getWorld());
}
@EventHandler
public void onEntityDamage(EntityDamageEvent event) {
EventCanceling.cancelIfInPixelWorld(event, event.getEntity().getWorld());

View File

@ -4,8 +4,10 @@ import eu.mhsl.minecraft.pixelblocks.Main;
import eu.mhsl.minecraft.pixelblocks.utils.Direction;
import eu.mhsl.minecraft.pixelblocks.utils.LocationUtil;
import org.bukkit.*;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.BlockData;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.Rotatable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.generator.ChunkGenerator;
@ -92,7 +94,7 @@ public class PixelBlockWorld {
return getBorderOrigin().add(worldGrassBorderWidth + pixelsPerBlock, 0, worldGrassBorderWidth + pixelsPerBlock);
}
public record PixelData(Vector relativeLocation, BlockData block, @Nullable Directional directional, double scale) {
public record PixelData(Vector relativeLocation, BlockData block, @Nullable Directional directional, @Nullable Rotatable rotatable, BlockState state, double scale) {
}
public List<PixelData> getPixels(Direction direction) {
@ -116,9 +118,11 @@ public class PixelBlockWorld {
}
BlockData blockData = blockLocation.getBlock().getBlockData();
@Nullable Directional directional = blockData instanceof Directional face ? face : null;
@Nullable Rotatable rotatable = blockData instanceof Rotatable rotation ? rotation : null;
BlockState state = blockLocation.getBlock().getState();
if(!blockData.getMaterial().isEmpty()) {
pixelData.add(new PixelData(relativeLocation.toVector(), blockData, directional, (double) 1 / pixelsPerBlock));
if(!blockData.getMaterial().isAir()) {
pixelData.add(new PixelData(relativeLocation.toVector(), blockData, directional, rotatable, state, (double) 1 / pixelsPerBlock));
}
}
}

View File

@ -5,8 +5,12 @@ import eu.mhsl.minecraft.pixelblocks.utils.Direction;
import eu.mhsl.minecraft.pixelblocks.utils.ListUtil;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Banner;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.data.Directional;
import org.bukkit.block.data.Rotatable;
import org.bukkit.block.data.type.Bed;
import org.bukkit.block.data.type.Chest;
import org.bukkit.block.data.type.EnderChest;
import org.bukkit.entity.BlockDisplay;
@ -48,8 +52,9 @@ public class Pixels {
EntityType.BLOCK_DISPLAY
);
entity.setBlock(pixelData.block());
this.setEntityRotation(entity, pixelData.directional());
if(!(pixelData.directional() instanceof Bed bed && bed.getPart().equals(Bed.Part.FOOT))) entity.setBlock(pixelData.block());
this.setEntityDirection(entity, pixelData.directional());
this.setEntityRotation(entity, pixelData.rotatable(), pixelData.state());
Transformation transform = entity.getTransformation();
transform.getScale().set(pixelData.scale());
@ -76,7 +81,17 @@ public class Pixels {
.execute());
}
private void setEntityRotation(Entity entity, @Nullable Directional direction) {
private void setEntityRotation(Entity entity, @Nullable Rotatable rotatable, BlockState blockState) {
if(rotatable == null) return;
Vector rotation = rotatable.getRotation().getDirection();
float yaw = (float) Math.toDegrees(Math.atan2(rotation.getX(), -rotation.getZ()));
if(blockState instanceof Banner) yaw += 180;
entity.setRotation(entity.getYaw()+yaw, entity.getPitch());
}
private void setEntityDirection(Entity entity, @Nullable Directional direction) {
Direction blockDirection = parentBlock.getFacingDirection();
float angle = switch (blockDirection) {
case Direction.north -> 180;
@ -86,7 +101,8 @@ public class Pixels {
};
entity.setRotation(entity.getYaw()+angle, entity.getPitch());
if(!(direction instanceof EnderChest || direction instanceof Chest)) return;
if (!(direction instanceof EnderChest || direction instanceof Chest || direction instanceof Bed)) return;
BlockFace blockFace = direction.getFacing();
float yaw = switch (blockFace) {
case NORTH -> 180;

View File

@ -5,4 +5,5 @@ api-version: '1.21'
commands:
createpixelblock:
exitworld:
givepixelblock:
givepixelblock:
destroypixelblocks: