1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2026-01-06 15:41:50 +00:00

Add tint method and isotropic properties to block material instances (#5977)

* Add tint method and isotropic properties to block material instances

* Check if tint method is null before including it

* Lets cover the null check on render method too
This commit is contained in:
rtm516
2025-11-19 13:21:47 +00:00
committed by GitHub
parent 42038a52ee
commit cc08b71b39
3 changed files with 59 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -46,6 +46,13 @@ public interface MaterialInstance {
*/
@Nullable String renderMethod();
/**
* Gets the tint method of the block
*
* @return The tint method of the block.
*/
@Nullable String tintMethod();
/**
* Gets if the block should be dimmed on certain faces
*
@@ -60,6 +67,13 @@ public interface MaterialInstance {
*/
boolean ambientOcclusion();
/**
* Gets if the block is isotropic
*
* @return If the block is isotropic.
*/
boolean isotropic();
/**
* Creates a builder for MaterialInstance.
*
@@ -74,10 +88,14 @@ public interface MaterialInstance {
Builder renderMethod(@Nullable String renderMethod);
Builder tintMethod(@Nullable String tintMethod);
Builder faceDimming(boolean faceDimming);
Builder ambientOcclusion(boolean ambientOcclusion);
Builder isotropic(boolean isotropic);
MaterialInstance build();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2023 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -33,14 +33,18 @@ import org.geysermc.geyser.api.block.custom.component.MaterialInstance;
public class GeyserMaterialInstance implements MaterialInstance {
private final String texture;
private final String renderMethod;
private final String tintMethod;
private final boolean faceDimming;
private final boolean ambientOcclusion;
private final boolean isotropic;
GeyserMaterialInstance(Builder builder) {
this.texture = builder.texture;
this.renderMethod = builder.renderMethod;
this.tintMethod = builder.tintMethod;
this.faceDimming = builder.faceDimming;
this.ambientOcclusion = builder.ambientOcclusion;
this.isotropic = builder.isotropic;
}
@Override
@@ -53,6 +57,11 @@ public class GeyserMaterialInstance implements MaterialInstance {
return renderMethod;
}
@Override
public @Nullable String tintMethod() {
return tintMethod;
}
@Override
public boolean faceDimming() {
return faceDimming;
@@ -63,11 +72,18 @@ public class GeyserMaterialInstance implements MaterialInstance {
return ambientOcclusion;
}
@Override
public boolean isotropic() {
return isotropic;
}
public static class Builder implements MaterialInstance.Builder {
private String texture;
private String renderMethod;
private String tintMethod;
private boolean faceDimming;
private boolean ambientOcclusion;
private boolean isotropic;
@Override
public Builder texture(@Nullable String texture) {
@@ -81,6 +97,12 @@ public class GeyserMaterialInstance implements MaterialInstance {
return this;
}
@Override
public Builder tintMethod(@Nullable String tintMethod) {
this.tintMethod = tintMethod;
return this;
}
@Override
public Builder faceDimming(boolean faceDimming) {
this.faceDimming = faceDimming;
@@ -93,6 +115,12 @@ public class GeyserMaterialInstance implements MaterialInstance {
return this;
}
@Override
public MaterialInstance.Builder isotropic(boolean isotropic) {
this.isotropic = isotropic;
return this;
}
@Override
public MaterialInstance build() {
return new GeyserMaterialInstance(this);

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2024 GeyserMC. http://geysermc.org
* Copyright (c) 2019-2025 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -448,8 +448,8 @@ public class CustomBlockRegistryPopulator {
for (Map.Entry<String, MaterialInstance> entry : components.materialInstances().entrySet()) {
MaterialInstance materialInstance = entry.getValue();
NbtMapBuilder materialBuilder = NbtMap.builder()
.putString("render_method", materialInstance.renderMethod())
.putBoolean("ambient_occlusion", materialInstance.ambientOcclusion());
.putBoolean("ambient_occlusion", materialInstance.ambientOcclusion())
.putBoolean("isotropic", materialInstance.isotropic());
if (GameProtocol.is1_21_110orHigher(protocolVersion)) {
materialBuilder.putBoolean("packed_bools", materialInstance.faceDimming());
@@ -457,6 +457,14 @@ public class CustomBlockRegistryPopulator {
materialBuilder.putBoolean("face_dimming", materialInstance.faceDimming());
}
if (materialInstance.renderMethod() != null) {
materialBuilder.putString("render_method", materialInstance.renderMethod());
}
if (materialInstance.tintMethod() != null) {
materialBuilder.putString("tint_method", materialInstance.tintMethod());
}
// 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());