mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Add TextureStitchEvent
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2020 shedaniel
|
||||
*
|
||||
* 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 me.shedaniel.architectury.event.events;
|
||||
|
||||
import me.shedaniel.architectury.event.Event;
|
||||
import me.shedaniel.architectury.event.EventFactory;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public interface TextureStitchEvent {
|
||||
Event<Pre> PRE = EventFactory.createLoop(Pre.class);
|
||||
Event<Post> POST = EventFactory.createLoop(Post.class);
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
interface Pre {
|
||||
void stitch(TextureAtlas atlas, Consumer<ResourceLocation> spriteAdder);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
interface Post {
|
||||
void stitch(TextureAtlas atlas);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2020 shedaniel
|
||||
*
|
||||
* 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 me.shedaniel.architectury.mixin.fabric.client;
|
||||
|
||||
import me.shedaniel.architectury.event.events.TextureStitchEvent;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
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 org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Mixin(TextureAtlas.class)
|
||||
public class MixinTextureAtlas {
|
||||
@Inject(method = "prepareToStitch",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/util/profiling/ProfilerFiller;popPush(Ljava/lang/String;)V", ordinal = 0,
|
||||
shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
|
||||
private void preStitch(ResourceManager resourceManager, Stream<ResourceLocation> stream, ProfilerFiller profilerFiller, int i, CallbackInfoReturnable<TextureAtlas.Preparations> cir, Set<ResourceLocation> set) {
|
||||
TextureStitchEvent.PRE.invoker().stitch((TextureAtlas) (Object) this, set::add);
|
||||
}
|
||||
|
||||
@Inject(method = "reload", at = @At("RETURN"))
|
||||
private void postStitch(TextureAtlas.Preparations preparations, CallbackInfo ci) {
|
||||
TextureStitchEvent.POST.invoker().stitch((TextureAtlas) (Object) this);
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,8 @@
|
||||
"client.MixinGameRenderer",
|
||||
"client.MixinMinecraft",
|
||||
"client.MixinMultiPlayerGameMode",
|
||||
"client.MixinScreen"
|
||||
"client.MixinScreen",
|
||||
"client.MixinTextureAtlas"
|
||||
],
|
||||
"mixins": [
|
||||
"ExplosionPreInvoker", "LivingDeathInvoker", "MixinCommands", "MixinExplosion", "MixinFurnaceResultSlot", "MixinItemEntity", "MixinLivingEntity",
|
||||
|
||||
@@ -18,6 +18,7 @@ package me.shedaniel.architectury.event.forge;
|
||||
|
||||
import me.shedaniel.architectury.event.EventHandler;
|
||||
import me.shedaniel.architectury.event.events.PlayerEvent;
|
||||
import me.shedaniel.architectury.event.events.TextureStitchEvent;
|
||||
import me.shedaniel.architectury.event.events.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.IGuiEventListener;
|
||||
@@ -173,6 +174,16 @@ public class EventHandlerImpl implements EventHandler.Impl {
|
||||
public static void event(PlayerInteractEvent.LeftClickEmpty event) {
|
||||
InteractionEvent.CLIENT_LEFT_CLICK_AIR.invoker().click(event.getPlayer(), event.getHand());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void event(net.minecraftforge.client.event.TextureStitchEvent.Pre event) {
|
||||
TextureStitchEvent.PRE.invoker().stitch(event.getMap(), event::addSprite);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void event(net.minecraftforge.client.event.TextureStitchEvent.Post event) {
|
||||
TextureStitchEvent.POST.invoker().stitch(event.getMap());
|
||||
}
|
||||
}
|
||||
|
||||
public static class Common {
|
||||
|
||||
@@ -16,8 +16,12 @@
|
||||
|
||||
package me.shedaniel.architectury.forge;
|
||||
|
||||
import me.shedaniel.architectury.event.EventHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod("architectury")
|
||||
public class ArchitecturyForge {
|
||||
public ArchitecturyForge() {
|
||||
EventHandler.init();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user