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:
Ursprung
e9e89b4b5c
Commit
cb0b52b997
@ -27,4 +27,10 @@ package org.geysermc.geyser.api.block.custom.component;
|
|||||||
|
|
||||||
public record BoxComponent(float originX, float originY, float originZ,
|
public record BoxComponent(float originX, float originY, float originZ,
|
||||||
float sizeX, float sizeY, float sizeZ) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,9 @@ public interface CustomBlockComponents {
|
|||||||
RotationComponent rotation();
|
RotationComponent rotation();
|
||||||
|
|
||||||
interface Builder {
|
interface Builder {
|
||||||
Builder aimCollision(BoxComponent aimCollision);
|
Builder selectionBox(BoxComponent selectionBox);
|
||||||
|
|
||||||
Builder entityCollision(BoxComponent entityCollision);
|
Builder collisionBox(BoxComponent collisionBox);
|
||||||
|
|
||||||
Builder geometry(String geometry);
|
Builder geometry(String geometry);
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ import org.geysermc.geyser.api.block.custom.component.RotationComponent;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class GeyserCustomBlockComponents implements CustomBlockComponents {
|
public class GeyserCustomBlockComponents implements CustomBlockComponents {
|
||||||
private final BoxComponent aimCollision;
|
private final BoxComponent selectionBox;
|
||||||
private final BoxComponent entityCollision;
|
private final BoxComponent collisionBox;
|
||||||
private final String geometry;
|
private final String geometry;
|
||||||
private final Map<String, MaterialInstance> materialInstances;
|
private final Map<String, MaterialInstance> materialInstances;
|
||||||
private final Float destroyTime;
|
private final Float destroyTime;
|
||||||
@ -44,8 +44,8 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
|
|||||||
private final RotationComponent rotation;
|
private final RotationComponent rotation;
|
||||||
|
|
||||||
private GeyserCustomBlockComponents(CustomBlockComponentsBuilder builder) {
|
private GeyserCustomBlockComponents(CustomBlockComponentsBuilder builder) {
|
||||||
this.aimCollision = builder.aimCollision;
|
this.selectionBox = builder.selectionBox;
|
||||||
this.entityCollision = builder.entityCollision;
|
this.collisionBox = builder.collisionBox;
|
||||||
this.geometry = builder.geometry;
|
this.geometry = builder.geometry;
|
||||||
this.materialInstances = builder.materialInstances;
|
this.materialInstances = builder.materialInstances;
|
||||||
this.destroyTime = builder.destroyTime;
|
this.destroyTime = builder.destroyTime;
|
||||||
@ -57,12 +57,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BoxComponent selectionBox() {
|
public BoxComponent selectionBox() {
|
||||||
return aimCollision;
|
return selectionBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BoxComponent collisionBox() {
|
public BoxComponent collisionBox() {
|
||||||
return entityCollision;
|
return collisionBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -101,8 +101,8 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class CustomBlockComponentsBuilder implements Builder {
|
public static class CustomBlockComponentsBuilder implements Builder {
|
||||||
protected BoxComponent aimCollision;
|
protected BoxComponent selectionBox;
|
||||||
protected BoxComponent entityCollision;
|
protected BoxComponent collisionBox;
|
||||||
protected String geometry;
|
protected String geometry;
|
||||||
protected Map<String, MaterialInstance> materialInstances;
|
protected Map<String, MaterialInstance> materialInstances;
|
||||||
protected Float destroyTime;
|
protected Float destroyTime;
|
||||||
@ -112,14 +112,14 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
|
|||||||
protected RotationComponent rotation;
|
protected RotationComponent rotation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder aimCollision(BoxComponent aimCollision) {
|
public Builder selectionBox(BoxComponent selectionBox) {
|
||||||
this.aimCollision = aimCollision;
|
this.selectionBox = selectionBox;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder entityCollision(BoxComponent entityCollision) {
|
public Builder collisionBox(BoxComponent collisionBox) {
|
||||||
this.entityCollision = entityCollision;
|
this.collisionBox = collisionBox;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -336,31 +336,21 @@ public class BlockRegistryPopulator {
|
|||||||
}
|
}
|
||||||
NbtMapBuilder builder = NbtMap.builder();
|
NbtMapBuilder builder = NbtMap.builder();
|
||||||
if (components.selectionBox() != null) {
|
if (components.selectionBox() != null) {
|
||||||
BoxComponent selectionBox = components.selectionBox();
|
builder.putCompound("minecraft:aim_collision", convertBox(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());
|
|
||||||
}
|
}
|
||||||
if (components.collisionBox() != null) {
|
if (components.collisionBox() != null) {
|
||||||
BoxComponent collisionBox = components.collisionBox();
|
|
||||||
String tagName = "minecraft:block_collision";
|
String tagName = "minecraft:block_collision";
|
||||||
if (protocolVersion >= Bedrock_v534.V534_CODEC.getProtocolVersion()) {
|
if (protocolVersion >= Bedrock_v534.V534_CODEC.getProtocolVersion()) {
|
||||||
tagName = "minecraft:collision_box";
|
tagName = "minecraft:collision_box";
|
||||||
}
|
}
|
||||||
builder.putCompound(tagName, NbtMap.builder()
|
builder.putCompound(tagName, convertBox(components.collisionBox()));
|
||||||
.putBoolean("enabled", true)
|
|
||||||
.putList("origin", NbtType.FLOAT, collisionBox.originX(), collisionBox.originY(), collisionBox.originZ())
|
|
||||||
.putList("size", NbtType.FLOAT, collisionBox.sizeX(), collisionBox.sizeY(), collisionBox.sizeZ())
|
|
||||||
.build());
|
|
||||||
}
|
}
|
||||||
if (components.geometry() != null) {
|
if (components.geometry() != null) {
|
||||||
builder.putCompound("minecraft:geometry", NbtMap.builder()
|
builder.putCompound("minecraft:geometry", NbtMap.builder()
|
||||||
.putString("value", components.geometry())
|
.putString("value", components.geometry())
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if (components.materialInstances() != null) {
|
if (components.materialInstances() != null && !components.materialInstances().isEmpty()) {
|
||||||
NbtMapBuilder materialsBuilder = NbtMap.builder();
|
NbtMapBuilder materialsBuilder = NbtMap.builder();
|
||||||
for (Map.Entry<String, MaterialInstance> entry : components.materialInstances().entrySet()) {
|
for (Map.Entry<String, MaterialInstance> entry : components.materialInstances().entrySet()) {
|
||||||
MaterialInstance materialInstance = entry.getValue();
|
MaterialInstance materialInstance = entry.getValue();
|
||||||
@ -406,6 +396,14 @@ public class BlockRegistryPopulator {
|
|||||||
return builder.build();
|
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() {
|
private static void registerJavaBlocks() {
|
||||||
JsonNode blocksJson;
|
JsonNode blocksJson;
|
||||||
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/blocks.json")) {
|
try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/blocks.json")) {
|
||||||
|
@ -131,8 +131,8 @@ public class CustomSkull {
|
|||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
int floorRotation = 4 * quadrant + i;
|
int floorRotation = 4 * quadrant + i;
|
||||||
CustomBlockComponents components = new GeyserCustomBlockComponents.CustomBlockComponentsBuilder()
|
CustomBlockComponents components = new GeyserCustomBlockComponents.CustomBlockComponentsBuilder()
|
||||||
.aimCollision(box)
|
.selectionBox(box)
|
||||||
.entityCollision(box)
|
.collisionBox(box)
|
||||||
.geometry("geometry.geyser.player_skull_floor_" + quadrantNames[i])
|
.geometry("geometry.geyser.player_skull_floor_" + quadrantNames[i])
|
||||||
.rotation(rotation)
|
.rotation(rotation)
|
||||||
.build();
|
.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);
|
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()
|
CustomBlockComponents components = new GeyserCustomBlockComponents.CustomBlockComponentsBuilder()
|
||||||
.aimCollision(box)
|
.selectionBox(box)
|
||||||
.entityCollision(box)
|
.collisionBox(box)
|
||||||
.geometry("geometry.geyser.player_skull_wall")
|
.geometry("geometry.geyser.player_skull_wall")
|
||||||
.rotation(rotation)
|
.rotation(rotation)
|
||||||
.build();
|
.build();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren