Port for 1.21.9

This commit is contained in:
shedaniel
2025-10-02 18:09:01 +08:00
parent 97ceb68560
commit bc6c57c33a
102 changed files with 1408 additions and 1856 deletions

View File

@@ -1,93 +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.core.item;
import dev.architectury.registry.registries.RegistrySupplier;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.dispenser.BlockSource;
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
import net.minecraft.core.dispenser.DispenseItemBehavior;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.world.level.gameevent.GameEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import java.util.Objects;
public class ArchitecturySpawnEggItem extends SpawnEggItem {
private static final Logger LOGGER = LogManager.getLogger(ArchitecturySpawnEggItem.class);
private final RegistrySupplier<? extends EntityType<? extends Mob>> entityType;
protected static DispenseItemBehavior createDispenseItemBehavior() {
return new DefaultDispenseItemBehavior() {
@Override
public ItemStack execute(BlockSource source, ItemStack stack) {
Direction direction = source.state().getValue(DispenserBlock.FACING);
EntityType<?> entityType = ((SpawnEggItem) stack.getItem()).getType(source.level().registryAccess(), stack);
try {
entityType.spawn(source.level(), stack, null, source.pos().relative(direction), EntitySpawnReason.DISPENSER, direction != Direction.UP, false);
} catch (Exception var6) {
LOGGER.error("Error while dispensing spawn egg from dispenser at {}", source.pos(), var6);
return ItemStack.EMPTY;
}
stack.shrink(1);
source.level().gameEvent(null, GameEvent.ENTITY_PLACE, source.pos());
return stack;
}
};
}
public ArchitecturySpawnEggItem(RegistrySupplier<? extends EntityType<? extends Mob>> entityType, Properties properties) {
this(entityType, properties, createDispenseItemBehavior());
}
public ArchitecturySpawnEggItem(RegistrySupplier<? extends EntityType<? extends Mob>> entityType, Properties properties,
@Nullable DispenseItemBehavior dispenseItemBehavior) {
super(null, properties);
this.entityType = Objects.requireNonNull(entityType, "entityType");
SpawnEggItem.BY_ID.remove(null);
entityType.listen(type -> {
LOGGER.debug("Registering spawn egg {} for {}", toString(),
Objects.toString(type.arch$registryName()));
SpawnEggItem.BY_ID.put(type, this);
this.defaultType = type;
if (dispenseItemBehavior != null) {
DispenserBlock.registerBehavior(this, dispenseItemBehavior);
}
});
}
@Override
public EntityType<?> getType(HolderLookup.Provider provider, ItemStack itemStack) {
EntityType<?> type = super.getType(provider, itemStack);
return type == null ? entityType.get() : type;
}
}

View File

