Merge remote-tracking branch 'architectury/1.18' into 1.18.2

This commit is contained in:
shedaniel
2022-02-19 00:58:24 +08:00
16 changed files with 212 additions and 141 deletions

View File

@@ -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 {
/**

View File

@@ -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;
}
}

View File

@@ -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();