[1.19.X] Client code cleanup, updates, and other refactors (#8786)

* Revert "Allow safely registering RenderType predicates at any time (#8685)"

This reverts commit be7275443f.

* Renderable API refactors
- Rename "render values" to "context"
- Rename SimpleRenderable to CompositeRenderable to better reflect its use
- Remove IMultipartRenderValues since it doesn't have any real use
- Add extensive customization options to BakedModelRenderable

* ClientRegistry and MinecraftForgeClient refactors
- Add sprite loader manager and registration event
- Add spectator shader manager and registration event
- Add client tooltip factory manager and registration event
- Add recipe book manager and registration event
- Add key mapping registration event
- Remove ClientRegistry, as everything has been moved out of it
- Remove registration methods from MinecraftForgeClient, as they have dedicated events now

* Dimension special effects refactors
- Fold handlers into an extension class and remove public mutable fields
- Add dimension special effects manager and registration event

* HUD overlay refactors
- Rename to IGuiOverlay match vanilla (instead of Ingame)
- Add overlay manager and registration event
- Move vanilla overlays to a standalone enum

* Model loader refactors
- Rename IModelLoader to IGeometryLoader
- Add loader manager and registration event
- Fold all model events into one
- Move registration of additionally loaded models to an event
- Remove ForgeModelBakery and related classes as they served no purpose anymore

* Render properties refactors
- Rename all render properties to client extensions and relocate accordingly
- Move lookups to the respective interfaces

* Model data refactors
- Convert model data to a final class backed by an immutable map and document mutability requirements. This addresses several thread-safety issues in the current implementation which could result in race conditions
- Transfer ownership of the data manager to the client level. This addresses several issues that arise when multiple levels are used at once

* GUI and widget refactors
- Move all widgets to the correct package
- Rename GuiUtils and children to match vanilla naming

* New vertex pipeline API
- Move to vanilla's VertexConsumer
- Roll back recent PR making VertexConsumer format-aware. This is the opposite of what vanilla does, and should not be relevant with the updated lighting pipeline

* Lighting pipeline refactors
- Move to dedicated lighting package
- Separate flat and smooth lighters
- Convert from a vertex pipeline transformer to a pure vertex source (input is baked quads)

* Model geometry API refactors
- Rename IModelGeometry to IUnbakedGeometry
- Rename IModelConfiguration to IGeometryBakingContext
- Rename other elements to match vanilla naming
- Remove current changes to ModelState, as they do not belong there. Transforms should be specified through vanilla's system. ModelState is intended to transfer state from the blockstate JSON
- Remove multipart geometries and geometry parts. After some discussion, these should not be exposed. Instead, geometries should be baked with only the necessary parts enabled

* Make render types a first-class citizen in baked models
- Add named render types (block + entity + fabulous entity)
- Add named render type manager + registration event
- Make BakedModel aware of render types and transfer control over which ones are used to it instead of ItemBlockRenderTypes (fallback)
- (additional) Add concatenated list view. A wrapper for multiple lists that iterates through them in order without the cost of merging them. Useful for merging lists of baked quads

* General event refactors
- Several renames to either match vanilla or improve clarity
- Relocate client chat event dispatching out of common code

* Forge model type refactors
- Rename SeparatePerspectiveModel to SeparateTransformsModel
- Rename ItemModelMesherForge to ForgeItemModelShaper
- Rename DynamicBucketModel to DynamicFluidContainerModel
- Prefix all OBJ-related classes with "Obj" and decouple parsing from construction
- Extract ElementsModel from model loader registry
- Add EmptyModel (baked, unbaked and loader)
- Refactor CompositeModel to take over ItemMultiLayerBakedModel
- Remove FluidModel as it's not used and isn't compatible with the new fluid rendering in modern versions
- Move model loader registration to a proper event handler
- Update names of several JSON fields (backwards-compatible)
- Update datagens to match

* Miscellaneous changes and overlapping patches
- Dispatch all new registration events
- Convert ExtendedServerListData to a record
- Add/remove hooks from ForgeHooksClient as necessary

* Update test mods

* Fix VertexConsumerWrapper returning parent instead of itself

* Additional event cleanup pass

As discussed on Discord:
- Remove "@hidden" and "@see <callsite>" javadoc annotations from all client events and replace them with @ApiStatus.Internal annotation
- Make all events that shouldn't be fired directly into abstract classes with protected constructors
- Another styling pass, just in case (caught some missed classes)

* Add proper deprecation javadocs and de-dupe some vertex consumer code

* Replace sets of chunk render types with a faster BitSet-backed collection

This largely addresses potential performance concerns that using a plain HashSet might involve by making lookups and iteration as linear as they can likely be (aside from using a plain byte/int/long for bit storage). Further performance concerns related to the implementation may be addressed separately, as all the implementation details are hidden from the end user

* Requested changes

- Remove MinecraftForgeClient and move members to Minecraft, IForgeMinecraft and StencilManager
- Allow non-default elements to be passed into VertexConsumer and add support to derived classes
- Move array instantiation out of quad processing in lighting pipeline
- Fix flipped fluid container model
- Set default UV1 to the correct values in the remapping pipeline
- Minor documentation changes

* Add/update EXC entries and fix AT comment

* Add test mod as per Orion's request

* Additional requested changes

* Allow custom model types to request the particle texture to be loaded

* Even more requested changes

* Improve generics in ConcatenatedListView and add missing fallbacks

* Fix fluid render types being bound to the fluid and not its holder

* Remove non-contractual nullability in ChunkRenderTypeSet and add isEmpty

Additionally, introduce chunk render type checks in ItemBlockRenderTypes

Co-authored-by: Dennis C <[email protected]>
This commit is contained in:
Néstor AmadorandDennis C authored and GitHub committed 2022-07-07 18:34:51 -04:00
1 parent c2225ab1da
commit 4d074f0a1e
295 files changed
+9929 -11604

No files matched your search

@@ -9,7 +9,6 @@ import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import com.mojang.datafixers.util.Pair;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.*;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -20,7 +19,6 @@ import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.stats.Stats;
import net.minecraft.util.RandomSource;
import net.minecraft.world.InteractionHand;
@@ -39,14 +37,17 @@ import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.ChunkRenderTypeSet;
import net.minecraftforge.client.event.ModelEvent;
import net.minecraftforge.client.model.*;
import net.minecraftforge.client.model.data.*;
import net.minecraftforge.client.model.geometry.IModelGeometry;
import net.minecraftforge.client.model.geometry.IGeometryBakingContext;
import net.minecraftforge.client.model.geometry.IGeometryLoader;
import net.minecraftforge.client.model.geometry.IUnbakedGeometry;
import net.minecraftforge.common.util.ConcatenatedListView;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
@@ -167,13 +168,13 @@ public class FullPotsAccessorDemo
{
public static final ModelProperty<Block> PLANT_PROPERTY = new ModelProperty<>();
private final IModelData modelData = new ModelDataMap.Builder().build();
private ModelData modelData;
private Block plant = Blocks.AIR;
public DioriteFlowerPotBlockEntity(BlockPos pos, BlockState state)
{
super(DIORITE_POT_BLOCK_ENTITY.get(), pos, state);
modelData.setData(PLANT_PROPERTY, plant);
modelData = ModelData.builder().with(PLANT_PROPERTY, plant).build();
}
public void setPlant(Block plant)
@@ -187,7 +188,7 @@ public class FullPotsAccessorDemo
public Block getPlant() { return plant; }
@Override
public IModelData getModelData() { return modelData; }
public ModelData getModelData() {return modelData; }
@Override
public CompoundTag getUpdateTag()
@@ -199,7 +200,7 @@ public class FullPotsAccessorDemo
public void handleUpdateTag(CompoundTag tag)
{
super.handleUpdateTag(tag);
modelData.setData(PLANT_PROPERTY, plant);
modelData = modelData.derive().with(PLANT_PROPERTY, plant).build();
requestModelDataUpdate();
}
@@ -237,42 +238,31 @@ public class FullPotsAccessorDemo
private static class ClientHandler
{
@SubscribeEvent
public static void onClientSetup(final FMLClientSetupEvent event)
public static void registerLoader(final ModelEvent.RegisterGeometryLoaders event)
{
if (!ENABLED) { return; }
ItemBlockRenderTypes.setRenderLayer(DIORITE_POT.get(), RenderType.cutout());
event.register("diorite_pot", new DioritePotGeometryLoader());
}
@SubscribeEvent
public static void registerLoader(final ModelRegistryEvent event)
{
ModelLoaderRegistry.registerLoader(new ResourceLocation(MOD_ID, "diorite_pot"), new DioritePotModelLoader());
}
private static class DioritePotModelLoader implements IModelLoader<DioritePotModelGeometry>
private static class DioritePotGeometryLoader implements IGeometryLoader<DioritePotModelGeometry>
{
@Override
public void onResourceManagerReload(ResourceManager manager) { }
@Override
public DioritePotModelGeometry read(JsonDeserializationContext context, JsonObject modelContents)
public DioritePotModelGeometry read(JsonObject jsonObject, JsonDeserializationContext deserializationContext)
{
JsonObject wrappedModel = modelContents.getAsJsonObject("model");
return new DioritePotModelGeometry(context.deserialize(wrappedModel, BlockModel.class));
JsonObject wrappedModel = jsonObject.getAsJsonObject("model");
return new DioritePotModelGeometry(deserializationContext.deserialize(wrappedModel, BlockModel.class));
}
}
private record DioritePotModelGeometry(UnbakedModel wrappedModel) implements IModelGeometry<DioritePotModelGeometry>
private record DioritePotModelGeometry(UnbakedModel wrappedModel) implements IUnbakedGeometry<DioritePotModelGeometry>
{
@Override
public BakedModel bake(IModelConfiguration owner, ModelBakery bakery, Function<net.minecraft.client.resources.model.Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ItemOverrides overrides, ResourceLocation modelLocation)
public BakedModel bake(IGeometryBakingContext context, ModelBakery bakery, Function<net.minecraft.client.resources.model.Material, TextureAtlasSprite> spriteGetter, ModelState modelState, ItemOverrides overrides, ResourceLocation modelLocation)
{
return new DioritePotModel(wrappedModel.bake(bakery, spriteGetter, modelTransform, modelLocation));
return new DioritePotModel(wrappedModel.bake(bakery, spriteGetter, modelState, modelLocation));
}
@Override
public Collection<net.minecraft.client.resources.model.Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
public Collection<net.minecraft.client.resources.model.Material> getMaterials(IGeometryBakingContext context, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors)
{
return wrappedModel.getMaterials(modelGetter, missingTextureErrors);
}
@@ -280,6 +270,7 @@ public class FullPotsAccessorDemo
private static class DioritePotModel extends BakedModelWrapper<BakedModel>
{
private static final ChunkRenderTypeSet CUTOUT = ChunkRenderTypeSet.of(RenderType.cutout());
private static final ResourceLocation POT_TEXTURE = new ResourceLocation("minecraft:block/flower_pot");
private static final ResourceLocation DIRT_TEXTURE = new ResourceLocation("minecraft:block/dirt");
@@ -287,30 +278,37 @@ public class FullPotsAccessorDemo
@NotNull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull ModelData extraData, @Nullable RenderType renderType)
{
List<BakedQuad> quads = new ArrayList<>(originalModel.getQuads(state, side, rand, extraData));
List<List<BakedQuad>> quads = new ArrayList<>();
quads.add(originalModel.getQuads(state, side, rand, extraData, renderType));
Block plant = extraData.getData(DioriteFlowerPotBlockEntity.PLANT_PROPERTY);
Block plant = extraData.get(DioriteFlowerPotBlockEntity.PLANT_PROPERTY);
if (plant != null && plant != Blocks.AIR)
{
quads.addAll(getPlantQuads(plant, side, rand));
quads.add(getPlantQuads(plant, side, rand, renderType));
}
return quads;
return ConcatenatedListView.of(quads);
}
private List<BakedQuad> getPlantQuads(Block plant, @Nullable Direction face, RandomSource rand)
private List<BakedQuad> getPlantQuads(Block plant, @Nullable Direction face, RandomSource rand, @Nullable RenderType renderType)
{
BlockState potState = ((FlowerPotBlock) Blocks.FLOWER_POT).getFullPotsView().getOrDefault(ForgeRegistries.BLOCKS.getKey(plant), ForgeRegistries.BLOCKS.getDelegateOrThrow(Blocks.AIR)).get().defaultBlockState();
BakedModel potModel = Minecraft.getInstance().getBlockRenderer().getBlockModel(potState);
return potModel.getQuads(potState, face, rand, EmptyModelData.INSTANCE)
return potModel.getQuads(potState, face, rand, ModelData.EMPTY, renderType)
.stream()
.filter(q -> !q.getSprite().getName().equals(POT_TEXTURE))
.filter(q -> !q.getSprite().getName().equals(DIRT_TEXTURE))
.collect(Collectors.toList());
}
@Override
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data)
{
return CUTOUT;
}
}
}
}