@@ -22,8 +22,6 @@ package dev.architectury.event;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.architectury.platform.Platform;
import dev.architectury.utils.Env;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
public final class EventHandler {
private EventHandler() {
@@ -42,7 +40,6 @@ public final class EventHandler {
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
private static void registerClient() {
throw new AssertionError();
}
@@ -53,7 +50,6 @@ public final class EventHandler {
}
@ExpectPlatform
@Environment(EnvType.SERVER)
private static void registerServer() {
throw new AssertionError();
}

View File

@@ -23,13 +23,10 @@ import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.EventResult;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public interface ClientChatEvent {
/**
* @see Send#send(String, Component)
@@ -40,7 +37,6 @@ public interface ClientChatEvent {
*/
Event<Received> RECEIVED = EventFactory.createCompoundEventResult();
@Environment(EnvType.CLIENT)
interface Send {
/**
* Event to cancel clients sending the chat message.
@@ -54,7 +50,6 @@ public interface ClientChatEvent {
EventResult send(String message, @Nullable Component component);
}
@Environment(EnvType.CLIENT)
interface Received {
/**
* Event to intercept the receiving of an chat message.

View File

@@ -24,8 +24,6 @@ import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.EventResult;
import dev.architectury.hooks.client.screen.ScreenAccess;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.DeltaTracker;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
@@ -33,7 +31,6 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import java.util.List;
@Environment(EnvType.CLIENT)
public interface ClientGuiEvent {
/**
* @see RenderHud#renderHud(GuiGraphics, float)
@@ -73,7 +70,6 @@ public interface ClientGuiEvent {
*/
Event<SetScreen> SET_SCREEN = EventFactory.createCompoundEventResult();
@Environment(EnvType.CLIENT)
interface RenderHud {
/**
* Invoked after the in-game hud has been rendered.
@@ -85,7 +81,6 @@ public interface ClientGuiEvent {
void renderHud(GuiGraphics graphics, DeltaTracker deltaTracker);
}
@Environment(EnvType.CLIENT)
interface DebugText {
/**
* Invoked when the debug text is being gathered for rendering.
@@ -97,7 +92,6 @@ public interface ClientGuiEvent {
void gatherText(List<String> strings);
}
@Environment(EnvType.CLIENT)
interface ScreenInitPre {
/**
* Invoked when a screen is being initialized and after the previous widgets have been cleared.
@@ -111,7 +105,6 @@ public interface ClientGuiEvent {
EventResult init(Screen screen, ScreenAccess access);
}
@Environment(EnvType.CLIENT)
interface ScreenInitPost {
/**
* Invoked after a screen has been initialized and all the vanilla initialization logic has happened.
@@ -123,7 +116,6 @@ public interface ClientGuiEvent {
void init(Screen screen, ScreenAccess access);
}
@Environment(EnvType.CLIENT)
interface ScreenRenderPre {
/**
* Invoked before any screen is rendered.
@@ -137,10 +129,9 @@ public interface ClientGuiEvent {
* @return A {@link EventResult} determining the outcome of the event,
* the vanilla render may be cancelled by the result.
*/
EventResult render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, DeltaTracker delta);
EventResult render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
}
@Environment(EnvType.CLIENT)
interface ScreenRenderPost {
/**
* Invoked after a screen has finished rendering using the vanilla logic.
@@ -152,10 +143,9 @@ public interface ClientGuiEvent {
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param delta The current tick delta.
*/
void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, DeltaTracker delta);
void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
}
@Environment(EnvType.CLIENT)
interface ContainerScreenRenderBackground {
/**
* Invoked after a container screen's background are rendered.
@@ -170,7 +160,6 @@ public interface ClientGuiEvent {
void render(AbstractContainerScreen<?> screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
}
@Environment(EnvType.CLIENT)
interface ContainerScreenRenderForeground {
/**
* Invoked after a screen has finished rendering most of the foreground, but before any floating widgets are rendered.
@@ -185,7 +174,6 @@ public interface ClientGuiEvent {
void render(AbstractContainerScreen<?> screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
}
@Environment(EnvType.CLIENT)
interface SetScreen {
/**
* Invoked before a new screen is set to open.

View File

@@ -22,12 +22,9 @@ package dev.architectury.event.events.client;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.events.common.LifecycleEvent;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
@Environment(EnvType.CLIENT)
public interface ClientLifecycleEvent {
/**
* Invoked when client has been initialised.
@@ -55,11 +52,9 @@ public interface ClientLifecycleEvent {
*/
Event<ClientState> CLIENT_SETUP = EventFactory.createLoop();
@Environment(EnvType.CLIENT)
interface ClientState extends LifecycleEvent.InstanceState<Minecraft> {
}
@Environment(EnvType.CLIENT)
interface ClientLevelState extends LifecycleEvent.LevelState<ClientLevel> {
}
}

View File

@@ -21,12 +21,9 @@ package dev.architectury.event.events.client;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.player.LocalPlayer;
import org.jetbrains.annotations.Nullable;
@Environment(EnvType.CLIENT)
public interface ClientPlayerEvent {
/**
* @see ClientPlayerJoin#join(LocalPlayer)
@@ -41,7 +38,6 @@ public interface ClientPlayerEvent {
*/
Event<ClientPlayerRespawn> CLIENT_PLAYER_RESPAWN = EventFactory.createLoop();
@Environment(EnvType.CLIENT)
interface ClientPlayerJoin {
/**
* Invoked whenever a client player joins a level
@@ -51,7 +47,6 @@ public interface ClientPlayerEvent {
void join(LocalPlayer player);
}
@Environment(EnvType.CLIENT)
interface ClientPlayerQuit {
/**
* Invoked whenever a client player leaves a level and is cleared on the client side.
@@ -61,7 +56,6 @@ public interface ClientPlayerEvent {
void quit(@Nullable LocalPlayer player);
}
@Environment(EnvType.CLIENT)
interface ClientPlayerRespawn {
/**
* Invoked whenever the player respawn packet is received by the client.

View File

@@ -22,11 +22,10 @@ package dev.architectury.event.events.client;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.EventResult;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.input.KeyEvent;
import net.minecraft.client.input.MouseButtonInfo;
@Environment(EnvType.CLIENT)
public interface ClientRawInputEvent {
/**
* @see MouseScrolled#mouseScrolled(Minecraft, double, double)
@@ -38,7 +37,7 @@ public interface ClientRawInputEvent {
Event<MouseClicked> MOUSE_CLICKED_PRE = EventFactory.createEventResult();
Event<MouseClicked> MOUSE_CLICKED_POST = EventFactory.createEventResult();
/**
* @see KeyPressed#keyPressed(Minecraft, int, int, int, int)
* @see KeyPressed#keyPressed(Minecraft, int, KeyEvent)
*/
Event<KeyPressed> KEY_PRESSED = EventFactory.createEventResult();
@@ -47,15 +46,13 @@ public interface ClientRawInputEvent {
* Invoked whenever a key input is performed.
* Equivalent to Forge's {@code InputEvent.KeyInputEvent} event.
*
* @param client The Minecraft instance performing it.
* @param keyCode The key code.
* @param scanCode The raw keyboard scan code.
* @param action The action that should be performed.
* @param modifiers Additional modifiers.
* @param client The Minecraft instance performing it.
* @param keyCode The key code.
* @param keyEvent The key event.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla pressing mechanism may be cancelled by the result.
*/
EventResult keyPressed(Minecraft client, int keyCode, int scanCode, int action, int modifiers);
EventResult keyPressed(Minecraft client, int keyCode, KeyEvent keyEvent);
}
interface MouseScrolled {
@@ -77,13 +74,12 @@ public interface ClientRawInputEvent {
* Invoked whenever a mouse button is pressed.
* There are two variants, either a raw mouse input or the input after it is processed by the game.
*
* @param client The Minecraft instance performing it.
* @param button The pressed mouse button.
* @param action The action that should be performed.
* @param mods Additional modifiers.
* @param client The Minecraft instance performing it.
* @param buttonInfo The pressed mouse button info.
* @param action The action that should be performed.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla clicking mechanism may be cancelled by the result.
*/
EventResult mouseClicked(Minecraft client, int button, int action, int mods);
EventResult mouseClicked(Minecraft client, MouseButtonInfo buttonInfo, int action);
}
}

View File

@@ -21,8 +21,6 @@ package dev.architectury.event.events.client;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.protocol.game.ClientboundRecipeBookAddPacket;
import net.minecraft.world.item.crafting.RecipeAccess;
import net.minecraft.world.item.crafting.display.RecipeDisplayId;
@@ -30,7 +28,6 @@ import org.jetbrains.annotations.ApiStatus;
import java.util.List;
@Environment(EnvType.CLIENT)
public interface ClientRecipeUpdateEvent {
/**
* @see ClientRecipeUpdateEvent#update(RecipeAccess)

View File

@@ -22,12 +22,12 @@ package dev.architectury.event.events.client;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.EventResult;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.input.CharacterEvent;
import net.minecraft.client.input.KeyEvent;
import net.minecraft.client.input.MouseButtonEvent;
@Environment(EnvType.CLIENT)
public interface ClientScreenInputEvent {
/**
* @see MouseScrolled#mouseScrolled(Minecraft, Screen, double, double, double, double)
@@ -50,17 +50,17 @@ public interface ClientScreenInputEvent {
Event<MouseDragged> MOUSE_DRAGGED_PRE = EventFactory.createEventResult();
Event<MouseDragged> MOUSE_DRAGGED_POST = EventFactory.createEventResult();
/**
* @see KeyTyped#charTyped(Minecraft, Screen, char, int)
* @see KeyTyped#charTyped(Minecraft, Screen, CharacterEvent)
*/
Event<KeyTyped> CHAR_TYPED_PRE = EventFactory.createEventResult();
Event<KeyTyped> CHAR_TYPED_POST = EventFactory.createEventResult();
/**
* @see KeyPressed#keyPressed(Minecraft, Screen, int, int, int)
* @see KeyPressed#keyPressed(Minecraft, Screen, KeyEvent)
*/
Event<KeyPressed> KEY_PRESSED_PRE = EventFactory.createEventResult();
Event<KeyPressed> KEY_PRESSED_POST = EventFactory.createEventResult();
/**
* @see KeyReleased#keyReleased(Minecraft, Screen, int, int, int)
* @see KeyReleased#keyReleased(Minecraft, Screen, KeyEvent)
*/
Event<KeyReleased> KEY_RELEASED_PRE = EventFactory.createEventResult();
Event<KeyReleased> KEY_RELEASED_POST = EventFactory.createEventResult();
@@ -73,15 +73,13 @@ public interface ClientScreenInputEvent {
* <p> This event is handled in two phases PRE and POST, which are invoked
* before and after the keys have been processed by the screen, respectively.
*
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param keyCode The key code.
* @param scanCode The raw keyboard scan code.
* @param modifiers Additional modifiers.
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param keyEvent The key event.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla pressing mechanism may be cancelled by the result.
*/
EventResult keyPressed(Minecraft client, Screen screen, int keyCode, int scanCode, int modifiers);
EventResult keyPressed(Minecraft client, Screen screen, KeyEvent keyEvent);
}
interface KeyReleased {
@@ -92,15 +90,13 @@ public interface ClientScreenInputEvent {
* <p> This event is handled in two phases PRE and POST, which are invoked
* before and after the keys have been processed by the screen, respectively.
*
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param keyCode The key code.
* @param scanCode The raw keyboard scan code.
* @param modifiers Additional modifiers.
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param keyEvent The key event.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla releasing mechanism may be cancelled by the result.
*/
EventResult keyReleased(Minecraft client, Screen screen, int keyCode, int scanCode, int modifiers);
EventResult keyReleased(Minecraft client, Screen screen, KeyEvent keyEvent);
}
interface KeyTyped {
@@ -111,14 +107,13 @@ public interface ClientScreenInputEvent {
* <p> This event is handled in two phases PRE and POST, which are invoked
* before and after the keys have been processed by the screen, respectively.
*
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param character The typed character.
* @param keyCode The key code.
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param characterEvent The character event.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla typing mechanism may be cancelled by the result.
*/
EventResult charTyped(Minecraft client, Screen screen, char character, int keyCode);
EventResult charTyped(Minecraft client, Screen screen, CharacterEvent characterEvent);
}
interface MouseScrolled {
@@ -149,15 +144,13 @@ public interface ClientScreenInputEvent {
* <p> This event is handled in two phases PRE and POST, which are invoked
* before and after the keys have been processed by the screen, respectively.
*
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param mouseX The scaled x-coordinate of the mouse cursor.
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param button The released mouse button.
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param buttonEvent The button click event.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla releasing mechanism may be cancelled by the result.
*/
EventResult mouseReleased(Minecraft client, Screen screen, double mouseX, double mouseY, int button);
EventResult mouseReleased(Minecraft client, Screen screen, MouseButtonEvent buttonEvent);
}
interface MouseDragged {
@@ -168,17 +161,15 @@ public interface ClientScreenInputEvent {
* <p> This event is handled in two phases PRE and POST, which are invoked
* before and after the keys have been processed by the screen, respectively.
*
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param mouseX1 The initial scaled x-coordinate of the mouse cursor.
* @param mouseY1 The initial scaled y-coordinate of the mouse cursor.
* @param button The dragged mouse button.
* @param mouseX2 The final scaled x-coordinate of the mouse cursor.
* @param mouseY2 The final scaled y-coordinate of the mouse cursor.
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param buttonEvent The mouse event.
* @param mouseX2 The final scaled x-delta of the mouse cursor.
* @param mouseY2 The final scaled y-delta of the mouse cursor.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla dragging mechanism may be cancelled by the result.
*/
EventResult mouseDragged(Minecraft client, Screen screen, double mouseX1, double mouseY1, int button, double mouseX2, double mouseY2);
EventResult mouseDragged(Minecraft client, Screen screen, MouseButtonEvent buttonEvent, double mouseX2, double mouseY2);
}
interface MouseClicked {
@@ -189,14 +180,13 @@ public interface ClientScreenInputEvent {
* <p> This event is handled in two phases PRE and POST, which are invoked
* before and after the keys have been processed by the screen, respectively.
*
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param mouseX The scaled x-coordinate of the mouse cursor.
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param button The clicked mouse button.
* @param client The Minecraft instance performing it.
* @param screen The screen this keystroke was performed in.
* @param buttonEvent The button click event.
* @param doubleClick Whether the click is a double click.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla clicking mechanism may be cancelled by the result.
*/
EventResult mouseClicked(Minecraft client, Screen screen, double mouseX, double mouseY, int button);
EventResult mouseClicked(Minecraft client, Screen screen, MouseButtonEvent buttonEvent, boolean doubleClick);
}
}

View File

@@ -22,18 +22,14 @@ package dev.architectury.event.events.client;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.chat.Component;
@Environment(EnvType.CLIENT)
public interface ClientSystemMessageEvent {
/**
* @see Received#process(Component)
*/
Event<Received> RECEIVED = EventFactory.createCompoundEventResult();
@Environment(EnvType.CLIENT)
interface Received {
/**
* Event to intercept the receiving of a system message.

View File

@@ -21,11 +21,8 @@ package dev.architectury.event.events.client;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
@Environment(EnvType.CLIENT)
public interface ClientTickEvent<T> {
Event<Client> CLIENT_PRE = EventFactory.createLoop();
Event<Client> CLIENT_POST = EventFactory.createLoop();
@@ -34,11 +31,9 @@ public interface ClientTickEvent<T> {
void tick(T instance);
@Environment(EnvType.CLIENT)
interface Client extends ClientTickEvent<Minecraft> {
}
@Environment(EnvType.CLIENT)
interface ClientLevel extends ClientTickEvent<net.minecraft.client.multiplayer.ClientLevel> {
}
}

View File

@@ -23,8 +23,6 @@ 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.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.network.chat.Component;
@@ -35,7 +33,6 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
@Environment(EnvType.CLIENT)
public interface ClientTooltipEvent {
/**
* @see Item#append(ItemStack, List, net.minecraft.world.item.Item.TooltipContext, TooltipFlag)
@@ -62,7 +59,6 @@ public interface ClientTooltipEvent {
void setItem(@Nullable ItemStack stack);
}
@Environment(EnvType.CLIENT)
interface Item {
/**
* Invoked whenever an item tooltip is rendered.
@@ -77,7 +73,6 @@ public interface ClientTooltipEvent {
void append(ItemStack stack, List<Component> lines, net.minecraft.world.item.Item.TooltipContext tooltipContext, TooltipFlag flag);
}
@Environment(EnvType.CLIENT)
interface Render {
/**
* Invoked before the tooltip for a tooltip is rendered.
@@ -92,7 +87,6 @@ public interface ClientTooltipEvent {
EventResult renderTooltip(GuiGraphics graphics, List<? extends ClientTooltipComponent> texts, int x, int y);
}
@Environment(EnvType.CLIENT)
interface RenderModifyPosition {
/**
* Event to manipulate the position of the tooltip.
@@ -103,7 +97,6 @@ public interface ClientTooltipEvent {
void renderTooltip(GuiGraphics graphics, PositionContext context);
}
@Environment(EnvType.CLIENT)
interface PositionContext {
int getTooltipX();

View File

@@ -0,0 +1,85 @@
/*
* 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.hooks.client.fluid;
import dev.architectury.fluid.FluidStack;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import org.jetbrains.annotations.Nullable;
public class ClientFluidStackHooks {
private ClientFluidStackHooks() {
}
@ExpectPlatform
@Nullable
public static TextureAtlasSprite getStillTexture(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos, FluidState state) {
throw new AssertionError();
}
@ExpectPlatform
@Nullable
public static TextureAtlasSprite getStillTexture(FluidStack stack) {
throw new AssertionError();
}
@ExpectPlatform
@Nullable
public static TextureAtlasSprite getStillTexture(Fluid fluid) {
throw new AssertionError();
}
@ExpectPlatform
@Nullable
public static TextureAtlasSprite getFlowingTexture(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos, FluidState state) {
throw new AssertionError();
}
@ExpectPlatform
@Nullable
public static TextureAtlasSprite getFlowingTexture(FluidStack stack) {
throw new AssertionError();
}
@ExpectPlatform
@Nullable
public static TextureAtlasSprite getFlowingTexture(Fluid fluid) {
throw new AssertionError();
}
@ExpectPlatform
public static int getColor(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos, FluidState state) {
throw new AssertionError();
}
@ExpectPlatform
public static int getColor(FluidStack stack) {
throw new AssertionError();
}
@ExpectPlatform
public static int getColor(Fluid fluid) {
throw new AssertionError();
}
}

View File

@@ -20,8 +20,6 @@
package dev.architectury.hooks.client.screen;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Renderable;
import net.minecraft.client.gui.components.events.GuiEventListener;
@@ -30,7 +28,6 @@ import net.minecraft.client.gui.screens.Screen;
import java.util.List;
@Environment(EnvType.CLIENT)
public final class ScreenHooks {
private ScreenHooks() {
}

View File

@@ -102,66 +102,6 @@ public class FluidStackHooks {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
@Nullable
public static TextureAtlasSprite getStillTexture(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos, FluidState state) {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
@Nullable
public static TextureAtlasSprite getStillTexture(FluidStack stack) {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
@Nullable
public static TextureAtlasSprite getStillTexture(Fluid fluid) {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
@Nullable
public static TextureAtlasSprite getFlowingTexture(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos, FluidState state) {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
@Nullable
public static TextureAtlasSprite getFlowingTexture(FluidStack stack) {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
@Nullable
public static TextureAtlasSprite getFlowingTexture(Fluid fluid) {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
public static int getColor(@Nullable BlockAndTintGetter level, @Nullable BlockPos pos, FluidState state) {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
public static int getColor(FluidStack stack) {
throw new AssertionError();
}
@ExpectPlatform
@Environment(EnvType.CLIENT)
public static int getColor(Fluid fluid) {
throw new AssertionError();
}
/**
* Returns the luminosity of the fluid.
*

View File

@@ -48,7 +48,7 @@ public abstract class MixinLightningBolt extends Entity {
by = 1
), locals = LocalCapture.CAPTURE_FAILHARD)
public void handleLightning(CallbackInfo ci, List<Entity> list) {
if (this.isRemoved() || this.level().isClientSide) {
if (this.isRemoved() || this.level().isClientSide()) {
return;
}

View File

@@ -0,0 +1,58 @@
/*
* 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.networking;
import dev.architectury.extensions.network.EntitySpawnExtension;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Minecraft;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.phys.Vec3;
public class ClientSpawnEntityPacket {
public static void register() {
NetworkManager.registerReceiver(NetworkManager.s2c(), SpawnEntityPacket.PACKET_TYPE, SpawnEntityPacket.PACKET_CODEC, ClientSpawnEntityPacket::receive);
}
private static void receive(SpawnEntityPacket.PacketPayload payload, NetworkManager.PacketContext context) {
context.queue(() -> {
if (Minecraft.getInstance().level == null) {
throw new IllegalStateException("Client world is null!");
}
var entity = payload.entityType().create(Minecraft.getInstance().level, EntitySpawnReason.LOAD);
if (entity == null) {
throw new IllegalStateException("Created entity is null!");
}
entity.setUUID(payload.uuid());
entity.setId(payload.id());
entity.syncPacketPositionCodec(payload.x(), payload.y(), payload.z());
entity.snapTo(payload.x(), payload.y(), payload.z(), payload.xRot(), payload.yRot());
entity.setYHeadRot(payload.yHeadRot());
entity.setYBodyRot(payload.yHeadRot());
if (entity instanceof EntitySpawnExtension ext) {
RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(payload.data()), context.registryAccess());
ext.loadAdditionalSpawnData(buf);
buf.release();
}
Minecraft.getInstance().level.addEntity(entity);
entity.lerpMotion(new Vec3(payload.deltaX(), payload.deltaY(), payload.deltaZ()));
});
}
}

View File

@@ -1,132 +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.networking;
import com.google.common.collect.Maps;
import dev.architectury.networking.NetworkManager.PacketContext;
import dev.architectury.platform.Platform;
import dev.architectury.utils.Env;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* Forge {@code SimpleChannel} like network wrapper of {@link NetworkManager}.
*/
@Deprecated(forRemoval = true)
public final class NetworkChannel {
private final ResourceLocation id;
private final Map<Class<?>, MessageInfo<?>> encoders = Maps.newHashMap();
private NetworkChannel(ResourceLocation id) {
this.id = id;
}
public static NetworkChannel create(ResourceLocation id) {
return new NetworkChannel(id);
}
public <T> void register(Class<T> type, BiConsumer<T, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, T> decoder, BiConsumer<T, Supplier<PacketContext>> messageConsumer) {
// TODO: this is pretty wasteful; add a way to specify custom or numeric ids
var s = UUID.nameUUIDFromBytes(type.getName().getBytes(StandardCharsets.UTF_8)).toString().replace("-", "");
var info = new MessageInfo<T>(ResourceLocation.parse(id + "/" + s), encoder, decoder, messageConsumer);
encoders.put(type, info);
NetworkManager.NetworkReceiver<RegistryFriendlyByteBuf> receiver = (buf, context) -> {
info.messageConsumer.accept(info.decoder.apply(buf), () -> context);
};
NetworkManager.registerReceiver(NetworkManager.c2s(), info.packetId, receiver);
if (Platform.getEnvironment() == Env.CLIENT) {
NetworkManager.registerReceiver(NetworkManager.s2c(), info.packetId, receiver);
}
}
public static long hashCodeString(String str) {
long h = 0;
var length = str.length();
for (var i = 0; i < length; i++) {
h = 31 * h + str.charAt(i);
}
return h;
}
public <T> Packet<?> toPacket(NetworkManager.Side side, T message, RegistryAccess access) {
var messageInfo = (MessageInfo<T>) Objects.requireNonNull(encoders.get(message.getClass()), "Unknown message type! " + message);
var buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), access);
messageInfo.encoder.accept(message, buf);
return NetworkManager.toPacket(side, messageInfo.packetId, buf);
}
public <T> void sendToPlayer(ServerPlayer player, T message) {
Objects.requireNonNull(player, "Unable to send packet to a 'null' player!").connection.send(toPacket(NetworkManager.s2c(), message, player.registryAccess()));
}
public <T> void sendToPlayers(Iterable<ServerPlayer> players, T message) {
Iterator<ServerPlayer> iterator = players.iterator();
if (!iterator.hasNext()) return;
var packet = toPacket(NetworkManager.s2c(), message, iterator.next().registryAccess());
for (var player : players) {
Objects.requireNonNull(player, "Unable to send packet to a 'null' player!").connection.send(packet);
}
}
@Environment(EnvType.CLIENT)
public <T> void sendToServer(T message) {
ClientPacketListener connection = Minecraft.getInstance().getConnection();
if (connection != null) {
connection.send(toPacket(NetworkManager.c2s(), message, connection.registryAccess()));
} else {
throw new IllegalStateException("Unable to send packet to the server while not in game!");
}
}
@Environment(EnvType.CLIENT)
public <T> boolean canServerReceive(Class<T> type) {
return NetworkManager.canServerReceive(encoders.get(type).packetId);
}
public <T> boolean canPlayerReceive(ServerPlayer player, Class<T> type) {
return NetworkManager.canPlayerReceive(player, encoders.get(type).packetId);
}
private record MessageInfo<T>(
ResourceLocation packetId,
BiConsumer<T, FriendlyByteBuf> encoder,
Function<FriendlyByteBuf, T> decoder,
BiConsumer<T, Supplier<PacketContext>> messageConsumer
) {
}
}

View File

@@ -26,10 +26,7 @@ import dev.architectury.networking.transformers.PacketSink;
import dev.architectury.networking.transformers.PacketTransformer;
import dev.architectury.networking.transformers.SinglePacketCollector;
import dev.architectury.utils.Env;
import dev.architectury.utils.GameInstance;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.StreamCodec;
@@ -147,7 +144,6 @@ public final class NetworkManager {
collectPackets(PacketSink.ofPlayers(players), serverToClient(), id, buf);
}
@Environment(EnvType.CLIENT)
@Deprecated(forRemoval = true)
public static void sendToServer(ResourceLocation id, RegistryFriendlyByteBuf buf) {
collectPackets(PacketSink.client(), clientToServer(), id, buf);
@@ -163,14 +159,11 @@ public final class NetworkManager {
collectPackets(PacketSink.ofPlayers(players), serverToClient(), payload, iterator.next().registryAccess());
}
@Environment(EnvType.CLIENT)
@ExpectPlatform
public static <T extends CustomPacketPayload> void sendToServer(T payload) {
ClientPacketListener connection = GameInstance.getClient().getConnection();
if (connection == null) return;
collectPackets(PacketSink.client(), clientToServer(), payload, connection.registryAccess());
throw new AssertionError();
}
@Environment(EnvType.CLIENT)
@ExpectPlatform
public static boolean canServerReceive(ResourceLocation id) {
throw new AssertionError();
@@ -181,7 +174,6 @@ public final class NetworkManager {
throw new AssertionError();
}
@Environment(EnvType.CLIENT)
public static boolean canServerReceive(CustomPacketPayload.Type<?> type) {
return canServerReceive(type.id());
}

View File

@@ -22,9 +22,6 @@ package dev.architectury.networking;
import dev.architectury.extensions.network.EntitySpawnExtension;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.FriendlyByteBuf;
@@ -37,7 +34,6 @@ import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.EntityType;
import java.util.UUID;
@@ -46,9 +42,9 @@ import java.util.UUID;
* @see net.minecraft.network.protocol.game.ClientboundAddEntityPacket
*/
public class SpawnEntityPacket {
private static final ResourceLocation PACKET_ID = ResourceLocation.fromNamespaceAndPath("architectury", "spawn_entity_packet");
private static final CustomPacketPayload.Type<PacketPayload> PACKET_TYPE = new CustomPacketPayload.Type<>(PACKET_ID);
private static final StreamCodec<RegistryFriendlyByteBuf, PacketPayload> PACKET_CODEC = CustomPacketPayload.codec(PacketPayload::write, PacketPayload::new);
static final ResourceLocation PACKET_ID = ResourceLocation.fromNamespaceAndPath("architectury", "spawn_entity_packet");
static final CustomPacketPayload.Type<PacketPayload> PACKET_TYPE = new CustomPacketPayload.Type<>(PACKET_ID);
static final StreamCodec<RegistryFriendlyByteBuf, PacketPayload> PACKET_CODEC = CustomPacketPayload.codec(PacketPayload::write, PacketPayload::new);
public static Packet<ClientGamePacketListener> create(Entity entity, ServerEntity serverEntity) {
if (entity.level().isClientSide()) {
@@ -61,42 +57,7 @@ public class SpawnEntityPacket {
NetworkManager.registerS2CPayloadType(PACKET_TYPE, PACKET_CODEC);
}
@Environment(EnvType.CLIENT)
public static class Client {
@Environment(EnvType.CLIENT)
public static void register() {
NetworkManager.registerReceiver(NetworkManager.s2c(), PACKET_TYPE, PACKET_CODEC, Client::receive);
}
@Environment(EnvType.CLIENT)
private static void receive(PacketPayload payload, NetworkManager.PacketContext context) {
context.queue(() -> {
if (Minecraft.getInstance().level == null) {
throw new IllegalStateException("Client world is null!");
}
var entity = payload.entityType().create(Minecraft.getInstance().level, EntitySpawnReason.LOAD);
if (entity == null) {
throw new IllegalStateException("Created entity is null!");
}
entity.setUUID(payload.uuid());
entity.setId(payload.id());
entity.syncPacketPositionCodec(payload.x(), payload.y(), payload.z());
entity.snapTo(payload.x(), payload.y(), payload.z(), payload.xRot(), payload.yRot());
entity.setYHeadRot(payload.yHeadRot());
entity.setYBodyRot(payload.yHeadRot());
if (entity instanceof EntitySpawnExtension ext) {
RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.wrappedBuffer(payload.data()), context.registryAccess());
ext.loadAdditionalSpawnData(buf);
buf.release();
}
Minecraft.getInstance().level.addEntity(entity);
entity.lerpMotion(payload.deltaX(), payload.deltaY(), payload.deltaZ());
});
}
}
private record PacketPayload(EntityType<?> entityType, UUID uuid, int id, double x, double y, double z, float xRot,
record PacketPayload(EntityType<?> entityType, UUID uuid, int id, double x, double y, double z, float xRot,
float yRot,
float yHeadRot,
double deltaX, double deltaY, double deltaZ,

View File

@@ -1,91 +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.networking.simple;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.level.chunk.LevelChunk;
/**
* The base class for server -&gt; client messages managed by a {@link SimpleNetworkManager}.
*/
public abstract class BaseS2CMessage extends Message {
private void sendTo(ServerPlayer player, Packet<?> packet) {
if (player == null) {
throw new NullPointerException("Unable to send packet '" + getType().getId() + "' to a 'null' player!");
}
player.connection.send(packet);
}
/**
* Sends this message to a player.
*
* @param player the player
*/
public final void sendTo(ServerPlayer player) {
sendTo(player, toPacket(player.registryAccess()));
}
/**
* Sends this message to multiple players.
*
* @param players the players
*/
public final void sendTo(Iterable<ServerPlayer> players) {
if (!players.iterator().hasNext()) return;
Packet<?> packet = toPacket(players.iterator().next().registryAccess());
for (ServerPlayer player : players) {
sendTo(player, packet);
}
}
/**
* Sends this message to all players in the server.
*
* @param server the server
*/
public final void sendToAll(MinecraftServer server) {
sendTo(server.getPlayerList().getPlayers());
}
/**
* Sends this message to all players in a level.
*
* @param level the level
*/
public final void sendToLevel(ServerLevel level) {
sendTo(level.players());
}
/**
* Sends this message to all players listening to a chunk.
*
* @param chunk the listened chunk
*/
public final void sendToChunkListeners(LevelChunk chunk) {
Packet<?> packet = toPacket(chunk.getLevel().registryAccess());
((ServerChunkCache) chunk.getLevel().getChunkSource()).chunkMap.getPlayers(chunk.getPos(), false).forEach(e -> sendTo(e, packet));
}
}

View File

@@ -1,71 +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.networking.simple;
import dev.architectury.networking.NetworkManager;
import io.netty.buffer.Unpooled;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
/**
* The base class for messages managed by a {@link SimpleNetworkManager}.
*
* @see BaseC2SMessage
* @see BaseS2CMessage
*/
public abstract class Message {
Message() {
}
/**
* Returns the {@link MessageType} of this message
*
* @return the {@link MessageType} of this message
* @see SimpleNetworkManager#registerC2S(String, MessageDecoder)
* @see SimpleNetworkManager#registerS2C(String, MessageDecoder)
*/
public abstract MessageType getType();
/**
* Writes this message to a byte buffer.
*
* @param buf the byte buffer
*/
public abstract void write(RegistryFriendlyByteBuf buf);
/**
* Handles this message when it is received.
*
* @param context the packet context for handling this message
*/
public abstract void handle(NetworkManager.PacketContext context);
/**
* Converts this message into a corresponding vanilla {@link Packet}.
*
* @return the converted {@link Packet}
*/
public final Packet<?> toPacket(RegistryAccess access) {
RegistryFriendlyByteBuf buf = new RegistryFriendlyByteBuf(Unpooled.buffer(), access);
write(buf);
return NetworkManager.toPacket(getType().getSide(), getType().getId(), buf);
}
}

View File

@@ -1,55 +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.networking.simple;
import dev.architectury.networking.NetworkManager;
import net.minecraft.network.RegistryFriendlyByteBuf;
/**
* Decodes a {@link Message} from a {@link RegistryFriendlyByteBuf}.
*
* @param <T> the message type handled by this decoder
* @author LatvianModder
*/
@FunctionalInterface
public interface MessageDecoder<T extends Message> {
/**
* Decodes a {@code T} message from a byte buffer.
*
* @param buf the byte buffer
* @return the decoded instance
*/
T decode(RegistryFriendlyByteBuf buf);
/**
* Creates a network receiver from this decoder.
*
* <p>The returned receiver will first {@linkplain #decode(RegistryFriendlyByteBuf) decode a message}
* and then call {@link Message#handle(NetworkManager.PacketContext)} on the decoded message.
*
* @return the created receiver
*/
default NetworkManager.NetworkReceiver<RegistryFriendlyByteBuf> createReceiver() {
return (buf, context) -> {
Message packet = decode(buf);
context.queue(() -> packet.handle(context));
};
}
}

View File

@@ -1,89 +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.networking.simple;
import dev.architectury.networking.NetworkManager;
import net.minecraft.resources.ResourceLocation;
import java.util.Objects;
/**
* A unique type for a message in a {@link SimpleNetworkManager}.
*/
public final class MessageType {
private final SimpleNetworkManager manager;
private final ResourceLocation id;
private final NetworkManager.Side side;
MessageType(SimpleNetworkManager manager, ResourceLocation id, NetworkManager.Side side) {
this.manager = manager;
this.id = id;
this.side = side;
}
/**
* Returns the network manager that manages this message type
*
* @return the network manager that manages this message type
*/
public SimpleNetworkManager getManager() {
return manager;
}
/**
* Returns the ID of this message type
*
* @return the ID of this message type
*/
public ResourceLocation getId() {
return id;
}
/**
* Returns the network side of this message type
*
* @return the network side of this message type
*/
public NetworkManager.Side getSide() {
return side;
}
@Override
public String toString() {
return id.toString() + ":" + side.name().toLowerCase();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
MessageType messageType = (MessageType) o;
return id.equals(messageType.id) && side == messageType.side;
}
@Override
public int hashCode() {
return Objects.hash(id, side);
}
}

View File

@@ -1,115 +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.networking.simple;
import dev.architectury.networking.NetworkManager;
import dev.architectury.networking.transformers.PacketTransformer;
import dev.architectury.platform.Platform;
import dev.architectury.utils.Env;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
import java.util.List;
/**
* A simple wrapper for {@link NetworkManager} to make it easier to register messages and send them to clients/servers.
*/
public class SimpleNetworkManager {
/**
* Creates a new {@code SimpleNetworkManager}.
*
* @param namespace a unique namespace for the messages ({@link #namespace})
* @return the created network manager
*/
public static SimpleNetworkManager create(String namespace) {
return new SimpleNetworkManager(namespace);
}
/**
* The unique namespace for the messages managed by this manager.
* This will typically be a mod ID.
*/
public final String namespace;
private SimpleNetworkManager(String namespace) {
this.namespace = namespace;
}
/**
* Registers a server -&gt; client message with no packet transformers.
*
* @param id a unique ID for the message, must be a valid value for {@link ResourceLocation#getPath}
* @param decoder the message decoder for the message
* @return a {@link MessageType} describing the registered message
* @see #registerS2C(String, MessageDecoder, List)
*/
public MessageType registerS2C(String id, MessageDecoder<BaseS2CMessage> decoder) {
return registerS2C(id, decoder, List.of());
}
/**
* Registers a server -&gt; client message using the given packet transformers.
*
* @param id a unique ID for the message, must be a valid value for {@link ResourceLocation#getPath}
* @param decoder the message decoder for the message
* @param transformers a list of packet transformers to apply to the message packet
* @return a {@link MessageType} describing the registered message
*/
@ApiStatus.Experimental
public MessageType registerS2C(String id, MessageDecoder<BaseS2CMessage> decoder, List<PacketTransformer> transformers) {
MessageType messageType = new MessageType(this, ResourceLocation.fromNamespaceAndPath(namespace, id), NetworkManager.s2c());
if (Platform.getEnvironment() == Env.CLIENT) {
NetworkManager.NetworkReceiver<RegistryFriendlyByteBuf> receiver = decoder.createReceiver();
NetworkManager.registerReceiver(NetworkManager.s2c(), messageType.getId(), transformers, receiver);
}
return messageType;
}
/**
* Registers a client -&gt; server message with no packet transformers.
*
* @param id a unique ID for the message, must be a valid value for {@link ResourceLocation#getPath}
* @param decoder the message decoder for the message
* @return a {@link MessageType} describing the registered message
* @see #registerC2S(String, MessageDecoder, List)
*/
public MessageType registerC2S(String id, MessageDecoder<BaseC2SMessage> decoder) {
return registerC2S(id, decoder, List.of());
}
/**
* Registers a client -&gt; server message using the given packet transformers.
*
* @param id a unique ID for the message, must be a valid value for {@link ResourceLocation#getPath}
* @param decoder the message decoder for the message
* @param transformers a list of packet transformers to apply to the message packet
* @return a {@link MessageType} describing the registered message
*/
@ApiStatus.Experimental
public MessageType registerC2S(String id, MessageDecoder<BaseC2SMessage> decoder, List<PacketTransformer> transformers) {
MessageType messageType = new MessageType(this, ResourceLocation.fromNamespaceAndPath(namespace, id), NetworkManager.c2s());
NetworkManager.NetworkReceiver<RegistryFriendlyByteBuf> receiver = decoder.createReceiver();
NetworkManager.registerReceiver(NetworkManager.c2s(), messageType.getId(), transformers, receiver);
return messageType;
}
}

View File

@@ -19,8 +19,6 @@
package dev.architectury.networking.transformers;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.network.protocol.Packet;
import net.minecraft.server.level.ServerPlayer;
@@ -41,7 +39,6 @@ public interface PacketSink {
};
}
@Environment(EnvType.CLIENT)
static PacketSink client() {
return packet -> {
if (Minecraft.getInstance().getConnection() != null) {

View File

@@ -19,15 +19,13 @@
package dev.architectury.networking.transformers;
import dev.architectury.event.events.client.ClientPlayerEvent;
import dev.architectury.event.events.common.PlayerEvent;
import dev.architectury.networking.NetworkManager;
import dev.architectury.networking.transformers.client.ClientSplitPacketTransformer;
import dev.architectury.utils.Env;
import dev.architectury.utils.EnvExecutor;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.LogManager;
@@ -46,47 +44,17 @@ public class SplitPacketTransformer implements PacketTransformer {
private static final byte END = 0x2;
private static final byte ONLY = 0x3;
private static class PartKey {
private final NetworkManager.Side side;
@Nullable
private final UUID playerUUID;
public PartKey(NetworkManager.Side side, @Nullable UUID playerUUID) {
this.side = side;
this.playerUUID = playerUUID;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof PartKey)) return false;
PartKey key = (PartKey) o;
return side == key.side && Objects.equals(playerUUID, key.playerUUID);
}
@Override
public int hashCode() {
return Objects.hash(side, playerUUID);
}
@Override
public String toString() {
return "PartKey{" +
"side=" + side +
", playerUUID=" + playerUUID +
'}';
}
@ApiStatus.Internal
public record PartKey(NetworkManager.Side side, @Nullable UUID playerUUID) {
}
private static class PartData {
private final ResourceLocation id;
private final int partsExpected;
private final List<RegistryFriendlyByteBuf> parts;
public PartData(ResourceLocation id, int partsExpected) {
this.id = id;
this.partsExpected = partsExpected;
this.parts = new ArrayList<>();
public record PartData(
ResourceLocation id,
int partsExpected,
List<RegistryFriendlyByteBuf> parts
) {
private PartData(ResourceLocation id, int partsExpected) {
this(id, partsExpected, new ArrayList<>());
}
}
@@ -96,16 +64,7 @@ public class SplitPacketTransformer implements PacketTransformer {
PlayerEvent.PLAYER_QUIT.register(player -> {
cache.keySet().removeIf(key -> Objects.equals(key.playerUUID, player.getUUID()));
});
EnvExecutor.runInEnv(Env.CLIENT, () -> new Client()::init);
}
private class Client {
@Environment(EnvType.CLIENT)
private void init() {
ClientPlayerEvent.CLIENT_PLAYER_QUIT.register(player -> {
cache.keySet().removeIf(key -> key.side == NetworkManager.Side.S2C);
});
}
EnvExecutor.runInEnv(Env.CLIENT, () -> () -> ClientSplitPacketTransformer.init(cache));
}
@Override
@@ -204,7 +163,7 @@ public class SplitPacketTransformer implements PacketTransformer {
buf.skipBytes(next);
sink.accept(side, id, packetBuffer);
}
buf.release();
}
}

View File

@@ -17,25 +17,18 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.networking.simple;
package dev.architectury.networking.transformers.client;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import dev.architectury.event.events.client.ClientPlayerEvent;
import dev.architectury.networking.NetworkManager;
import dev.architectury.networking.transformers.SplitPacketTransformer;
/**
* The base class for client -&gt; server messages managed by a {@link SimpleNetworkManager}.
*/
public abstract class BaseC2SMessage extends Message {
/**
* Sends this message to the server.
*/
@Environment(EnvType.CLIENT)
public final void sendToServer() {
if (Minecraft.getInstance().getConnection() != null) {
Minecraft.getInstance().getConnection().send(toPacket(Minecraft.getInstance().level.registryAccess()));
} else {
throw new IllegalStateException("Unable to send packet to the server while not in game!");
}
import java.util.Map;
public class ClientSplitPacketTransformer {
public static void init(Map<SplitPacketTransformer.PartKey, SplitPacketTransformer.PartData> cache) {
ClientPlayerEvent.CLIENT_PLAYER_QUIT.register(player -> {
cache.keySet().removeIf(key -> key.side() == NetworkManager.Side.S2C);
});
}
}

View File

@@ -19,9 +19,6 @@
package dev.architectury.platform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screens.Screen;
import org.jetbrains.annotations.Nullable;
import java.nio.file.Path;
@@ -80,13 +77,4 @@ public interface Mod {
Optional<String> getSources();
Optional<String> getIssueTracker();
@Environment(EnvType.CLIENT)
void registerConfigurationScreen(ConfigurationScreenProvider provider);
@Environment(EnvType.CLIENT)
@FunctionalInterface
interface ConfigurationScreenProvider {
Screen provide(Screen parent);
}
}

View File

@@ -17,5 +17,20 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@Deprecated(forRemoval = true)
package dev.architectury.networking.simple;
package dev.architectury.platform.client;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.architectury.platform.Mod;
import net.minecraft.client.gui.screens.Screen;
public class ConfigurationScreenRegistry {
@ExpectPlatform
public static void register(Mod mod, ConfigurationScreenProvider provider) {
throw new AssertionError();
}
@FunctionalInterface
public interface ConfigurationScreenProvider {
Screen provide(Screen parent);
}
}

View File

@@ -20,8 +20,6 @@
package dev.architectury.registry.client.gui;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.world.inventory.tooltip.TooltipComponent;
@@ -30,7 +28,6 @@ import java.util.function.Function;
/**
* Registry for {@link ClientTooltipComponent} factories
*/
@Environment(EnvType.CLIENT)
public final class ClientTooltipComponentRegistry {
private ClientTooltipComponentRegistry() {
}

View File

@@ -0,0 +1,62 @@
/*
* 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.registry.client.gui;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.MenuAccess;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
public class MenuScreenRegistry {
/**
* Registers a Screen Factory on the client to display.
*
* @param type The {@link MenuType} the screen visualizes
* @param factory A functional interface that is used to create new {@link Screen}s
* @param <H> The type of {@link AbstractContainerMenu} for the screen
* @param <S> The type for the {@link Screen}
*/
@ExpectPlatform
public static <H extends AbstractContainerMenu, S extends Screen & MenuAccess<H>> void registerScreenFactory(MenuType<? extends H> type, ScreenFactory<H, S> factory) {
throw new AssertionError();
}
/**
* Creates new screens.
*
* @param <H> The type of {@link AbstractContainerMenu} for the screen
* @param <S> The type for the {@link Screen}
*/
@FunctionalInterface
public interface ScreenFactory<H extends AbstractContainerMenu, S extends Screen & MenuAccess<H>> {
/**
* Creates a new {@link S} that extends {@link Screen}
*
* @param containerMenu The {@link AbstractContainerMenu} that controls the game logic for the screen
* @param inventory The {@link Inventory} for the screen
* @param component The {@link Component} for the screen
* @return A new {@link S} that extends {@link Screen}
*/
S create(H containerMenu, Inventory inventory, Component component);
}
}

View File

@@ -20,11 +20,8 @@
package dev.architectury.registry.client.keymappings;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.KeyMapping;
@Environment(EnvType.CLIENT)
public final class KeyMappingRegistry {
private KeyMappingRegistry() {
}

View File

@@ -20,14 +20,11 @@
package dev.architectury.registry.client.level.entity;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import java.util.function.Supplier;
@Environment(EnvType.CLIENT)
public class EntityModelLayerRegistry {
@ExpectPlatform
public static void register(ModelLayerLocation location, Supplier<LayerDefinition> definition) {

View File

@@ -20,15 +20,12 @@
package dev.architectury.registry.client.level.entity;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import java.util.function.Supplier;
@Environment(EnvType.CLIENT)
public final class EntityRendererRegistry {
private EntityRendererRegistry() {
}

View File

@@ -20,10 +20,7 @@
package dev.architectury.registry.client.particle;
import dev.architectury.event.events.client.ClientLifecycleEvent;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.architectury.registry.registries.RegistrySupplier;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.particle.ParticleProvider;
import net.minecraft.client.particle.SpriteSet;
import net.minecraft.client.renderer.texture.TextureAtlas;
@@ -44,7 +41,6 @@ import java.util.List;
* or use the helper methods {@link #register(RegistrySupplier, ParticleProvider)} and {@link #register(RegistrySupplier, DeferredParticleProvider)},
* which will automatically handle the listening for you.
*/
@Environment(EnvType.CLIENT)
public final class ParticleProviderRegistry {
public interface ExtendedSpriteSet extends SpriteSet {
TextureAtlas getAtlas();

View File

@@ -20,19 +20,17 @@
package dev.architectury.registry.client.rendering;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.blockentity.state.BlockEntityRenderState;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
@Environment(EnvType.CLIENT)
public final class BlockEntityRendererRegistry {
private BlockEntityRendererRegistry() {
}
@ExpectPlatform
public static <T extends BlockEntity> void register(BlockEntityType<T> type, BlockEntityRendererProvider<? super T> provider) {
public static <E extends BlockEntity, S extends BlockEntityRenderState> void register(BlockEntityType<E> type, BlockEntityRendererProvider<? super E, ? super S> provider) {
throw new AssertionError();
}
}

View File

@@ -20,15 +20,12 @@
package dev.architectury.registry.client.rendering;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.world.level.block.Block;
import java.util.Objects;
import java.util.function.Supplier;
@Environment(EnvType.CLIENT)
public final class ColorHandlerRegistry {
private ColorHandlerRegistry() {
}

View File

@@ -20,13 +20,10 @@
package dev.architectury.registry.client.rendering;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.chunk.ChunkSectionLayer;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Fluid;
@Environment(EnvType.CLIENT)
public final class RenderTypeRegistry {
private RenderTypeRegistry() {
}

View File

@@ -20,10 +20,7 @@
package dev.architectury.registry.menu;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.MenuAccess;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerPlayer;
@@ -38,6 +35,7 @@ import java.util.function.Consumer;
/**
* A utility class to register {@link MenuType}s and {@link Screen}s for containers
* @see dev.architectury.registry.client.gui.MenuScreenRegistry
*/
public final class MenuRegistry {
private MenuRegistry() {
@@ -117,40 +115,6 @@ public final class MenuRegistry {
throw new AssertionError();
}
/**
* Registers a Screen Factory on the client to display.
*
* @param type The {@link MenuType} the screen visualizes
* @param factory A functional interface that is used to create new {@link Screen}s
* @param <H> The type of {@link AbstractContainerMenu} for the screen
* @param <S> The type for the {@link Screen}
*/
@Environment(EnvType.CLIENT)
@ExpectPlatform
public static <H extends AbstractContainerMenu, S extends Screen & MenuAccess<H>> void registerScreenFactory(MenuType<? extends H> type, ScreenFactory<H, S> factory) {
throw new AssertionError();
}
/**
* Creates new screens.
*
* @param <H> The type of {@link AbstractContainerMenu} for the screen
* @param <S> The type for the {@link Screen}
*/
@Environment(EnvType.CLIENT)
@FunctionalInterface
public interface ScreenFactory<H extends AbstractContainerMenu, S extends Screen & MenuAccess<H>> {
/**
* Creates a new {@link S} that extends {@link Screen}
*
* @param containerMenu The {@link AbstractContainerMenu} that controls the game logic for the screen
* @param inventory The {@link Inventory} for the screen
* @param component The {@link Component} for the screen
* @return A new {@link S} that extends {@link Screen}
*/
S create(H containerMenu, Inventory inventory, Component component);
}
/**
* Creates simple menus.
*

View File

@@ -20,18 +20,10 @@
package dev.architectury.utils;
import dev.architectury.injectables.annotations.ExpectPlatform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import org.jetbrains.annotations.Nullable;
public final class GameInstance {
@Environment(EnvType.CLIENT)
public static Minecraft getClient() {
return Minecraft.getInstance();
}
@Nullable
@ExpectPlatform
public static MinecraftServer getServer() {

View File

@@ -120,16 +120,12 @@ transitive-accessible method net/minecraft/client/renderer/RenderType create (Lj
transitive-accessible class net/minecraft/client/renderer/RenderType$CompositeState
transitive-accessible class net/minecraft/client/renderer/RenderType$CompositeRenderType
transitive-accessible class net/minecraft/client/renderer/RenderType$OutlineProperty
accessible class net/minecraft/client/resources/model/AtlasSet$AtlasEntry
accessible field net/minecraft/world/item/SpawnEggItem BY_ID Ljava/util/Map;
accessible field net/minecraft/world/item/SpawnEggItem defaultType Lnet/minecraft/world/entity/EntityType;
mutable field net/minecraft/world/item/SpawnEggItem defaultType Lnet/minecraft/world/entity/EntityType;
accessible field net/minecraft/client/particle/ParticleEngine textureAtlas Lnet/minecraft/client/renderer/texture/TextureAtlas;
accessible class net/minecraft/client/particle/ParticleEngine$MutableSpriteSet
accessible field net/minecraft/client/particle/ParticleEngine$MutableSpriteSet sprites Ljava/util/List;
accessible class net/minecraft/client/particle/ParticleResources$MutableSpriteSet
accessible field net/minecraft/client/particle/ParticleResources$MutableSpriteSet sprites Ljava/util/List;
transitive-accessible class net/minecraft/world/item/CreativeModeTab$Output
transitive-accessible class net/minecraft/world/item/CreativeModeTab$TabVisibility
accessible field net/minecraft/client/multiplayer/MultiPlayerGameMode connection Lnet/minecraft/client/multiplayer/ClientPacketListener;
accessible field net/minecraft/client/Minecraft particleResources Lnet/minecraft/client/particle/ParticleResources;
##############################
# This section is generated automatically with Gradle task generateAccessWidener!!!
@@ -154,7 +150,7 @@ transitive-accessible method net/minecraft/world/level/block/CakeBlock <init> (L
transitive-accessible method net/minecraft/world/level/block/CandleCakeBlock <init> (Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CartographyTableBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CarvedPumpkinBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/ChestBlock <init> (Ljava/util/function/Supplier;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/ChestBlock <init> (Ljava/util/function/Supplier;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundEvent;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/ChorusFlowerBlock <init> (Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/ChorusPlantBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/CoralFanBlock <init> (Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
@@ -174,7 +170,6 @@ transitive-accessible method net/minecraft/world/level/block/EndPortalBlock <ini
transitive-accessible method net/minecraft/world/level/block/EndRodBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/EnderChestBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/FarmBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/FletchingTableBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/FlowerBedBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/FungusBlock <init> (Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/block/Block;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/FurnaceBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
@@ -230,9 +225,13 @@ transitive-accessible method net/minecraft/world/level/block/WallSkullBlock <ini
transitive-accessible method net/minecraft/world/level/block/WallTorchBlock <init> (Lnet/minecraft/core/particles/SimpleParticleType;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WaterlilyBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WaterloggedTransparentBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WeatheringCopperBarsBlock <init> (Lnet/minecraft/world/level/block/WeatheringCopper$WeatherState;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WeatheringCopperChainBlock <init> (Lnet/minecraft/world/level/block/WeatheringCopper$WeatherState;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WeatheringCopperDoorBlock <init> (Lnet/minecraft/world/level/block/state/properties/BlockSetType;Lnet/minecraft/world/level/block/WeatheringCopper$WeatherState;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WeatheringCopperGrateBlock <init> (Lnet/minecraft/world/level/block/WeatheringCopper$WeatherState;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WeatheringCopperTrapDoorBlock <init> (Lnet/minecraft/world/level/block/state/properties/BlockSetType;Lnet/minecraft/world/level/block/WeatheringCopper$WeatherState;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WeatheringLanternBlock <init> (Lnet/minecraft/world/level/block/WeatheringCopper$WeatherState;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WeatheringLightningRodBlock <init> (Lnet/minecraft/world/level/block/WeatheringCopper$WeatherState;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WeightedPressurePlateBlock <init> (ILnet/minecraft/world/level/block/state/properties/BlockSetType;Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WetSpongeBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
transitive-accessible method net/minecraft/world/level/block/WitherSkullBlock <init> (Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;)V
@@ -256,8 +255,6 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard VIEW_
transitive-accessible field net/minecraft/client/renderer/RenderStateShard VIEW_OFFSET_Z_LAYERING_FORWARD Lnet/minecraft/client/renderer/RenderStateShard$LayeringStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard MAIN_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard OUTLINE_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard TRANSLUCENT_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard PARTICLES_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard WEATHER_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard ITEM_ENTITY_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard DEFAULT_LINE Lnet/minecraft/client/renderer/RenderStateShard$LineStateShard;
@@ -304,6 +301,7 @@ transitive-accessible field net/minecraft/client/renderer/RenderPipelines PARTIC
transitive-accessible field net/minecraft/client/renderer/RenderPipelines WEATHER_SNIPPET Lcom/mojang/blaze3d/pipeline/RenderPipeline$Snippet;
transitive-accessible field net/minecraft/client/renderer/RenderPipelines GUI_SNIPPET Lcom/mojang/blaze3d/pipeline/RenderPipeline$Snippet;
transitive-accessible field net/minecraft/client/renderer/RenderPipelines GUI_TEXTURED_SNIPPET Lcom/mojang/blaze3d/pipeline/RenderPipeline$Snippet;
transitive-accessible field net/minecraft/client/renderer/RenderPipelines GUI_TEXT_SNIPPET Lcom/mojang/blaze3d/pipeline/RenderPipeline$Snippet;
transitive-accessible field net/minecraft/client/renderer/RenderPipelines OUTLINE_SNIPPET Lcom/mojang/blaze3d/pipeline/RenderPipeline$Snippet;
# CreativeModeTabs fields