diff --git a/src/main/java/eu/mhsl/minecraft/pixelblocks/pixelblock/PixelBlockHitbox.java b/src/main/java/eu/mhsl/minecraft/pixelblocks/pixelblock/PixelBlockHitbox.java index 5c987ee..2d8d254 100644 --- a/src/main/java/eu/mhsl/minecraft/pixelblocks/pixelblock/PixelBlockHitbox.java +++ b/src/main/java/eu/mhsl/minecraft/pixelblocks/pixelblock/PixelBlockHitbox.java @@ -21,36 +21,34 @@ public class PixelBlockHitbox { } public void spawn() { - Location pixelBlockLocation = this.parentBlock.getPixelBlockLocation(); + Location absoluteLocation = this.parentBlock.getPixelBlockLocation(); List pixels = this.parentBlock.getPixelData(); - double scale = pixels.getFirst().scale(); - float offset = (float) Main.configuration().hitboxOffset(); int pixelsPerBlock = Main.configuration().pixelsPerBlock(); Interaction interaction; - if(true) { - interaction = (Interaction) pixelBlockLocation.getWorld().spawnEntity( - pixelBlockLocation.clone().add(0.5, -offset, 0.5), + if (pixels.size() <= 5 || true) { + interaction = (Interaction) absoluteLocation.getWorld().spawnEntity( + absoluteLocation.clone().add(0.5, -offset, 0.5), EntityType.INTERACTION ); interaction.setInteractionHeight(1 + 2 * offset); interaction.setInteractionWidth(1 + 2 * offset); } else { -// double startingX = this.parentBlock.getPixelBlockLocation().x() + MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getX()) * scale; -// double startingY = this.parentBlock.getPixelBlockLocation().y() + MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getY()) * scale; -// double startingZ = this.parentBlock.getPixelBlockLocation().z() + MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getZ()) * scale; +// double startingX = absoluteLocation.x() + MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getX()); +// double startingY = absoluteLocation.y() + MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getY()); +// double startingZ = absoluteLocation.z() + MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getZ()); // -// double endingX = this.parentBlock.getPixelBlockLocation().x() + MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getX()) * scale; -// double endingY = this.parentBlock.getPixelBlockLocation().y() + MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getY()) * scale; -// double endingZ = this.parentBlock.getPixelBlockLocation().z() + MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getZ()) * scale; +// double endingX = absoluteLocation.x() + MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getX()); +// double endingY = absoluteLocation.y() + MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getY()); +// double endingZ = absoluteLocation.z() + MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getZ()); // -// Location spawnLocation = pixelBlockLocation.clone().add( +// Location spawnLocation = absoluteLocation.clone().add( // ((startingX+endingX+1)/2)/pixelsPerBlock, -// (startingY/pixelsPerBlock)-offset, +// ((startingY+endingY+1)/2)/pixelsPerBlock, // ((startingZ+endingZ+1)/2)/pixelsPerBlock // ); -// + // float height = (float) (endingY-startingY+1)/pixelsPerBlock + 2*offset; // // float width; @@ -73,20 +71,21 @@ public class PixelBlockHitbox { // if(spawnLocation.getZ()-width/2 < pixelBlockLocation.getZ()) { // spawnLocation.add(0, 0, pixelBlockLocation.getZ()-(spawnLocation.getZ()-width/2)); // } -// -// interaction = (Interaction) pixelBlockLocation.getWorld().spawnEntity( + +// interaction = (Interaction) absoluteLocation.getWorld().spawnEntity( // spawnLocation, // EntityType.INTERACTION // ); // -// interaction.setInteractionHeight(height); -// interaction.setInteractionWidth(width); +// interaction.setInteractionHeight(0.5f); +// interaction.setInteractionWidth(0.5f); } interaction.getPersistentDataContainer() .set(hitboxOfTag, PersistentDataType.STRING, this.parentBlock.getBlockUUID().toString()); } + public void destroy() { this.parentBlock.getPixelBlockLocation().getNearbyEntitiesByType(Interaction.class, 1) .stream() @@ -95,9 +94,6 @@ public class PixelBlockHitbox { interaction.getPersistentDataContainer().get(hitboxOfTag, PersistentDataType.STRING), parentBlock.getBlockUUID().toString() )) - .reduce((a, b) -> { - throw new IllegalStateException(String.format("Mehrere hitboxen für PixelBlock '%s' gefunden!", parentBlock.getBlockUUID())); - }) - .ifPresent(Entity::remove); + .forEach(Entity::remove); } } diff --git a/src/main/java/eu/mhsl/minecraft/pixelblocks/pixelblock/PixelBlockWorld.java b/src/main/java/eu/mhsl/minecraft/pixelblocks/pixelblock/PixelBlockWorld.java index fa55aea..4521494 100644 --- a/src/main/java/eu/mhsl/minecraft/pixelblocks/pixelblock/PixelBlockWorld.java +++ b/src/main/java/eu/mhsl/minecraft/pixelblocks/pixelblock/PixelBlockWorld.java @@ -179,23 +179,26 @@ public class PixelBlockWorld { LocationUtil.iterateBlocks(getPlatformOrigin().add(1, 1, 1), getPlatformOriginEnd().add(0, 1, 0), location -> { if(allowPlacements(location)) return; if(!location.clone().subtract(0, 1, 0).getBlock().getType().equals(Material.GRASS_BLOCK)) return; + + List flowers = List.of( + Material.DANDELION, + Material.POPPY, + Material.BLUE_ORCHID, + Material.ALLIUM, + Material.AZURE_BLUET, + Material.RED_TULIP, + Material.ORANGE_TULIP, + Material.WHITE_TULIP, + Material.CORNFLOWER, + Material.LILY_OF_THE_VALLEY, + Material.SHORT_GRASS, + Material.TALL_GRASS + ); + if(flowers.contains(location.getBlock().getType())) location.getBlock().setType(Material.AIR); if(!location.getBlock().getType().equals(Material.AIR)) return; - if(random.nextInt(10) == 0) { - Material[] flowers = { - Material.DANDELION, - Material.POPPY, - Material.BLUE_ORCHID, - Material.ALLIUM, - Material.AZURE_BLUET, - Material.RED_TULIP, - Material.ORANGE_TULIP, - Material.WHITE_TULIP, - Material.CORNFLOWER, - Material.LILY_OF_THE_VALLEY, - }; - - Material randomFlower = flowers[random.nextInt(flowers.length)]; + if(random.nextInt(30) == 0) { + Material randomFlower = flowers.get(random.nextInt(flowers.size())); location.getBlock().setType(randomFlower); } });