removed offset, fixed hitbox

This commit is contained in:
2024-10-19 15:24:05 +02:00
parent 744f1dd6e2
commit 8a6577afa0
5 changed files with 48 additions and 59 deletions

View File

@@ -1,6 +1,7 @@
package eu.mhsl.minecraft.pixelblocks.pixelblock;
import eu.mhsl.minecraft.pixelblocks.Main;
import eu.mhsl.minecraft.pixelblocks.utils.MinMaxUtil;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Entity;
@@ -23,62 +24,61 @@ public class PixelBlockHitbox {
public void spawn() {
Location absoluteLocation = this.parentBlock.getPixelBlockLocation();
List<PixelBlockWorld.PixelData> pixels = this.parentBlock.getPixelData();
float offset = (float) Main.configuration().hitboxOffset();
int pixelsPerBlock = Main.configuration().pixelsPerBlock();
Interaction interaction;
if (pixels.size() <= 5 || true) {
if (pixels.size() <= 5) {
interaction = (Interaction) absoluteLocation.getWorld().spawnEntity(
absoluteLocation.clone().add(0.5, -offset, 0.5),
absoluteLocation.clone().add(0.5, -0, 0.5),
EntityType.INTERACTION
);
interaction.setInteractionHeight(1 + 2 * offset);
interaction.setInteractionWidth(1 + 2 * offset);
interaction.setInteractionHeight(1);
interaction.setInteractionWidth(1);
} else {
// 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 = 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 = absoluteLocation.clone().add(
// ((startingX+endingX+1)/2)/pixelsPerBlock,
// ((startingY+endingY+1)/2)/pixelsPerBlock,
// ((startingZ+endingZ+1)/2)/pixelsPerBlock
// );
double startingX = MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getX());
double startingY = MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getY());
double startingZ = MinMaxUtil.getMinProperty(pixels, pixel -> pixel.relativeLocation().getZ());
// float height = (float) (endingY-startingY+1)/pixelsPerBlock + 2*offset;
//
// float width;
// if((endingX-startingX) > (endingZ-startingZ)) {
// width = (float) (endingX-startingX+1)/pixelsPerBlock + 2*offset;
// } else {
// width = (float) (endingZ-startingZ+1)/pixelsPerBlock + 2*offset;
// }
//
// if(spawnLocation.getX()+width/2 > pixelBlockLocation.getX()+1) {
// spawnLocation.subtract((spawnLocation.getX()+width/2)-(pixelBlockLocation.getX()+1), 0, 0);
// }
// if(spawnLocation.getX()-width/2 < pixelBlockLocation.getX()) {
// spawnLocation.add(pixelBlockLocation.getX()-(spawnLocation.getX()-width/2), 0, 0);
// }
//
// if(spawnLocation.getZ()+width/2 > pixelBlockLocation.getZ()+1) {
// spawnLocation.subtract(0, 0, (spawnLocation.getZ()+width/2)-(pixelBlockLocation.getZ()+1));
// }
// if(spawnLocation.getZ()-width/2 < pixelBlockLocation.getZ()) {
// spawnLocation.add(0, 0, pixelBlockLocation.getZ()-(spawnLocation.getZ()-width/2));
// }
double endingX = MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getX());
double endingY = MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getY());
double endingZ = MinMaxUtil.getMaxProperty(pixels, pixel -> pixel.relativeLocation().getZ());
// interaction = (Interaction) absoluteLocation.getWorld().spawnEntity(
// spawnLocation,
// EntityType.INTERACTION
// );
//
// interaction.setInteractionHeight(0.5f);
// interaction.setInteractionWidth(0.5f);
Location spawnLocation = absoluteLocation.clone().add(
((startingX+endingX)/2)/pixelsPerBlock,
(startingY/pixelsPerBlock)-0,
((startingZ+endingZ)/2)/pixelsPerBlock
);
float height = (float) (endingY-startingY+1)/pixelsPerBlock;
float width;
if((endingX-startingX) > (endingZ-startingZ)) {
width = (float) (endingX-startingX+1)/pixelsPerBlock;
} else {
width = (float) (endingZ-startingZ+1)/pixelsPerBlock;
}
if(spawnLocation.getX()+width/2 > absoluteLocation.getX()+1) {
spawnLocation.subtract((spawnLocation.getX()+width/2)-(absoluteLocation.getX()+1), 0, 0);
}
if(spawnLocation.getX()-width/2 < absoluteLocation.getX()) {
spawnLocation.add(absoluteLocation.getX()-(spawnLocation.getX()-width/2), 0, 0);
}
if(spawnLocation.getZ()+width/2 > absoluteLocation.getZ()+1) {
spawnLocation.subtract(0, 0, (spawnLocation.getZ()+width/2)-(absoluteLocation.getZ()+1));
}
if(spawnLocation.getZ()-width/2 < absoluteLocation.getZ()) {
spawnLocation.add(0, 0, absoluteLocation.getZ()-(spawnLocation.getZ()-width/2));
}
interaction = (Interaction) absoluteLocation.getWorld().spawnEntity(
spawnLocation,
EntityType.INTERACTION
);
interaction.setInteractionHeight(height);
interaction.setInteractionWidth(width);
}
interaction.getPersistentDataContainer()