mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-15 03:35:07 -05:00
Add RenderReloadCallback Event (#217)
This commit is contained in:
parent
e46586a959
commit
6dad974e70
4 changed files with 77 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
archivesBaseName = "fabric-rendering-v0"
|
||||
version = getSubprojectVersion(project, "0.1.0")
|
||||
version = getSubprojectVersion(project, "0.1.1")
|
||||
|
||||
dependencies {
|
||||
compile project(path: ':fabric-api-base', configuration: 'dev')
|
||||
|
|
|
@ -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.render;
|
||||
|
||||
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 {
|
||||
public static final Event<InvalidateRenderStateCallback> EVENT = EventFactory.createArrayBacked(InvalidateRenderStateCallback.class,
|
||||
(listeners) -> () -> {
|
||||
for (InvalidateRenderStateCallback event : listeners) {
|
||||
event.onInvalidate();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
void onInvalidate();
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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.render;
|
||||
|
||||
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.fabricmc.fabric.api.client.render.InvalidateRenderStateCallback;
|
||||
import net.minecraft.client.render.WorldRenderer;
|
||||
|
||||
@Mixin(WorldRenderer.class)
|
||||
public abstract class MixinWorldRenderer {
|
||||
@Inject(method = "reload", at = @At("HEAD"))
|
||||
private void onReload(CallbackInfo ci) {
|
||||
InvalidateRenderStateCallback.EVENT.invoker().onInvalidate();
|
||||
}
|
||||
}
|
|
@ -6,7 +6,8 @@
|
|||
"MixinBlockColorMap",
|
||||
"MixinBlockEntityRenderManager",
|
||||
"MixinEntityRenderManager",
|
||||
"MixinItemColorMap"
|
||||
"MixinItemColorMap",
|
||||
"MixinWorldRenderer"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue