Add display name component and add toggle for client block placing

The display name component allows blocks to use other locale keys.
placeAir will prevent the client from placing the default block state.
This commit is contained in:
davchoo 2022-12-23 11:16:50 -05:00
parent f495c8522d
commit 8f7d67bde0
No known key found for this signature in database
GPG key ID: 501B6F4FD961CF9A
4 changed files with 40 additions and 0 deletions

View file

@ -33,6 +33,7 @@ public interface CustomBlockComponents {
BoxComponent selectionBox();
BoxComponent collisionBox();
String displayName();
String geometry();
@ -48,11 +49,15 @@ public interface CustomBlockComponents {
RotationComponent rotation();
boolean placeAir();
interface Builder {
Builder selectionBox(BoxComponent selectionBox);
Builder collisionBox(BoxComponent collisionBox);
Builder displayName(String displayName);
Builder geometry(String geometry);
Builder materialInstance(@NonNull String name, @NonNull MaterialInstance materialInstance);
@ -67,6 +72,8 @@ public interface CustomBlockComponents {
Builder rotation(RotationComponent rotation);
Builder placeAir(boolean placeAir);
CustomBlockComponents build();
}
}

View file

@ -45,6 +45,7 @@ import java.util.Set;
public class GeyserCustomBlockComponents implements CustomBlockComponents {
BoxComponent selectionBox;
BoxComponent collisionBox;
String displayName;
String geometry;
Map<String, MaterialInstance> materialInstances;
Float destroyTime;
@ -52,10 +53,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
Integer lightEmission;
Integer lightDampening;
RotationComponent rotation;
boolean placeAir;
private GeyserCustomBlockComponents(CustomBlockComponentsBuilder builder) {
this.selectionBox = builder.selectionBox;
this.collisionBox = builder.collisionBox;
this.displayName = builder.displayName;
this.geometry = builder.geometry;
if (builder.materialInstances.isEmpty()) {
this.materialInstances = Object2ObjectMaps.emptyMap();
@ -67,6 +70,7 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
this.lightEmission = builder.lightEmission;
this.lightDampening = builder.lightDampening;
this.rotation = builder.rotation;
this.placeAir = builder.placeAir;
}
@Override
@ -79,6 +83,11 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
return collisionBox;
}
@Override
public String displayName() {
return displayName;
}
@Override
public String geometry() {
return geometry;
@ -114,6 +123,11 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
return rotation;
}
@Override
public boolean placeAir() {
return placeAir;
}
public static class CustomBlockComponentsBuilder implements Builder {
protected BoxComponent selectionBox;
protected BoxComponent collisionBox;
@ -125,6 +139,7 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
protected Integer lightEmission;
protected Integer lightDampening;
protected RotationComponent rotation;
protected boolean placeAir = false;
private static final Set<String> VALID_MATERIAL_INSTANCE_NAMES = ImmutableSet.of("*", "up", "down", "north", "south", "west", "east");
@ -160,6 +175,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
return this;
}
@Override
public Builder displayName(String displayName) {
this.displayName = displayName;
return this;
}
@Override
public Builder geometry(String geometry) {
this.geometry = geometry;
@ -226,6 +247,12 @@ public class GeyserCustomBlockComponents implements CustomBlockComponents {
return this;
}
@Override
public Builder placeAir(boolean placeAir) {
this.placeAir = placeAir;
return this;
}
@Override
public CustomBlockComponents build() {
return new GeyserCustomBlockComponents(this);

View file

@ -204,6 +204,11 @@ public class CustomBlockRegistryPopulator {
.putFloat("z", components.rotation().z())
.build());
}
if (components.placeAir()) {
builder.putCompound("minecraft:on_player_placing", NbtMap.builder()
.putString("triggerType", "geyser:place_event")
.build());
}
return builder.build();
}

View file

@ -68,6 +68,7 @@ public class CustomSkull {
.destroyTime(1.5f)
.materialInstance("*", new MaterialInstance("geyser." + skinHash + "_player_skin", "alpha_test", true, true))
.lightDampening(0)
.placeAir(true)
.build();
List<CustomBlockPermutation> permutations = new ArrayList<>();