mirror of
https://github.com/architectury/architectury-api.git
synced 2026-03-28 03:56:59 -05:00
Merge remote-tracking branch 'architectury/1.18' into 1.18.2
This commit is contained in:
@@ -23,12 +23,15 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import dev.architectury.event.Event;
|
||||
import dev.architectury.event.EventFactory;
|
||||
import dev.architectury.event.EventResult;
|
||||
import dev.architectury.impl.TooltipAdditionalContextsImpl;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -51,6 +54,18 @@ public interface ClientTooltipEvent {
|
||||
*/
|
||||
Event<RenderModifyColor> RENDER_MODIFY_COLOR = EventFactory.createLoop();
|
||||
|
||||
static AdditionalContexts additionalContexts() {
|
||||
return TooltipAdditionalContextsImpl.get();
|
||||
}
|
||||
|
||||
@ApiStatus.NonExtendable
|
||||
interface AdditionalContexts {
|
||||
@Nullable
|
||||
ItemStack getItem();
|
||||
|
||||
void setItem(@Nullable ItemStack stack);
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
interface Item {
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021, 2022 architectury
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package dev.architectury.impl;
|
||||
|
||||
import dev.architectury.event.events.client.ClientTooltipEvent;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TooltipAdditionalContextsImpl implements ClientTooltipEvent.AdditionalContexts {
|
||||
private static final ThreadLocal<TooltipAdditionalContextsImpl> INSTANCE_LOCAL = ThreadLocal.withInitial(TooltipAdditionalContextsImpl::new);
|
||||
|
||||
public static ClientTooltipEvent.AdditionalContexts get() {
|
||||
return INSTANCE_LOCAL.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ItemStack item;
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItem(@Nullable ItemStack item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
@@ -24,9 +24,11 @@ import dev.architectury.injectables.targets.ArchitecturyTarget;
|
||||
import dev.architectury.utils.Env;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.minecraft.SharedConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class Platform {
|
||||
@@ -60,54 +62,118 @@ public final class Platform {
|
||||
return SharedConstants.getCurrentVersion().getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the root directory for the current instance of Minecraft.
|
||||
* <p>
|
||||
* The returned path is guaranteed to be <b>absolute</b>.
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static Path getGameFolder() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the main <code>config</code> folder for the current instance of Minecraft.
|
||||
* <p>
|
||||
* The returned path is guaranteed to be <b>absolute</b>.
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static Path getConfigFolder() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the <code>mods</code> folder of the current instance of Minecraft.
|
||||
* <p>
|
||||
* The returned path is guaranteed to be <b>absolute</b>.
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static Path getModsFolder() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current Environment the game is running in,
|
||||
* being one of either <code>CLIENT</code> or <code>SERVER</code>.
|
||||
* <p>
|
||||
* The class returned is a platform-agnostic wrapper around the
|
||||
* <code>EnvType</code> and <code>Dist</code> enums, respectively.
|
||||
*
|
||||
* @return The current Environment, as an instance of {@link Env}
|
||||
* @see Env
|
||||
* @see #getEnv()
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static Env getEnvironment() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current Environment the game is running in,
|
||||
* as a member of the {@link EnvType} enum. This is remapped
|
||||
* on Forge to be the <code>Dist</code> enum, instead.
|
||||
*
|
||||
* @return The current Environment, as an instance of {@link EnvType}
|
||||
* (or <code>Dist</code> on Forge)
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static EnvType getEnv() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a mod with the given mod ID is present.
|
||||
*
|
||||
* @param id The mod ID to check.
|
||||
* @return <code>true</code> if the mod is loaded, <code>false</code> otherwise.
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static boolean isModLoaded(String id) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link Mod} container by its mod ID.
|
||||
*
|
||||
* @param id The mod ID to look for.
|
||||
* @return The mod container, if found.
|
||||
* @throws NoSuchElementException if no mod with the given ID exists
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static Mod getMod(String id) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally gets a {@link Mod} container by its mod ID if it exists.
|
||||
*
|
||||
* @param id The mod ID to look for.
|
||||
* @return An optional representing the mod container, if found,
|
||||
* or an empty optional otherwise.
|
||||
*/
|
||||
public static Optional<Mod> getOptionalMod(String id) {
|
||||
try {
|
||||
return Optional.of(getMod(id));
|
||||
} catch (NullPointerException e) {
|
||||
} catch (NoSuchElementException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a collection of {@link Mod} containers for all currently-loaded mods.
|
||||
*
|
||||
* @return A collection of mod containers.
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static Collection<Mod> getMods() {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a collection of Strings representing the mod IDs of all currently-loaded mods.
|
||||
*
|
||||
* @return A collection of all loaded mod IDs.
|
||||
*/
|
||||
@ExpectPlatform
|
||||
public static Collection<String> getModIds() {
|
||||
throw new AssertionError();
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
|
||||
package dev.architectury.mixin.fabric.client;
|
||||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.shaders.Program;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dev.architectury.event.events.client.ClientGuiEvent;
|
||||
import dev.architectury.event.events.client.ClientReloadShadersEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -48,8 +50,8 @@ public abstract class MixinGameRenderer {
|
||||
@Inject(method = "render(FJZ)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V",
|
||||
ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
|
||||
public void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, PoseStack matrices) {
|
||||
if (ClientGuiEvent.RENDER_PRE.invoker().render(minecraft.screen, matrices, mouseX, mouseY, minecraft.getDeltaFrameTime()).isFalse()) {
|
||||
public void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, Matrix4f matrix, PoseStack matrices, PoseStack matrices2) {
|
||||
if (ClientGuiEvent.RENDER_PRE.invoker().render(minecraft.screen, matrices2, mouseX, mouseY, minecraft.getDeltaFrameTime()).isFalse()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
@@ -57,8 +59,8 @@ public abstract class MixinGameRenderer {
|
||||
@Inject(method = "render(FJZ)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V",
|
||||
shift = At.Shift.AFTER, ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
|
||||
public void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, PoseStack matrices) {
|
||||
ClientGuiEvent.RENDER_POST.invoker().render(minecraft.screen, matrices, mouseX, mouseY, minecraft.getDeltaFrameTime());
|
||||
public void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, Matrix4f matrix, PoseStack matrices, PoseStack matrices2) {
|
||||
ClientGuiEvent.RENDER_POST.invoker().render(minecraft.screen, matrices2, mouseX, mouseY, minecraft.getDeltaFrameTime());
|
||||
}
|
||||
|
||||
@Inject(method = "reloadShaders",
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of architectury.
|
||||
* Copyright (C) 2020, 2021, 2022 architectury
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package dev.architectury.mixin.fabric.client;
|
||||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.shaders.Program;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import dev.architectury.event.events.client.ClientGuiEvent;
|
||||
import dev.architectury.event.events.client.ClientReloadShadersEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
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.LocalCapture;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Mixin(value = GameRenderer.class, priority = 1100)
|
||||
public abstract class MixinGameRenderer013 {
|
||||
@Shadow
|
||||
@Final
|
||||
private Minecraft minecraft;
|
||||
|
||||
@Inject(method = "render(FJZ)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V",
|
||||
ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION, cancellable = true)
|
||||
public void renderScreenPre(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, Matrix4f matrix, PoseStack matrices, PoseStack matrices2) {
|
||||
if (ClientGuiEvent.RENDER_PRE.invoker().render(minecraft.screen, matrices2, mouseX, mouseY, minecraft.getDeltaFrameTime()).isFalse()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "render(FJZ)V",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/Screen;render(Lcom/mojang/blaze3d/vertex/PoseStack;IIF)V",
|
||||
shift = At.Shift.AFTER, ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
|
||||
public void renderScreenPost(float tickDelta, long startTime, boolean tick, CallbackInfo ci, int mouseX, int mouseY, Window window, Matrix4f matrix, PoseStack matrices, PoseStack matrices2) {
|
||||
ClientGuiEvent.RENDER_POST.invoker().render(minecraft.screen, matrices2, mouseX, mouseY, minecraft.getDeltaFrameTime());
|
||||
}
|
||||
|
||||
@Inject(method = "reloadShaders",
|
||||
at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 0), locals = LocalCapture.CAPTURE_FAILEXCEPTION)
|
||||
public void reloadShaders(ResourceManager resourceManager, CallbackInfo ci, List<Program> programs, List<Pair<ShaderInstance, Consumer<ShaderInstance>>> shaders) {
|
||||
ClientReloadShadersEvent.EVENT.invoker().reload(resourceManager, (shader, callback) -> {
|
||||
shaders.add(Pair.of(shader, callback));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,7 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
@@ -98,6 +99,16 @@ public abstract class MixinScreen implements ScreenInputDelegate {
|
||||
return message;
|
||||
}
|
||||
|
||||
@Inject(method = "renderTooltip(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/world/item/ItemStack;II)V", at = @At("HEAD"))
|
||||
private void preRenderTooltipItem(PoseStack poseStack, ItemStack stack, int x, int y, CallbackInfo ci) {
|
||||
ClientTooltipEvent.additionalContexts().setItem(stack);
|
||||
}
|
||||
|
||||
@Inject(method = "renderTooltip(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/world/item/ItemStack;II)V", at = @At("RETURN"))
|
||||
private void postRenderTooltipItem(PoseStack poseStack, ItemStack stack, int x, int y, CallbackInfo ci) {
|
||||
ClientTooltipEvent.additionalContexts().setItem(null);
|
||||
}
|
||||
|
||||
@Inject(method = "renderTooltipInternal", at = @At("HEAD"), cancellable = true)
|
||||
private void renderTooltip(PoseStack poseStack, List<? extends ClientTooltipComponent> list, int x, int y, CallbackInfo ci) {
|
||||
if (!list.isEmpty()) {
|
||||
|
||||
@@ -41,11 +41,11 @@ public class PlatformImpl {
|
||||
private static final Map<String, Mod> mods = new ConcurrentHashMap<>();
|
||||
|
||||
public static Path getGameFolder() {
|
||||
return FabricLoader.getInstance().getGameDir();
|
||||
return FabricLoader.getInstance().getGameDir().toAbsolutePath();
|
||||
}
|
||||
|
||||
public static Path getConfigFolder() {
|
||||
return FabricLoader.getInstance().getConfigDir();
|
||||
return FabricLoader.getInstance().getConfigDir().toAbsolutePath();
|
||||
}
|
||||
|
||||
public static Path getModsFolder() {
|
||||
@@ -88,7 +88,7 @@ public class PlatformImpl {
|
||||
private final ModMetadata metadata;
|
||||
|
||||
public ModImpl(String id) {
|
||||
this.container = FabricLoader.getInstance().getModContainer(id).get();
|
||||
this.container = FabricLoader.getInstance().getModContainer(id).orElseThrow();
|
||||
this.metadata = this.container.getMetadata();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
package dev.architectury.plugin.fabric;
|
||||
|
||||
import net.fabricmc.loader.api.*;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
@@ -38,29 +38,10 @@ public class ArchitecturyMixinPlugin implements IMixinConfigPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isLoader013() {
|
||||
ModContainer fabricLoader = FabricLoader.getInstance().getModContainer("fabricloader")
|
||||
.orElseThrow(() -> new IllegalStateException("Where is fabricloader?"));
|
||||
Version version = fabricLoader.getMetadata().getVersion();
|
||||
if (version instanceof SemanticVersion) {
|
||||
try {
|
||||
return version.compareTo(SemanticVersion.parse("0.13-")) >= 0;
|
||||
} catch (VersionParsingException e) {
|
||||
throw new IllegalStateException("Failed to parse version", e);
|
||||
}
|
||||
}
|
||||
System.err.println("FabricLoader is not a SemanticVersion, cannot determine if it is >= 0.13");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
|
||||
if ("dev.architectury.mixin.fabric.client.MixinEffectInstance".equals(mixinClassName)) {
|
||||
return !FabricLoader.getInstance().isModLoaded("satin");
|
||||
} else if ("dev.architectury.mixin.fabric.client.MixinGameRenderer".equals(mixinClassName)) {
|
||||
return !isLoader013();
|
||||
} else if ("dev.architectury.mixin.fabric.client.MixinGameRenderer013".equals(mixinClassName)) {
|
||||
return isLoader013();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
"client.MixinDebugScreenOverlay",
|
||||
"client.MixinEffectInstance",
|
||||
"client.MixinGameRenderer",
|
||||
"client.MixinGameRenderer013",
|
||||
"client.MixinIntegratedServer",
|
||||
"client.MixinKeyboardHandler",
|
||||
"client.MixinMinecraft",
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
"icon": "icon.png",
|
||||
"depends": {
|
||||
"minecraft": "~1.18-",
|
||||
"fabricloader": ">=0.12.0",
|
||||
"fabricloader": ">=0.13.0",
|
||||
"fabric": ">=0.44.0"
|
||||
},
|
||||
"custom": {
|
||||
|
||||
@@ -171,32 +171,42 @@ public class EventHandlerImplClient {
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public static void event(RenderTooltipEvent.Pre event) {
|
||||
PoseStack stack = event.getPoseStack();
|
||||
ClientTooltipEvent.additionalContexts().setItem(event.getItemStack());
|
||||
|
||||
if (ClientTooltipEvent.RENDER_PRE.invoker().renderTooltip(stack, event.getComponents(), event.getX(), event.getY()).isFalse()) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
try {
|
||||
if (ClientTooltipEvent.RENDER_PRE.invoker().renderTooltip(stack, event.getComponents(), event.getX(), event.getY()).isFalse()) {
|
||||
event.setCanceled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
TooltipEventPositionContextImpl positionContext = tooltipPositionContext.get();
|
||||
positionContext.reset(event.getX(), event.getY());
|
||||
ClientTooltipEvent.RENDER_MODIFY_POSITION.invoker().renderTooltip(stack, positionContext);
|
||||
event.setX(positionContext.getTooltipX());
|
||||
event.setY(positionContext.getTooltipY());
|
||||
} finally {
|
||||
ClientTooltipEvent.additionalContexts().setItem(null);
|
||||
}
|
||||
|
||||
TooltipEventPositionContextImpl positionContext = tooltipPositionContext.get();
|
||||
positionContext.reset(event.getX(), event.getY());
|
||||
ClientTooltipEvent.RENDER_MODIFY_POSITION.invoker().renderTooltip(stack, positionContext);
|
||||
event.setX(positionContext.getTooltipX());
|
||||
event.setY(positionContext.getTooltipY());
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
public static void event(RenderTooltipEvent.Color event) {
|
||||
PoseStack stack = event.getPoseStack();
|
||||
ClientTooltipEvent.additionalContexts().setItem(event.getItemStack());
|
||||
|
||||
TooltipEventColorContextImpl colorContext = tooltipColorContext.get();
|
||||
colorContext.reset();
|
||||
colorContext.setBackgroundColor(event.getBackgroundStart());
|
||||
colorContext.setOutlineGradientTopColor(event.getBorderStart());
|
||||
colorContext.setOutlineGradientBottomColor(event.getBorderEnd());
|
||||
ClientTooltipEvent.RENDER_MODIFY_COLOR.invoker().renderTooltip(stack, event.getX(), event.getY(), colorContext);
|
||||
event.setBackground(colorContext.getBackgroundColor());
|
||||
event.setBorderEnd(colorContext.getOutlineGradientBottomColor());
|
||||
event.setBorderStart(colorContext.getOutlineGradientTopColor());
|
||||
try {
|
||||
TooltipEventColorContextImpl colorContext = tooltipColorContext.get();
|
||||
colorContext.reset();
|
||||
colorContext.setBackgroundColor(event.getBackgroundStart());
|
||||
colorContext.setOutlineGradientTopColor(event.getBorderStart());
|
||||
colorContext.setOutlineGradientBottomColor(event.getBorderEnd());
|
||||
ClientTooltipEvent.RENDER_MODIFY_COLOR.invoker().renderTooltip(stack, event.getX(), event.getY(), colorContext);
|
||||
event.setBackground(colorContext.getBackgroundColor());
|
||||
event.setBorderEnd(colorContext.getOutlineGradientBottomColor());
|
||||
event.setBorderStart(colorContext.getOutlineGradientTopColor());
|
||||
} finally {
|
||||
ClientTooltipEvent.additionalContexts().setItem(null);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.HIGH)
|
||||
|
||||
@@ -59,7 +59,7 @@ public class MixinChunkSerializer {
|
||||
ChunkDataEvent.Load load = (ChunkDataEvent.Load) event;
|
||||
((EventHandlerImplCommon.WorldEventAttachment) load).architectury$attachLevel(levelRef.get());
|
||||
}
|
||||
level.set(null);
|
||||
level.remove();
|
||||
return event;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,9 +32,7 @@ public final class EventBuses {
|
||||
private static final Map<String, List<Consumer<IEventBus>>> ON_REGISTERED = new HashMap<>();
|
||||
|
||||
public static void registerModEventBus(String modId, IEventBus bus) {
|
||||
IEventBus previous = EVENT_BUS_MAP.put(modId, bus);
|
||||
if (previous != null) {
|
||||
EVENT_BUS_MAP.put(modId, previous);
|
||||
if (EVENT_BUS_MAP.putIfAbsent(modId, bus) != bus) {
|
||||
throw new IllegalStateException("Can't register event bus for mod '" + modId + "' because it was previously registered!");
|
||||
}
|
||||
|
||||
|
||||
@@ -92,11 +92,11 @@ public class PlatformImpl {
|
||||
private final IModInfo info;
|
||||
|
||||
public ModImpl(String id) {
|
||||
this.container = ModList.get().getModContainerById(id).get();
|
||||
this.container = ModList.get().getModContainerById(id).orElseThrow();
|
||||
this.info = ModList.get().getMods().stream()
|
||||
.filter(modInfo -> Objects.equals(modInfo.getModId(), id))
|
||||
.findAny()
|
||||
.get();
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,10 +21,8 @@ package dev.architectury.registry.registries.forge;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Suppliers;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Table;
|
||||
import dev.architectury.platform.forge.EventBuses;
|
||||
import dev.architectury.registry.registries.Registrar;
|
||||
import dev.architectury.registry.registries.RegistrarBuilder;
|
||||
@@ -43,10 +41,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@@ -67,10 +62,24 @@ public class RegistriesImpl {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class Data {
|
||||
private boolean collected = false;
|
||||
private final Map<RegistryObject<?>, Supplier<? extends IForgeRegistryEntry<?>>> objects = new LinkedHashMap<>();
|
||||
|
||||
public void register(IForgeRegistry registry, RegistryObject object, Supplier<? extends IForgeRegistryEntry<?>> reference) {
|
||||
if (!collected) {
|
||||
objects.put(object, reference);
|
||||
} else {
|
||||
registry.register(reference.get());
|
||||
object.updateReference(registry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class RegistryProviderImpl implements Registries.RegistryProvider {
|
||||
private final String modId;
|
||||
private final Supplier<IEventBus> eventBus;
|
||||
private final Table<Type, RegistryObject<?>, Supplier<? extends IForgeRegistryEntry<?>>> registry = HashBasedTable.create();
|
||||
private final Map<Type, Data> registry = new HashMap<>();
|
||||
private final Multimap<ResourceKey<Registry<?>>, Consumer<Registrar<?>>> listeners = HashMultimap.create();
|
||||
|
||||
public RegistryProviderImpl(String modId) {
|
||||
@@ -125,12 +134,18 @@ public class RegistriesImpl {
|
||||
IForgeRegistry registry = event.getRegistry();
|
||||
Registrar<Object> archRegistry = get(registry);
|
||||
|
||||
for (Map.Entry<Type, Map<RegistryObject<?>, Supplier<? extends IForgeRegistryEntry<?>>>> row : RegistryProviderImpl.this.registry.rowMap().entrySet()) {
|
||||
if (row.getKey() == event.getGenericType()) {
|
||||
for (Map.Entry<RegistryObject<?>, Supplier<? extends IForgeRegistryEntry<?>>> entry : row.getValue().entrySet()) {
|
||||
for (Map.Entry<Type, Data> typeDataEntry : RegistryProviderImpl.this.registry.entrySet()) {
|
||||
if (typeDataEntry.getKey() == registry.getRegistrySuperType()) {
|
||||
Data data = typeDataEntry.getValue();
|
||||
|
||||
data.collected = true;
|
||||
|
||||
for (Map.Entry<RegistryObject<?>, Supplier<? extends IForgeRegistryEntry<?>>> entry : data.objects.entrySet()) {
|
||||
registry.register(entry.getValue().get());
|
||||
entry.getKey().updateReference(registry);
|
||||
}
|
||||
|
||||
data.objects.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,9 +306,9 @@ public class RegistriesImpl {
|
||||
|
||||
public static class ForgeBackedRegistryImpl<T extends IForgeRegistryEntry<T>> implements Registrar<T> {
|
||||
private IForgeRegistry<T> delegate;
|
||||
private Table<Type, RegistryObject<?>, Supplier<? extends IForgeRegistryEntry<?>>> registry;
|
||||
private Map<Type, Data> registry;
|
||||
|
||||
public ForgeBackedRegistryImpl(Table<Type, RegistryObject<?>, Supplier<? extends IForgeRegistryEntry<?>>> registry, IForgeRegistry<T> delegate) {
|
||||
public ForgeBackedRegistryImpl(Map<Type, Data> registry, IForgeRegistry<T> delegate) {
|
||||
this.registry = registry;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
@@ -345,7 +360,8 @@ public class RegistriesImpl {
|
||||
@Override
|
||||
public @NotNull <E extends T> RegistrySupplier<E> register(ResourceLocation id, Supplier<E> supplier) {
|
||||
RegistryObject registryObject = RegistryObject.of(id, delegate);
|
||||
registry.put(delegate.getRegistrySuperType(), registryObject, () -> supplier.get().setRegistryName(id));
|
||||
registry.computeIfAbsent(delegate.getRegistrySuperType(), type -> new Data())
|
||||
.register(delegate, registryObject, () -> supplier.get().setRegistryName(id));
|
||||
return new RegistrySupplier<E>() {
|
||||
@Override
|
||||
public @NotNull ResourceLocation getRegistryId() {
|
||||
|
||||
@@ -10,7 +10,7 @@ cf_type=beta
|
||||
|
||||
archives_base_name=architectury
|
||||
archives_base_name_snapshot=architectury-snapshot
|
||||
base_version=3.6
|
||||
base_version=3.7
|
||||
maven_group=dev.architectury
|
||||
|
||||
fabric_loader_version=0.12.12
|
||||
|
||||
Reference in New Issue
Block a user