fabric-rendering-v1 module & added HudRenderCallback (#359)

This commit is contained in:
shedaniel 2019-12-28 23:29:04 +08:00 committed by Player
parent 175d0eb82e
commit 5341049050
18 changed files with 263 additions and 13 deletions

View file

@ -1,6 +1,7 @@
archivesBaseName = "fabric-rendering-v0"
version = getSubprojectVersion(project, "1.0.1")
version = getSubprojectVersion(project, "1.1.0")
dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev')
compile project(path: ':fabric-rendering-v1', configuration: 'dev')
}

View file

@ -21,12 +21,34 @@ import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.item.ItemColorProvider;
import net.minecraft.item.ItemConvertible;
import net.fabricmc.fabric.impl.client.rendering.ColorProviderRegistryImpl;
/**
* @deprecated Replaced by {@link net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry}
*/
@Deprecated
public interface ColorProviderRegistry<T, Provider> {
ColorProviderRegistry<ItemConvertible, ItemColorProvider> ITEM = ColorProviderRegistryImpl.ITEM;
ColorProviderRegistry<ItemConvertible, ItemColorProvider> ITEM = new ColorProviderRegistry<ItemConvertible, ItemColorProvider>() {
@Override
public void register(ItemColorProvider itemColorProvider, ItemConvertible... objects) {
net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry.ITEM.register(itemColorProvider, objects);
}
ColorProviderRegistry<Block, BlockColorProvider> BLOCK = ColorProviderRegistryImpl.BLOCK;
@Override
public ItemColorProvider get(ItemConvertible object) {
return net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry.ITEM.get(object);
}
};
ColorProviderRegistry<Block, BlockColorProvider> BLOCK = new ColorProviderRegistry<Block, BlockColorProvider>() {
@Override
public void register(BlockColorProvider blockColorProvider, Block... objects) {
net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry.BLOCK.register(blockColorProvider, objects);
}
@Override
public BlockColorProvider get(Block object) {
return net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry.BLOCK.get(object);
}
};
/**
* Register a color provider for one or more objects.

View file

@ -27,7 +27,10 @@ import net.fabricmc.fabric.api.event.EventFactory;
* <p>Render chunks and other render-related object instances will be made null
* or invalid after this event so do not use it to capture dependent state.
* Instead, use it to invalidate state and reinitialize lazily.
*
* @deprecated Replaced by {@link net.fabricmc.fabric.api.client.rendering.v1.InvalidateRenderStateCallback}
*/
@Deprecated
public interface InvalidateRenderStateCallback {
Event<InvalidateRenderStateCallback> EVENT = EventFactory.createArrayBacked(InvalidateRenderStateCallback.class,
(listeners) -> () -> {

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.impl.client.rendering;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.InvalidateRenderStateCallback;
public class RenderingCallbackInvoker implements ClientModInitializer {
@Override
public void onInitializeClient() {
InvalidateRenderStateCallback.EVENT.register(() -> net.fabricmc.fabric.api.client.render.InvalidateRenderStateCallback.EVENT.invoker().onInvalidate());
}
}

View file

@ -15,13 +15,16 @@
"authors": [
"FabricMC"
],
"entrypoints": {
"client": [
"net.fabricmc.fabric.impl.client.rendering.RenderingCallbackInvoker"
]
},
"depends": {
"fabricloader": ">=0.4.0",
"minecraft": ">=1.15-alpha.19.39.a",
"fabric-api-base": "*"
"fabric-api-base": "*",
"fabric-rendering-v1": "*"
},
"description": "Hooks and registries for rendering-related things.",
"mixins": [
"fabric-rendering-v0.mixins.json"
]
"description": "Hooks and registries for rendering-related things."
}

View file

@ -0,0 +1,6 @@
archivesBaseName = "fabric-rendering-v1"
version = getSubprojectVersion(project, "0.1.0")
dependencies {
compile project(path: ':fabric-api-base', configuration: 'dev')
}

View file

@ -0,0 +1,49 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.api.client.rendering.v1;
import net.minecraft.block.Block;
import net.minecraft.client.color.block.BlockColorProvider;
import net.minecraft.client.color.item.ItemColorProvider;
import net.minecraft.item.ItemConvertible;
import net.fabricmc.fabric.impl.client.rendering.ColorProviderRegistryImpl;
public interface ColorProviderRegistry<T, Provider> {
ColorProviderRegistry<ItemConvertible, ItemColorProvider> ITEM = ColorProviderRegistryImpl.ITEM;
ColorProviderRegistry<Block, BlockColorProvider> BLOCK = ColorProviderRegistryImpl.BLOCK;
/**
* Register a color provider for one or more objects.
*
* @param provider The color provider to register.
* @param objects The objects which should be colored using this provider.
*/
void register(Provider provider, T... objects);
/**
* Get a color provider for the given object.
*
* <p>Please note that the underlying registry may not be fully populated or stable until the game has started,
* as other mods may overwrite the registry.
*
* @param object The object to acquire the provide for.
* @return The registered mapper for this provider, or {@code null} if none is registered or available.
*/
Provider get(T object);
}

View file

@ -0,0 +1,36 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.api.client.rendering.v1;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
public interface HudRenderCallback {
Event<HudRenderCallback> EVENT = EventFactory.createArrayBacked(HudRenderCallback.class, (listeners) ->
(delta) -> {
for (HudRenderCallback event : listeners) {
event.onHudRender(delta);
}
});
/**
* Called after rendering the whole hud, which is displayed in game, in a world.
*
* @param tickDelta Progress for linearly interpolating between the previous and current game state
*/
void onHudRender(float tickDelta);
}

View file

@ -0,0 +1,41 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.api.client.rendering.v1;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
/**
* Called when the world renderer reloads, usually as result of changing resource pack
* or video configuration, or when the player types F3+A in the debug screen.
* Afterwards all render chunks will be reset and reloaded.
*
* <p>Render chunks and other render-related object instances will be made null
* or invalid after this event so do not use it to capture dependent state.
* Instead, use it to invalidate state and reinitialize lazily.
*/
public interface InvalidateRenderStateCallback {
Event<InvalidateRenderStateCallback> EVENT = EventFactory.createArrayBacked(InvalidateRenderStateCallback.class,
(listeners) -> () -> {
for (InvalidateRenderStateCallback event : listeners) {
event.onInvalidate();
}
}
);
void onInvalidate();
}

View file

@ -26,7 +26,7 @@ import net.minecraft.client.color.item.ItemColorProvider;
import net.minecraft.client.color.item.ItemColors;
import net.minecraft.item.ItemConvertible;
import net.fabricmc.fabric.api.client.render.ColorProviderRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
public abstract class ColorProviderRegistryImpl<T, Provider, Underlying> implements ColorProviderRegistry<T, Provider> {
public static final ColorProviderRegistryImpl<Block, BlockColorProvider, BlockColors> BLOCK = new ColorProviderRegistryImpl<Block, BlockColorProvider, BlockColors>() {

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.mixin.client.rendering;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.gui.hud.InGameHud;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
@Mixin(InGameHud.class)
public class MixinInGameHud {
@Inject(method = "render", at = @At(value = "RETURN", shift = At.Shift.BY, by = -6))
public void render(float tickDelta, CallbackInfo callbackInfo) {
HudRenderCallback.EVENT.invoker().onHudRender(tickDelta);
}
}

View file

@ -23,7 +23,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.render.WorldRenderer;
import net.fabricmc.fabric.api.client.render.InvalidateRenderStateCallback;
import net.fabricmc.fabric.api.client.rendering.v1.InvalidateRenderStateCallback;
@Mixin(WorldRenderer.class)
public abstract class MixinWorldRenderer {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_8",
"client": [
"MixinBlockColorMap",
"MixinInGameHud",
"MixinItemColorMap",
"MixinWorldRenderer"
],

View file

@ -0,0 +1,26 @@
{
"schemaVersion": 1,
"id": "fabric-rendering-v1",
"name": "Fabric Rendering (v1)",
"version": "${version}",
"environment": "client",
"license": "Apache-2.0",
"icon": "assets/fabric-rendering-v1/icon.png",
"contact": {
"homepage": "https://fabricmc.net",
"irc": "irc://irc.esper.net:6667/fabric",
"issues": "https://github.com/FabricMC/fabric/issues",
"sources": "https://github.com/FabricMC/fabric"
},
"authors": [
"FabricMC"
],
"depends": {
"fabricloader": ">=0.4.0",
"fabric-api-base": "*"
},
"description": "Hooks and registries for rendering-related things.",
"mixins": [
"fabric-rendering-v1.mixins.json"
]
}

View file

@ -36,9 +36,10 @@ include 'fabric-renderer-api-v1'
include 'fabric-renderer-indigo'
include 'fabric-renderer-registries-v1'
include 'fabric-rendering-v0'
include 'fabric-rendering-v1'
include 'fabric-rendering-data-attachment-v1'
include 'fabric-rendering-fluids-v1'
include 'fabric-resource-loader-v0'
include 'fabric-tag-extensions-v0'
include 'fabric-textures-v0'
include 'fabric-dimensions-v1'
include 'fabric-dimensions-v1'