Multiple tweaks and fixes to the recent changes in the client refactor PR: Part 2 (#8854)

* Add getter for the component names in an unbaked geometry
* Fix render type hint not being copied in BlockGeometryBakingContext
* Ensure BlockRenderDispatches's renderSingleBlock uses the correct buffer
This commit is contained in:
Néstor Amador authored and GitHub committed 2022-07-12 17:04:03 +02:00
1 parent b8b40e1f54
commit e76d814439
6 files changed
+65 -2

No files matched your search

@@ -953,6 +953,20 @@ public class ForgeHooksClient
return MinecraftForge.EVENT_BUS.post(event) ? "" : event.getMessage();
}
/**
* Mimics the behavior of {@link net.minecraft.client.renderer.ItemBlockRenderTypes#getRenderType(BlockState, boolean)}
* for the input {@link RenderType}.
*/
@NotNull
public static RenderType getEntityRenderType(RenderType chunkRenderType, boolean fabulous)
{
if (chunkRenderType != RenderType.translucent())
return Sheets.cutoutBlockSheet();
if (!Minecraft.useShaderTransparency())
return Sheets.translucentCullBlockSheet();
return fabulous ? Sheets.translucentCullBlockSheet() : Sheets.translucentItemSheet();
}
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid="forge", bus= Mod.EventBusSubscriber.Bus.MOD)
public static class ClientEvents
{
@@ -125,6 +125,12 @@ public class CompositeModel implements IUnbakedGeometry<CompositeModel>
return textures;
}
@Override
public Set<String> getConfigurableComponentNames()
{
return children.keySet();
}
public static class Baked implements IDynamicBakedModel
{
private final boolean isAmbientOcclusion;
@@ -147,6 +147,7 @@ public class BlockGeometryBakingContext implements IGeometryBakingContext
this.customGeometry = other.customGeometry;
this.rootTransform = other.rootTransform;
this.visibilityData.copyFrom(other.visibilityData);
this.renderTypeHint = other.renderTypeHint;
}
public Collection<Material> getTextureDependencies(Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
@@ -32,4 +32,12 @@ public interface IUnbakedGeometry<T extends IUnbakedGeometry<T>>
BakedModel bake(IGeometryBakingContext context, ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation);
Collection<Material> getMaterials(IGeometryBakingContext context, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors);
/**
* {@return a set of all the components whose visibility may be configured via {@link IGeometryBakingContext}}
*/
default Set<String> getConfigurableComponentNames()
{
return Set.of();
}
}
@@ -40,6 +40,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -67,6 +69,8 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
};
private final Map<String, ModelGroup> parts = Maps.newHashMap();
private final Set<String> rootComponentNames = Collections.unmodifiableSet(parts.keySet());
private Set<String> allComponentNames;
private final List<Vector3f> positions = Lists.newArrayList();
private final List<Vec2> texCoords = Lists.newArrayList();
@@ -360,6 +364,22 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
return combined;
}
public Set<String> getRootComponentNames()
{
return rootComponentNames;
}
@Override
public Set<String> getConfigurableComponentNames()
{
if (allComponentNames != null)
return allComponentNames;
var names = new HashSet<String>();
for (var group : parts.values())
group.addNamesRecursively(names);
return allComponentNames = Collections.unmodifiableSet(names);
}
private Pair<BakedQuad, Direction> makeQuad(int[][] indices, int tintIndex, Vector4f colorTint, Vector4f ambientColor, TextureAtlasSprite texture, Transformation transform)
{
boolean needsNormalRecalculation = false;
@@ -553,6 +573,11 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
: Stream.of())
.collect(Collectors.toSet());
}
protected void addNamesRecursively(Set<String> names)
{
names.add(name());
}
}
public class ModelGroup extends ModelObject
@@ -595,6 +620,14 @@ public class ObjModel extends SimpleUnbakedGeometry<ObjModel>
combined.addAll(part.getTextures(owner, modelGetter, missingTextureErrors));
return combined;
}
@Override
protected void addNamesRecursively(Set<String> names)
{
super.addNamesRecursively(names);
for (ModelObject object : parts.values())
object.addNamesRecursively(names);
}
}
private class ModelMesh