3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 22:40:18 +01:00

Disable collision box & selection box when box is empty

Fix incorrect collision names used in CustomBlockComponentsBuilder
Dieser Commit ist enthalten in:
davchoo 2022-07-25 15:59:24 -04:00
Ursprung e9e89b4b5c
Commit cb0b52b997
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: A0168C8E45799B7D
5 geänderte Dateien mit 35 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -27,4 +27,10 @@ package org.geysermc.geyser.api.block.custom.component;
public record BoxComponent(float originX, float originY, float originZ,
float sizeX, float sizeY, float sizeZ) {
public static final BoxComponent FULL_BLOCK = new BoxComponent(-8, 0, -8, 16, 16, 16);
public static final BoxComponent EMPTY_BOX = new BoxComponent(0, 0, 0, 0, 0, 0);
public boolean isEmpty() {
return sizeX == 0 && sizeY == 0 && sizeZ == 0;
}
}

Datei anzeigen

@ -47,9 +47,9 @@ public interface CustomBlockComponents {
RotationComponent rotation();
interface Builder {
Builder aimCollision(BoxComponent aimCollision);
Builder selectionBox(BoxComponent selectionBox);
Builder entityCollision(BoxComponent entityCollision);
Builder collisionBox(BoxComponent collisionBox);
Builder geometry(String geometry);

Datei anzeigen

@ -33,8 +33,8 @@ import org.geysermc.geyser.api.block.custom.component.RotationComponent;
import java.util.Map;
public class GeyserCustomBlockComponents implements CustomBlockComponents {
private final BoxComponent aimCollision;
private final BoxComponent entityCollision;
private final BoxComponent selectionBox;
private final BoxComponent collisionBox;
private final String geometry;
private final Map<String, MaterialInstance> materialInstances;
private final Float destroyTime;
@ -44,8 +44,8 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
private final RotationComponent rotation;
private GeyserCustomBlockComponents(CustomBlockComponentsBuilder builder) {
this.aimCollision = builder.aimCollision;
this.entityCollision = builder.entityCollision;
this.selectionBox = builder.selectionBox;
this.collisionBox = builder.collisionBox;
this.geometry = builder.geometry;
this.materialInstances = builder.materialInstances;
this.destroyTime = builder.destroyTime;
@ -57,12 +57,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
@Override
public BoxComponent selectionBox() {
return aimCollision;
return selectionBox;
}
@Override
public BoxComponent collisionBox() {
return entityCollision;
return collisionBox;
}
@Override
@ -101,8 +101,8 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
}
public static class CustomBlockComponentsBuilder implements Builder {
protected BoxComponent aimCollision;
protected BoxComponent entityCollision;
protected BoxComponent selectionBox;
protected BoxComponent collisionBox;
protected String geometry;
protected Map<String, MaterialInstance> materialInstances;
protected Float destroyTime;
@ -112,14 +112,14 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
protected RotationComponent rotation;
@Override
public Builder aimCollision(BoxComponent aimCollision) {
this.aimCollision = aimCollision;
public Builder selectionBox(BoxComponent selectionBox) {
this.selectionBox = selectionBox;
return this;
}
@Override
public Builder entityCollision(BoxComponent entityCollision) {
this.entityCollision = entityCollision;
public Builder collisionBox(BoxComponent collisionBox) {
this.collisionBox = collisionBox;
return this;
}

Datei anzeigen

@ -336,31 +336,21 @@ public class BlockRegistryPopulator {
}
NbtMapBuilder builder = NbtMap.builder();
if (components.selectionBox() != null) {
BoxComponent selectionBox = components.selectionBox();
builder.putCompound("minecraft:aim_collision", NbtMap.builder()
.putBoolean("enabled", true)
.putList("origin", NbtType.FLOAT, selectionBox.originX(), selectionBox.originY(), selectionBox.originZ())
.putList("size", NbtType.FLOAT, selectionBox.sizeX(), selectionBox.sizeY(), selectionBox.sizeZ())
.build());
builder.putCompound("minecraft:aim_collision", convertBox(components.selectionBox()));
}
if (components.collisionBox() != null) {
BoxComponent collisionBox = components.collisionBox();
String tagName = "minecraft:block_collision";
if (protocolVersion >= Bedrock_v534.V534_CODEC.getProtocolVersion()) {
tagName = "minecraft:collision_box";
}
builder.putCompound(tagName, NbtMap.builder()
.putBoolean("enabled", true)
.putList("origin", NbtType.FLOAT, collisionBox.originX(), collisionBox.originY(), collisionBox.originZ())
.putList("size", NbtType.FLOAT, collisionBox.sizeX(), collisionBox.sizeY(), collisionBox.sizeZ())
.build());
builder.putCompound(tagName, convertBox(components.collisionBox()));
}
if (components.geometry() != null) {
builder.putCompound("minecraft:geometry", NbtMap.builder()
.putString("value", components.geometry())
.build());
}
if (components.materialInstances() != null) {
if (components.materialInstances() != null && !components.materialInstances().isEmpty()) {
NbtMapBuilder materialsBuilder = NbtMap.builder();
for (Map.Entry<String, MaterialInstance> entry : components.materialInstances().entrySet()) {
MaterialInstance materialInstance = entry.getValue();
@ -406,6 +396,14 @@ public class BlockRegistryPopulator {
return builder.build();
}
private static NbtMap convertBox(BoxComponent boxComponent) {
return NbtMap.builder()
.putBoolean("enabled", !boxComponent.isEmpty())
.putList("origin", NbtType.FLOAT, boxComponent.originX(), boxComponent.originY(), boxComponent.originZ())
.putList("size", NbtType.FLOAT, boxComponent.sizeX(), boxComponent.sizeY(), boxComponent.sizeZ())
.build();
}
private static void registerJavaBlocks() {
JsonNode blocksJson;
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/blocks.json")) {

Datei anzeigen

@ -131,8 +131,8 @@ public class CustomSkull {
for (int i = 0; i < 4; i++) {
int floorRotation = 4 * quadrant + i;
CustomBlockComponents components = new GeyserCustomBlockComponents.CustomBlockComponentsBuilder()
.aimCollision(box)
.entityCollision(box)
.selectionBox(box)
.collisionBox(box)
.geometry("geometry.geyser.player_skull_floor_" + quadrantNames[i])
.rotation(rotation)
.build();
@ -159,8 +159,8 @@ public class CustomSkull {
String condition = String.format("query.block_property('%s') == %d && query.block_property('%s') == %d", BITS_A_PROPERTY, i + 1, BITS_B_PROPERTY, 0);
CustomBlockComponents components = new GeyserCustomBlockComponents.CustomBlockComponentsBuilder()
.aimCollision(box)
.entityCollision(box)
.selectionBox(box)
.collisionBox(box)
.geometry("geometry.geyser.player_skull_wall")
.rotation(rotation)
.build();