Allow Null Texture for Block Mappings/API (#4094)

* Allow null textures for blocks.json use

* Missing semicolon
This commit is contained in:
Kas-tle 2023-08-31 10:09:14 -07:00 committed by GitHub
parent 1b05f9f15e
commit bf81fc1139
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 19 deletions

View file

@ -25,7 +25,6 @@
package org.geysermc.geyser.api.block.custom.component; package org.geysermc.geyser.api.block.custom.component;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.GeyserApi; import org.geysermc.geyser.api.GeyserApi;
@ -38,7 +37,7 @@ public interface MaterialInstance {
* *
* @return The texture of the block. * @return The texture of the block.
*/ */
@NonNull String texture(); @Nullable String texture();
/** /**
* Gets the render method of the block * Gets the render method of the block
@ -52,14 +51,14 @@ public interface MaterialInstance {
* *
* @return If the block should be dimmed on certain faces. * @return If the block should be dimmed on certain faces.
*/ */
@Nullable boolean faceDimming(); boolean faceDimming();
/** /**
* Gets if the block should have ambient occlusion * Gets if the block should have ambient occlusion
* *
* @return If the block should have ambient occlusion. * @return If the block should have ambient occlusion.
*/ */
@Nullable boolean ambientOcclusion(); boolean ambientOcclusion();
/** /**
* Creates a builder for MaterialInstance. * Creates a builder for MaterialInstance.
@ -71,13 +70,13 @@ public interface MaterialInstance {
} }
interface Builder { interface Builder {
Builder texture(@NonNull String texture); Builder texture(@Nullable String texture);
Builder renderMethod(@Nullable String renderMethod); Builder renderMethod(@Nullable String renderMethod);
Builder faceDimming(@Nullable boolean faceDimming); Builder faceDimming(boolean faceDimming);
Builder ambientOcclusion(@Nullable boolean ambientOcclusion); Builder ambientOcclusion(boolean ambientOcclusion);
MaterialInstance build(); MaterialInstance build();
} }

View file

@ -26,7 +26,6 @@
package org.geysermc.geyser.level.block; package org.geysermc.geyser.level.block;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.api.block.custom.component.MaterialInstance; import org.geysermc.geyser.api.block.custom.component.MaterialInstance;
@ -45,7 +44,7 @@ public class GeyserMaterialInstance implements MaterialInstance {
} }
@Override @Override
public @NonNull String texture() { public @Nullable String texture() {
return texture; return texture;
} }
@ -55,12 +54,12 @@ public class GeyserMaterialInstance implements MaterialInstance {
} }
@Override @Override
public @Nullable boolean faceDimming() { public boolean faceDimming() {
return faceDimming; return faceDimming;
} }
@Override @Override
public @Nullable boolean ambientOcclusion() { public boolean ambientOcclusion() {
return ambientOcclusion; return ambientOcclusion;
} }
@ -71,7 +70,7 @@ public class GeyserMaterialInstance implements MaterialInstance {
private boolean ambientOcclusion; private boolean ambientOcclusion;
@Override @Override
public Builder texture(@NonNull String texture) { public Builder texture(@Nullable String texture) {
this.texture = texture; this.texture = texture;
return this; return this;
} }
@ -83,13 +82,13 @@ public class GeyserMaterialInstance implements MaterialInstance {
} }
@Override @Override
public Builder faceDimming(@Nullable boolean faceDimming) { public Builder faceDimming(boolean faceDimming) {
this.faceDimming = faceDimming; this.faceDimming = faceDimming;
return this; return this;
} }
@Override @Override
public Builder ambientOcclusion(@Nullable boolean ambientOcclusion) { public Builder ambientOcclusion(boolean ambientOcclusion) {
this.ambientOcclusion = ambientOcclusion; this.ambientOcclusion = ambientOcclusion;
return this; return this;
} }

View file

@ -626,7 +626,7 @@ public class MappingsReader_v1 extends MappingsReader {
*/ */
private MaterialInstance createMaterialInstanceComponent(JsonNode node, String name) { private MaterialInstance createMaterialInstanceComponent(JsonNode node, String name) {
// Set default values, and use what the user provides if they have provided something // Set default values, and use what the user provides if they have provided something
String texture = name; String texture = null;
if (node.has("texture")) { if (node.has("texture")) {
texture = node.get("texture").asText(); texture = node.get("texture").asText();
} }

View file

@ -325,12 +325,15 @@ public class CustomBlockRegistryPopulator {
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();
materialsBuilder.putCompound(entry.getKey(), NbtMap.builder() NbtMapBuilder materialBuilder = NbtMap.builder()
.putString("texture", materialInstance.texture())
.putString("render_method", materialInstance.renderMethod()) .putString("render_method", materialInstance.renderMethod())
.putBoolean("face_dimming", materialInstance.faceDimming()) .putBoolean("face_dimming", materialInstance.faceDimming())
.putBoolean("ambient_occlusion", materialInstance.faceDimming()) .putBoolean("ambient_occlusion", materialInstance.faceDimming());
.build()); // Texture can be unspecified when blocks.json is used in RP (https://wiki.bedrock.dev/blocks/blocks-stable.html#minecraft-material-instances)
if (materialInstance.texture() != null) {
materialBuilder.putString("texture", materialInstance.texture());
}
materialsBuilder.putCompound(entry.getKey(), materialBuilder.build());
} }
builder.putCompound("minecraft:material_instances", NbtMap.builder() builder.putCompound("minecraft:material_instances", NbtMap.builder()