mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
Forge 1.19
* Bump pack.mcmeta formats * 1.19 biome modifiers * Mark ClientPlayerNetworkEvent.LoggedOutEvent's getters as nullable * Add docs and package-info to client extension interfaces package * Move RenderBlockOverlayEvent hooks to ForgeHooksClient * Add package-infos to client events package * Rename SoundLoadEvent to SoundEngineLoadEvent This reduces confusion from consumers which may think the name SoundLoadEvent refers to an individual sound being loaded rather than the sound engine. * Document and change SoundLoadEvent to fire on mod bus Previously, it fired on both the mod bus and the Forge bus, which is confusing for consumers. * Delete SoundSetupEvent Looking at its original implementation shows that there isn't an appropriate place in the new sound code to reinsert the event, and the place of 'sound engine/manager initialization event' is taken already by SoundLoadEvent. * Perform some cleanup on client events - Removed nullable annotations from ClientPlayerNetworkEvent - Renamed #getPartialTicks methods to #getPartialTick, to be consistent with vanilla's naming of the partial tick - Cleanup documentation to remove line breaks, use the spelling 'cancelled' over 'canceled', and improve docs on existing and new methods. * Remove EntityEvent.CanUpdate Closes MinecraftForge/MinecraftForge#6394 * Switch to Jetbrains nullability annotations * New PlayLevelSoundEvent; replaces old PlaySoundAtEntityEvent * Remove ForgeWorldPresetScreens * Remove IForgeRegistryEntry * Remove use of List<Throwable> in FML's CompletableFutures * Add docs to mod loading stages, stages, and phases * Gradle 7.4.2 * Use SLF4J in FMLLoader and other subprojects * Switch dynamic versions in subprojects to pinned ones * Switch ForgeRoot and MDK to FG plugin markers * Configure Forge javadoc task The task now uses a custom stylesheet with MCForge elements, and configured to combine the generation from the four FML subprojects (fmlloader, fmlcore, javafmllanguage, mclanguage) and the Forge project into the javadoc output. * Update docs/md files, for 1.19 update and the move away from IRC to Discord. * Make "Potentially dangerous alternative prefix" a debug warning, not info. Co-authored-by: Curle <[email protected]> Co-authored-by: sciwhiz12 <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
270e778ac5
commit
4ed9117799
1485 files changed
+14960
-15446
No files matched your search
@@ -14,7 +14,6 @@ import com.mojang.brigadier.suggestion.SuggestionProvider;
|
||||
import com.mojang.brigadier.tree.CommandNode;
|
||||
import com.mojang.brigadier.tree.RootCommandNode;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
@@ -22,12 +21,7 @@ import net.minecraft.commands.CommandRuntimeException;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.synchronization.SuggestionProviders;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.ComponentUtils;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraftforge.client.event.ClientPlayerNetworkEvent;
|
||||
import net.minecraftforge.client.event.RegisterClientCommandsEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -79,11 +73,6 @@ public class ClientCommandHandler
|
||||
CommandDispatcher<SharedSuggestionProvider> newServerCommands = new CommandDispatcher<>();
|
||||
copy(serverCommandsRoot, newServerCommands.getRoot());
|
||||
|
||||
// Copies the server side commands into a temporary server side commands root node to be used later without the client commands
|
||||
RootCommandNode<SharedSuggestionProvider> serverCommandsCopy = new RootCommandNode<>();
|
||||
CommandHelper.mergeCommandNode(newServerCommands.getRoot(), serverCommandsCopy, new IdentityHashMap<>(),
|
||||
Minecraft.getInstance().getConnection().getSuggestionsProvider(), (context) -> 0, (suggestions) -> null);
|
||||
|
||||
// Copies the client side commands into the server side commands to be used for suggestions
|
||||
CommandHelper.mergeCommandNode(commands.getRoot(), newServerCommands.getRoot(), new IdentityHashMap<>(), getSource(), (context) -> 0, (suggestions) -> {
|
||||
SuggestionProvider<SharedSuggestionProvider> suggestionProvider = SuggestionProviders
|
||||
@@ -105,12 +94,6 @@ public class ClientCommandHandler
|
||||
return suggestionProvider;
|
||||
});
|
||||
|
||||
// Copies the server side commands into the client side commands so that they can be sent to the server as a chat message
|
||||
CommandHelper.mergeCommandNode(serverCommandsCopy, commands.getRoot(), new IdentityHashMap<>(), Minecraft.getInstance().getConnection().getSuggestionsProvider(),
|
||||
(context) -> {
|
||||
Minecraft.getInstance().player.chat((context.getInput().startsWith("/") ? "" : "/") + context.getInput());
|
||||
return 0;
|
||||
}, (suggestions) -> null);
|
||||
return newServerCommands;
|
||||
}
|
||||
|
||||
@@ -159,23 +142,17 @@ public class ClientCommandHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* Always try to execute the cached parsing of client message as a command. Requires that the execute field of the commands to be set to send to server so that they aren't
|
||||
* Always try to execute the cached parsing of a typed command as a clientside command. Requires that the execute field of the commands to be set to send to server so that they aren't\
|
||||
* treated as client command's that do nothing.
|
||||
*
|
||||
* {@link net.minecraft.commands.Commands#performCommand(CommandSourceStack, String)} for reference
|
||||
*
|
||||
* @param sendMessage
|
||||
* the chat message
|
||||
* @return false leaves the message to be sent to the server, true means it should be caught before {@link LocalPlayer#chat(String)}
|
||||
* @param command the full command to execute, no preceding slash
|
||||
* @return {@code false} leaves the message to be sent to the server, while {@code true} means it should be caught before LocalPlayer#sendCommand
|
||||
*/
|
||||
public static boolean sendMessage(String sendMessage)
|
||||
public static boolean runCommand(String command)
|
||||
{
|
||||
StringReader reader = new StringReader(sendMessage);
|
||||
|
||||
if (!reader.canRead() || reader.read() != '/')
|
||||
{
|
||||
return false;
|
||||
}
|
||||
StringReader reader = new StringReader(command);
|
||||
|
||||
ClientCommandSourceStack source = getSource();
|
||||
|
||||
@@ -185,7 +162,7 @@ public class ClientCommandHandler
|
||||
}
|
||||
catch (CommandRuntimeException execution)// Probably thrown by the command
|
||||
{
|
||||
Minecraft.getInstance().player.sendMessage(new TextComponent("").append(execution.getComponent()).withStyle(ChatFormatting.RED), Util.NIL_UUID);
|
||||
Minecraft.getInstance().player.sendSystemMessage(Component.literal("").append(execution.getComponent()).withStyle(ChatFormatting.RED));
|
||||
}
|
||||
catch (CommandSyntaxException syntax)// Usually thrown by the CommandDispatcher
|
||||
{
|
||||
@@ -194,12 +171,12 @@ public class ClientCommandHandler
|
||||
// in case of unknown command, let the server try and handle it
|
||||
return false;
|
||||
}
|
||||
Minecraft.getInstance().player.sendMessage(
|
||||
new TextComponent("").append(ComponentUtils.fromMessage(syntax.getRawMessage())).withStyle(ChatFormatting.RED), Util.NIL_UUID);
|
||||
Minecraft.getInstance().player.sendSystemMessage(
|
||||
Component.literal("").append(ComponentUtils.fromMessage(syntax.getRawMessage())).withStyle(ChatFormatting.RED));
|
||||
if (syntax.getInput() != null && syntax.getCursor() >= 0)
|
||||
{
|
||||
int position = Math.min(syntax.getInput().length(), syntax.getCursor());
|
||||
MutableComponent details = new TextComponent("")
|
||||
MutableComponent details = Component.literal("")
|
||||
.withStyle(ChatFormatting.GRAY)
|
||||
.withStyle((style) -> style
|
||||
.withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, reader.getString())));
|
||||
@@ -210,21 +187,20 @@ public class ClientCommandHandler
|
||||
details.append(syntax.getInput().substring(Math.max(0, position - 10), position));
|
||||
if (position < syntax.getInput().length())
|
||||
{
|
||||
details.append(new TextComponent(syntax.getInput().substring(position)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE));
|
||||
details.append(Component.literal(syntax.getInput().substring(position)).withStyle(ChatFormatting.RED, ChatFormatting.UNDERLINE));
|
||||
}
|
||||
details.append(new TranslatableComponent("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
||||
Minecraft.getInstance().player.sendMessage(new TextComponent("").append(details).withStyle(ChatFormatting.RED), Util.NIL_UUID);
|
||||
details.append(Component.translatable("command.context.here").withStyle(ChatFormatting.RED, ChatFormatting.ITALIC));
|
||||
Minecraft.getInstance().player.sendSystemMessage(Component.literal("").append(details).withStyle(ChatFormatting.RED));
|
||||
}
|
||||
}
|
||||
catch (Exception generic)// Probably thrown by the command
|
||||
{
|
||||
TextComponent message = new TextComponent(generic.getMessage() == null ? generic.getClass().getName() : generic.getMessage());
|
||||
Minecraft.getInstance().player.sendMessage(new TranslatableComponent("command.failed")
|
||||
MutableComponent message = Component.literal(generic.getMessage() == null ? generic.getClass().getName() : generic.getMessage());
|
||||
Minecraft.getInstance().player.sendSystemMessage(Component.translatable("command.failed")
|
||||
.withStyle(ChatFormatting.RED)
|
||||
.withStyle((style) -> style
|
||||
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, message))),
|
||||
Util.NIL_UUID);
|
||||
LOGGER.error("Error executing client command \"{}\"", sendMessage, generic);
|
||||
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, message))));
|
||||
LOGGER.error("Error executing client command \"{}\"", command, generic);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ClientCommandSourceStack extends CommandSourceStack
|
||||
@Override
|
||||
public void sendSuccess(Component message, boolean sendToAdmins)
|
||||
{
|
||||
Minecraft.getInstance().player.sendMessage(message, Util.NIL_UUID);
|
||||
Minecraft.getInstance().player.sendSystemMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,16 +5,15 @@
|
||||
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FluidContainerColorer implements ItemColor
|
||||
{
|
||||
@Override
|
||||
public int getColor(@Nonnull ItemStack stack, int tintIndex)
|
||||
public int getColor(@NotNull ItemStack stack, int tintIndex)
|
||||
{
|
||||
if (tintIndex != 1) return 0xFFFFFFFF;
|
||||
return FluidUtil.getFluidContained(stack)
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import net.minecraft.client.gui.chat.NarratorChatListener;
|
||||
import net.minecraft.client.gui.components.toasts.SystemToast;
|
||||
import net.minecraft.client.gui.screens.ConfirmScreen;
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.gui.screens.multiplayer.JoinMultiplayerScreen;
|
||||
@@ -30,10 +29,13 @@ import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.*;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.server.WorldStem;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -43,12 +45,10 @@ import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.components.LerpingBossEvent;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.client.renderer.*;
|
||||
import net.minecraft.client.renderer.FogRenderer.FogMode;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.client.model.HumanoidModel;
|
||||
@@ -77,6 +77,7 @@ import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.client.player.Input;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
import net.minecraft.world.level.storage.LevelStorageSource;
|
||||
import net.minecraft.world.level.storage.PrimaryLevelData;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
@@ -90,7 +91,6 @@ import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.*;
|
||||
import net.minecraftforge.client.event.sound.PlaySoundEvent;
|
||||
@@ -115,8 +115,6 @@ import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -127,7 +125,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@@ -143,6 +140,8 @@ import static net.minecraftforge.fml.VersionChecker.Status.BETA_OUTDATED;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.renderer.entity.ItemRenderer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ForgeHooksClient
|
||||
{
|
||||
@@ -214,11 +213,11 @@ public class ForgeHooksClient
|
||||
{
|
||||
switch (target.getType()) {
|
||||
case BLOCK:
|
||||
if (!(target instanceof BlockHitResult)) return false;
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawSelectionEvent.HighlightBlock(context, camera, target, partialTick, poseStack, bufferSource));
|
||||
if (!(target instanceof BlockHitResult blockTarget)) return false;
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawSelectionEvent.HighlightBlock(context, camera, blockTarget, partialTick, poseStack, bufferSource));
|
||||
case ENTITY:
|
||||
if (!(target instanceof EntityHitResult)) return false;
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawSelectionEvent.HighlightEntity(context, camera, target, partialTick, poseStack, bufferSource));
|
||||
if (!(target instanceof EntityHitResult entityTarget)) return false;
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawSelectionEvent.HighlightEntity(context, camera, entityTarget, partialTick, poseStack, bufferSource));
|
||||
default:
|
||||
return MinecraftForge.EVENT_BUS.post(new DrawSelectionEvent(context, camera, target, partialTick, poseStack, bufferSource));
|
||||
}
|
||||
@@ -316,7 +315,7 @@ public class ForgeHooksClient
|
||||
{
|
||||
FOVModifierEvent fovModifierEvent = new FOVModifierEvent(entity, fov);
|
||||
MinecraftForge.EVENT_BUS.post(fovModifierEvent);
|
||||
return fovModifierEvent.getNewfov();
|
||||
return fovModifierEvent.getNewFov();
|
||||
}
|
||||
|
||||
public static double getFieldOfView(GameRenderer renderer, Camera camera, double partialTick, double fov) {
|
||||
@@ -340,9 +339,9 @@ public class ForgeHooksClient
|
||||
if (status == BETA || status == BETA_OUTDATED)
|
||||
{
|
||||
// render a warning at the top of the screen,
|
||||
Component line = new TranslatableComponent("forge.update.beta.1", ChatFormatting.RED, ChatFormatting.RESET).withStyle(ChatFormatting.RED);
|
||||
Component line = Component.translatable("forge.update.beta.1", ChatFormatting.RED, ChatFormatting.RESET).withStyle(ChatFormatting.RED);
|
||||
GuiComponent.drawCenteredString(poseStack, font, line, width / 2, 4 + (0 * (font.lineHeight + 1)), 0xFFFFFF | alpha);
|
||||
line = new TranslatableComponent("forge.update.beta.2");
|
||||
line = Component.translatable("forge.update.beta.2");
|
||||
GuiComponent.drawCenteredString(poseStack, font, line, width / 2, 4 + (1 * (font.lineHeight + 1)), 0xFFFFFF | alpha);
|
||||
}
|
||||
|
||||
@@ -361,6 +360,7 @@ public class ForgeHooksClient
|
||||
}
|
||||
|
||||
public static String forgeStatusLine;
|
||||
@Nullable
|
||||
public static SoundInstance playSound(SoundEngine manager, SoundInstance sound)
|
||||
{
|
||||
PlaySoundEvent e = new PlaySoundEvent(manager, sound);
|
||||
@@ -387,23 +387,7 @@ public class ForgeHooksClient
|
||||
MinecraftForge.EVENT_BUS.post(new ScreenEvent.DrawScreenEvent.Post(screen, poseStack, mouseX, mouseY, partialTick));
|
||||
}
|
||||
|
||||
public static float getFogDensity(FogMode type, Camera camera, float partialTick, float density)
|
||||
{
|
||||
EntityViewRenderEvent.FogDensity event = new EntityViewRenderEvent.FogDensity(type, camera, partialTick, density);
|
||||
if (MinecraftForge.EVENT_BUS.post(event)) return event.getDensity();
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated to be removed in 1.19, use other onFogRender hook with more params
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static void onFogRender(FogMode type, Camera camera, float partialTick, float distance)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EntityViewRenderEvent.RenderFogEvent(type, camera, partialTick, distance));
|
||||
}
|
||||
|
||||
public static void onFogRender(FogMode type, Camera camera, float partialTick, float nearDistance, float farDistance, FogShape shape)
|
||||
public static void onFogRender(FogType type, Camera camera, float partialTick, float nearDistance, float farDistance, FogShape shape)
|
||||
{
|
||||
EntityViewRenderEvent.RenderFogEvent event = new EntityViewRenderEvent.RenderFogEvent(type, camera, partialTick, nearDistance, farDistance, shape);
|
||||
if (MinecraftForge.EVENT_BUS.post(event))
|
||||
@@ -541,7 +525,7 @@ public class ForgeHooksClient
|
||||
|
||||
private static int slotMainHand = 0;
|
||||
|
||||
public static boolean shouldCauseReequipAnimation(@Nonnull ItemStack from, @Nonnull ItemStack to, int slot)
|
||||
public static boolean shouldCauseReequipAnimation(@NotNull ItemStack from, @NotNull ItemStack to, int slot)
|
||||
{
|
||||
boolean fromInvalid = from.isEmpty();
|
||||
boolean toInvalid = to.isEmpty();
|
||||
@@ -765,36 +749,11 @@ public class ForgeHooksClient
|
||||
{
|
||||
setRenderType(rendertype);
|
||||
VertexConsumer ivertexbuilder = bufferSource.getBuffer(rendertype == RenderType.translucent() ? RenderType.translucentMovingBlock() : rendertype);
|
||||
blockRenderer.getModelRenderer().tesselateBlock(level, blockRenderer.getBlockModel(state), state, pos, stack, ivertexbuilder, checkSides, new Random(), state.getSeed(pos), packedOverlay);
|
||||
blockRenderer.getModelRenderer().tesselateBlock(level, blockRenderer.getBlockModel(state), state, pos, stack, ivertexbuilder, checkSides, RandomSource.create(), state.getSeed(pos), packedOverlay);
|
||||
});
|
||||
setRenderType(null);
|
||||
}
|
||||
|
||||
public static void registerForgeWorldPresetScreens()
|
||||
{
|
||||
ForgeWorldPresetScreens.registerPresets();
|
||||
}
|
||||
|
||||
public static WorldPreset.PresetEditor getPresetEditor(Optional<WorldPreset> generator, @Nullable WorldPreset.PresetEditor biomegeneratortypescreens$ifactory)
|
||||
{
|
||||
return ForgeWorldPresetScreens.getPresetEditor(generator, biomegeneratortypescreens$ifactory);
|
||||
}
|
||||
|
||||
public static boolean hasPresetEditor(Optional<WorldPreset> generator)
|
||||
{
|
||||
return getPresetEditor(generator, null) != null;
|
||||
}
|
||||
|
||||
public static Optional<WorldPreset> getWorldPresetFromGenerator(WorldGenSettings dimensionGeneratorSettings)
|
||||
{
|
||||
return WorldPreset.of(dimensionGeneratorSettings);
|
||||
}
|
||||
|
||||
public static Optional<WorldPreset> getDefaultWorldPreset()
|
||||
{
|
||||
return Optional.of(ForgeWorldPresetScreens.getDefaultPreset());
|
||||
}
|
||||
|
||||
public static boolean shouldRenderEffect(MobEffectInstance effectInstance)
|
||||
{
|
||||
return RenderProperties.getEffectRenderer(effectInstance).shouldRender(effectInstance);
|
||||
@@ -808,7 +767,7 @@ public class ForgeHooksClient
|
||||
int atlasWidth, int atlasHeight,
|
||||
int spriteX, int spriteY, int mipmapLevel,
|
||||
NativeImage image
|
||||
)
|
||||
) throws IOException
|
||||
{
|
||||
ForgeTextureMetadata metadata = ForgeTextureMetadata.forResource(resource);
|
||||
return metadata.getLoader() == null ? null : metadata.getLoader().load(textureAtlas, resourceManager, textureInfo, resource, atlasWidth, atlasHeight, spriteX, spriteY, mipmapLevel, image);
|
||||
@@ -929,7 +888,7 @@ public class ForgeHooksClient
|
||||
if(relativeMouseX > width - 15 && relativeMouseX < width && relativeMouseY > 10 && relativeMouseY < 26) {
|
||||
//this is not the most proper way to do it,
|
||||
//but works best here and has the least maintenance overhead
|
||||
gui.setToolTip(Arrays.stream(tooltip.split("\n")).map(TextComponent::new).collect(Collectors.toList()));
|
||||
gui.setToolTip(Arrays.stream(tooltip.split("\n")).map(Component::literal).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -952,7 +911,7 @@ public class ForgeHooksClient
|
||||
MinecraftForge.EVENT_BUS.post(new ClientPlayerNetworkEvent.LoggedInEvent(pc, player, networkManager));
|
||||
}
|
||||
|
||||
public static void firePlayerLogout(MultiPlayerGameMode pc, LocalPlayer player) {
|
||||
public static void firePlayerLogout(@Nullable MultiPlayerGameMode pc, @Nullable LocalPlayer player) {
|
||||
MinecraftForge.EVENT_BUS.post(new ClientPlayerNetworkEvent.LoggedOutEvent(pc, player, player != null ? player.connection != null ? player.connection.getConnection() : null : null));
|
||||
}
|
||||
|
||||
@@ -981,7 +940,7 @@ public class ForgeHooksClient
|
||||
}
|
||||
}
|
||||
|
||||
public static Font getTooltipFont(@Nullable Font forcedFont, @Nonnull ItemStack stack, Font fallbackFont)
|
||||
public static Font getTooltipFont(@Nullable Font forcedFont, @NotNull ItemStack stack, Font fallbackFont)
|
||||
{
|
||||
if (forcedFont != null)
|
||||
{
|
||||
@@ -991,14 +950,14 @@ public class ForgeHooksClient
|
||||
return stackFont == null ? fallbackFont : stackFont;
|
||||
}
|
||||
|
||||
public static RenderTooltipEvent.Pre onRenderTooltipPre(@Nonnull ItemStack stack, PoseStack poseStack, int x, int y, int screenWidth, int screenHeight, @Nonnull List<ClientTooltipComponent> components, @Nullable Font forcedFont, @Nonnull Font fallbackFont)
|
||||
public static RenderTooltipEvent.Pre onRenderTooltipPre(@NotNull ItemStack stack, PoseStack poseStack, int x, int y, int screenWidth, int screenHeight, @NotNull List<ClientTooltipComponent> components, @Nullable Font forcedFont, @NotNull Font fallbackFont)
|
||||
{
|
||||
var preEvent = new RenderTooltipEvent.Pre(stack, poseStack, x, y, screenWidth, screenHeight, getTooltipFont(forcedFont, stack, fallbackFont), components);
|
||||
MinecraftForge.EVENT_BUS.post(preEvent);
|
||||
return preEvent;
|
||||
}
|
||||
|
||||
public static RenderTooltipEvent.Color onRenderTooltipColor(@Nonnull ItemStack stack, PoseStack poseStack, int x, int y, @Nonnull Font font, @Nonnull List<ClientTooltipComponent> components)
|
||||
public static RenderTooltipEvent.Color onRenderTooltipColor(@NotNull ItemStack stack, PoseStack poseStack, int x, int y, @NotNull Font font, @NotNull List<ClientTooltipComponent> components)
|
||||
{
|
||||
var colorEvent = new RenderTooltipEvent.Color(stack, poseStack, x, y, font, 0xf0100010, 0x505000FF, 0x5028007f, components);
|
||||
MinecraftForge.EVENT_BUS.post(colorEvent);
|
||||
@@ -1101,47 +1060,48 @@ public class ForgeHooksClient
|
||||
}
|
||||
|
||||
public static void createWorldConfirmationScreen(
|
||||
LevelStorageSource save, String worldName, boolean creatingWorld,
|
||||
Function<LevelStorageSource.LevelStorageAccess, WorldStem.WorldDataSupplier> worldData,
|
||||
Function<Function<LevelStorageSource.LevelStorageAccess, WorldStem.WorldDataSupplier>, Runnable> runAfter)
|
||||
String worldName, LevelStorageSource.LevelStorageAccess levelStorageAccess,
|
||||
PackRepository packRepository, WorldStem worldStem)
|
||||
{
|
||||
Component title = new TranslatableComponent("selectWorld.backupQuestion.experimental");
|
||||
Component msg = new TranslatableComponent("selectWorld.backupWarning.experimental")
|
||||
Component title = Component.translatable("selectWorld.backupQuestion.experimental");
|
||||
Component msg = Component.translatable("selectWorld.backupWarning.experimental")
|
||||
.append("\n\n")
|
||||
.append(new TranslatableComponent("forge.selectWorld.backupWarning.experimental.additional"));
|
||||
.append(Component.translatable("forge.selectWorld.backupWarning.experimental.additional"));
|
||||
|
||||
Screen screen = new ConfirmScreen(confirmed ->
|
||||
{
|
||||
if (confirmed)
|
||||
{
|
||||
//The WorldData is re-created when re-running the runnable,
|
||||
// so make sure to be setting the field to true on the right instance.
|
||||
runAfter.apply(worldData.andThen(wds -> (rm, dpc) ->
|
||||
wds.get(rm, dpc).mapFirst(wd -> wd instanceof PrimaryLevelData pld ? pld.withConfirmedWarning(true) : wd))
|
||||
).run();
|
||||
if (worldStem.worldData() instanceof PrimaryLevelData pld)
|
||||
{
|
||||
pld.withConfirmedWarning(true);
|
||||
}
|
||||
Minecraft.getInstance().doWorldLoad(worldName, levelStorageAccess, packRepository, worldStem);
|
||||
}
|
||||
else
|
||||
{
|
||||
Minecraft.getInstance().setScreen(null);
|
||||
|
||||
if (creatingWorld) // delete save when cancelling creation.
|
||||
{
|
||||
try (LevelStorageSource.LevelStorageAccess levelSave = save.createAccess(worldName))
|
||||
{
|
||||
levelSave.deleteLevel();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
SystemToast.onWorldDeleteFailure(Minecraft.getInstance(), worldName);
|
||||
LOGGER.error("Failed to delete world {}", worldName, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, title, msg, CommonComponents.GUI_PROCEED, CommonComponents.GUI_CANCEL);
|
||||
|
||||
Minecraft.getInstance().setScreen(screen);
|
||||
}
|
||||
|
||||
public static boolean renderFireOverlay(Player player, PoseStack mat)
|
||||
{
|
||||
return renderBlockOverlay(player, mat, RenderBlockOverlayEvent.OverlayType.FIRE, Blocks.FIRE.defaultBlockState(), player.blockPosition());
|
||||
}
|
||||
|
||||
public static boolean renderWaterOverlay(Player player, PoseStack mat)
|
||||
{
|
||||
return renderBlockOverlay(player, mat, RenderBlockOverlayEvent.OverlayType.WATER, Blocks.WATER.defaultBlockState(), player.blockPosition());
|
||||
}
|
||||
|
||||
public static boolean renderBlockOverlay(Player player, PoseStack mat, RenderBlockOverlayEvent.OverlayType type, BlockState block, BlockPos pos)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new RenderBlockOverlayEvent(player, mat, type, block, pos));
|
||||
}
|
||||
|
||||
public static int getMaxMipmapLevel(int width, int height)
|
||||
{
|
||||
return Math.min(
|
||||
|
||||
@@ -6,30 +6,20 @@
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.RenderStateShard;
|
||||
import net.minecraft.client.renderer.RenderStateShard.TextureStateShard;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraftforge.client.event.RegisterShadersEvent;
|
||||
import net.minecraftforge.common.util.NonNullLazy;
|
||||
import net.minecraftforge.common.util.NonNullSupplier;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldPreset;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.WorldGenSettings;
|
||||
import net.minecraftforge.common.world.ForgeWorldPreset;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ForgeWorldPresetScreens
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final Map<ForgeWorldPreset, WorldPreset> GENERATORS = Maps.newHashMap();
|
||||
private static final Map<ForgeWorldPreset, WorldPreset.PresetEditor> GENERATOR_SCREEN_FACTORIES = Maps.newHashMap();
|
||||
|
||||
public static synchronized void registerPresetEditor(ForgeWorldPreset type, WorldPreset.PresetEditor factory)
|
||||
{
|
||||
if (GENERATOR_SCREEN_FACTORIES.containsKey(type))
|
||||
throw new IllegalStateException("Factory has already been registered for: " + type);
|
||||
|
||||
GENERATOR_SCREEN_FACTORIES.put(type, factory);
|
||||
}
|
||||
|
||||
static WorldPreset getDefaultPreset()
|
||||
{
|
||||
ForgeWorldPreset def = ForgeWorldPreset.getDefaultWorldPreset();
|
||||
if (def == null)
|
||||
{
|
||||
return WorldPreset.NORMAL;
|
||||
}
|
||||
|
||||
WorldPreset gen = GENERATORS.get(def);
|
||||
if (gen == null)
|
||||
{
|
||||
LOGGER.error("The default world type '{}' has not been added to the GUI. Was it registered too late?", def.getRegistryName());
|
||||
return WorldPreset.NORMAL;
|
||||
}
|
||||
|
||||
return gen;
|
||||
}
|
||||
|
||||
static WorldPreset.PresetEditor getPresetEditor(Optional<WorldPreset> generator, @Nullable WorldPreset.PresetEditor biomegeneratortypescreens$ifactory)
|
||||
{
|
||||
return generator.filter(gen -> gen instanceof GeneratorPreset)
|
||||
.map(type -> GENERATOR_SCREEN_FACTORIES.get(((GeneratorPreset)type).getWorldPreset()))
|
||||
.orElse(biomegeneratortypescreens$ifactory);
|
||||
}
|
||||
|
||||
static void registerPresets()
|
||||
{
|
||||
ForgeRegistries.WORLD_TYPES.get().forEach(wt -> {
|
||||
GeneratorPreset gen = new GeneratorPreset(wt);
|
||||
GENERATORS.put(wt, gen);
|
||||
WorldPreset.registerGenerator(gen);
|
||||
});
|
||||
}
|
||||
|
||||
private static class GeneratorPreset extends WorldPreset
|
||||
{
|
||||
private final ForgeWorldPreset worldPreset;
|
||||
|
||||
public GeneratorPreset(ForgeWorldPreset wt)
|
||||
{
|
||||
super(wt.getDisplayName());
|
||||
worldPreset = wt;
|
||||
}
|
||||
|
||||
public ForgeWorldPreset getWorldPreset()
|
||||
{
|
||||
return worldPreset;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public WorldGenSettings create(@Nonnull RegistryAccess dynamicRegistries, long seed, boolean generateStructures, boolean bonusChest)
|
||||
{
|
||||
return worldPreset.createSettings(dynamicRegistries, seed, generateStructures, bonusChest, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ChunkGenerator generator(RegistryAccess p_194083_, long p_194084_) {
|
||||
return worldPreset.createChunkGenerator(p_194083_, p_194084_, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,8 @@ import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IItemRenderProperties
|
||||
{
|
||||
@@ -43,7 +42,7 @@ public interface IItemRenderProperties
|
||||
* @param itemStack The itemStack to render the model of
|
||||
* @param armorSlot The slot the armor is in
|
||||
* @param _default Original armor model. Will have attributes set.
|
||||
* @return A HumanoidModel to render instead of the default, will have the relevant properties copied in {@link #getBaseArmorModel(LivingEntity, ItemStack, EquipmentSlot, HumanoidModel).
|
||||
* @return A HumanoidModel to render instead of the default, will have the relevant properties copied in {@link #getBaseArmorModel(LivingEntity, ItemStack, EquipmentSlot, HumanoidModel)}.
|
||||
* Returning null will cause the default to render.
|
||||
* @see #getBaseArmorModel(LivingEntity, ItemStack, EquipmentSlot, HumanoidModel)
|
||||
*/
|
||||
@@ -65,7 +64,7 @@ public interface IItemRenderProperties
|
||||
* @return A Model to render instead of the default
|
||||
* @see #getArmorModel(LivingEntity, ItemStack, EquipmentSlot, HumanoidModel)
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
default Model getBaseArmorModel(LivingEntity entityLiving, ItemStack itemStack, EquipmentSlot armorSlot, HumanoidModel<?> _default)
|
||||
{
|
||||
HumanoidModel<?> replacement = getArmorModel(entityLiving, itemStack, armorSlot, _default);
|
||||
|
||||
@@ -7,9 +7,6 @@ package net.minecraftforge.client;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.client.renderer.ItemModelShaper;
|
||||
@@ -17,17 +14,20 @@ import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.registries.IRegistryDelegate;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Wrapper around ItemModeMesher that cleans up the internal maps to respect ID remapping.
|
||||
*/
|
||||
public class ItemModelMesherForge extends ItemModelShaper
|
||||
{
|
||||
final Map<IRegistryDelegate<Item>, ModelResourceLocation> locations = Maps.newHashMap();
|
||||
final Map<IRegistryDelegate<Item>, BakedModel> models = Maps.newHashMap();
|
||||
final Map<Holder.Reference<Item>, ModelResourceLocation> locations = Maps.newHashMap();
|
||||
final Map<Holder.Reference<Item>, BakedModel> models = Maps.newHashMap();
|
||||
|
||||
public ItemModelMesherForge(ModelManager manager)
|
||||
{
|
||||
@@ -38,13 +38,13 @@ public class ItemModelMesherForge extends ItemModelShaper
|
||||
@Nullable
|
||||
public BakedModel getItemModel(Item item)
|
||||
{
|
||||
return models.get(item.delegate);
|
||||
return models.get(ForgeRegistries.ITEMS.getDelegateOrThrow(item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(Item item, ModelResourceLocation location)
|
||||
{
|
||||
IRegistryDelegate<Item> key = item.delegate;
|
||||
Holder.Reference<Item> key = ForgeRegistries.ITEMS.getDelegateOrThrow(item);
|
||||
locations.put(key, location);
|
||||
models.put(key, getModelManager().getModel(location));
|
||||
}
|
||||
@@ -53,15 +53,15 @@ public class ItemModelMesherForge extends ItemModelShaper
|
||||
public void rebuildCache()
|
||||
{
|
||||
final ModelManager manager = this.getModelManager();
|
||||
for (Map.Entry<IRegistryDelegate<Item>, ModelResourceLocation> e : locations.entrySet())
|
||||
for (Map.Entry<Holder.Reference<Item>, ModelResourceLocation> e : locations.entrySet())
|
||||
{
|
||||
models.put(e.getKey(), manager.getModel(e.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
public ModelResourceLocation getLocation(@Nonnull ItemStack stack)
|
||||
public ModelResourceLocation getLocation(@NotNull ItemStack stack)
|
||||
{
|
||||
ModelResourceLocation location = locations.get(stack.getItem().delegate);
|
||||
ModelResourceLocation location = locations.get(ForgeRegistries.ITEMS.getDelegateOrThrow(stack.getItem()));
|
||||
|
||||
if (location == null)
|
||||
{
|
||||
|
||||
@@ -10,33 +10,22 @@ import java.util.BitSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.chunk.RenderChunkRegion;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.client.textures.ITextureAtlasSpriteLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MinecraftForgeClient
|
||||
{
|
||||
@@ -107,15 +96,15 @@ public class MinecraftForgeClient
|
||||
bufferedImageSuppliers.put(resourceLocation, supplier);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public static NativeImage getImageLayer(ResourceLocation resourceLocation, ResourceManager resourceManager) throws IOException
|
||||
{
|
||||
Supplier<NativeImage> supplier = bufferedImageSuppliers.get(resourceLocation);
|
||||
if (supplier != null)
|
||||
return supplier.get();
|
||||
|
||||
Resource iresource1 = resourceManager.getResource(resourceLocation);
|
||||
return NativeImage.read(iresource1.getInputStream());
|
||||
Resource iresource1 = resourceManager.getResource(resourceLocation).orElseThrow();
|
||||
return NativeImage.read(iresource1.open());
|
||||
}
|
||||
|
||||
private static final Map<ResourceLocation, ITextureAtlasSpriteLoader> textureAtlasSpriteLoaders = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -11,8 +11,8 @@ import net.minecraft.client.RecipeBookCategories;
|
||||
import net.minecraft.world.inventory.RecipeBookType;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
|
||||
@@ -6,48 +6,58 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* ClientChatEvent is fired whenever the client is about to send a chat message or command to the server. <br>
|
||||
* This event is fired via {@link ForgeEventFactory#onClientSendMessage(String)},
|
||||
* which is executed by {@link Screen#sendMessage(String, boolean)}<br>
|
||||
* <br>
|
||||
* {@link #message} contains the message that will be sent to the server. This can be changed by mods.<br>
|
||||
* {@link #originalMessage} contains the original message that was going to be sent to the server. This cannot be changed by mods.<br>
|
||||
* <br>
|
||||
* This event is {@link Cancelable}. <br>
|
||||
* If this event is canceled, the chat message or command is never sent to the server.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
* Fired when the client is about to send a chat message to the server.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the chat message or command will not be sent to the server. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
**/
|
||||
@Cancelable
|
||||
public class ClientChatEvent extends Event
|
||||
{
|
||||
private String message;
|
||||
private final String originalMessage;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeEventFactory#onClientSendMessage(String)
|
||||
*/
|
||||
public ClientChatEvent(String message)
|
||||
{
|
||||
this.setMessage(message);
|
||||
this.originalMessage = Strings.nullToEmpty(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the message that will be sent to the server, if the event is not cancelled}
|
||||
*/
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new message to be sent to the server, if the event is not cancelled.
|
||||
*
|
||||
* @param message the new message to be sent
|
||||
*/
|
||||
public void setMessage(String message)
|
||||
{
|
||||
this.message = Strings.nullToEmpty(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original message that was to be sent to the server}
|
||||
*/
|
||||
public String getOriginalMessage()
|
||||
{
|
||||
return originalMessage;
|
||||
|
||||
@@ -5,56 +5,79 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.network.chat.ChatSender;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired on the client when a chat message is received.<br>
|
||||
* If this event is cancelled, the message is not displayed in the chat message window.<br>
|
||||
* Fired on {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.
|
||||
* Fired when a chat message is received on the client.
|
||||
* This can be used for filtering and detecting messages with specific words or phrases, and suppressing them.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, the message is not displayed in the chat message window. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ChatType
|
||||
*/
|
||||
@Cancelable
|
||||
public class ClientChatReceivedEvent extends Event
|
||||
{
|
||||
private Component message;
|
||||
private final ChatType type;
|
||||
@Nullable
|
||||
private final UUID senderUUID;
|
||||
private final ChatSender chatSender;
|
||||
|
||||
public ClientChatReceivedEvent(ChatType type, Component message, @Nullable UUID senderUUID)
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeEventFactory#onClientChat(ChatType, Component, ChatSender)
|
||||
*/
|
||||
public ClientChatReceivedEvent(ChatType type, Component message, ChatSender chatSender)
|
||||
{
|
||||
this.type = type;
|
||||
this.message = message;
|
||||
this.senderUUID = senderUUID;
|
||||
this.chatSender = chatSender;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the message that will be displayed in the chat message window, if the event is not cancelled}
|
||||
*/
|
||||
public Component getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new message to be displayed in the chat message window, if the event is not cancelled.
|
||||
*
|
||||
* @param message the new message to be sent
|
||||
*/
|
||||
public void setMessage(Component message)
|
||||
{
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the type of the chat message}
|
||||
*/
|
||||
public ChatType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* The UUID of the player or entity that sent this message, or null if not known.
|
||||
* This will be equal to {@link net.minecraft.Util#NIL_UUID} for system messages.
|
||||
* {@return the sender of this chat message} This contains the UUID, name, and (optionally) the team name of the
|
||||
* entity which sent the chat message. For system messages, {@link ChatSender#uuid()} will be equal to
|
||||
* {@link Util#NIL_UUID}.
|
||||
*/
|
||||
@Nullable
|
||||
public UUID getSenderUUID()
|
||||
public ChatSender getChatSender()
|
||||
{
|
||||
return senderUUID;
|
||||
return chatSender;
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,19 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired before the client player is notified of a change in game mode from the server.
|
||||
* Fired when the client player is notified of a change of {@link GameType} from the server.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public class ClientPlayerChangeGameTypeEvent extends Event
|
||||
{
|
||||
@@ -18,6 +27,10 @@ public class ClientPlayerChangeGameTypeEvent extends Event
|
||||
private final GameType currentGameType;
|
||||
private final GameType newGameType;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onClientChangeGameType(PlayerInfo, GameType, GameType)
|
||||
*/
|
||||
public ClientPlayerChangeGameTypeEvent(PlayerInfo info, GameType currentGameType, GameType newGameType)
|
||||
{
|
||||
this.info = info;
|
||||
@@ -25,16 +38,25 @@ public class ClientPlayerChangeGameTypeEvent extends Event
|
||||
this.newGameType = newGameType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the client player information}
|
||||
*/
|
||||
public PlayerInfo getInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the current game type of the player}
|
||||
*/
|
||||
public GameType getCurrentGameType()
|
||||
{
|
||||
return currentGameType;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the new game type of the player}
|
||||
*/
|
||||
public GameType getNewGameType()
|
||||
{
|
||||
return newGameType;
|
||||
|
||||
@@ -8,42 +8,53 @@ package net.minecraftforge.client.event;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Client side player connectivity events.
|
||||
*/
|
||||
* Fired for different client connectivity events.
|
||||
* See the various subclasses to listen for specific events.
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ClientPlayerNetworkEvent.LoggedInEvent
|
||||
* @see ClientPlayerNetworkEvent.LoggedOutEvent
|
||||
* @see ClientPlayerNetworkEvent.RespawnEvent
|
||||
**/
|
||||
public class ClientPlayerNetworkEvent extends Event {
|
||||
private final MultiPlayerGameMode multiPlayerGameMode;
|
||||
private final LocalPlayer player;
|
||||
private final Connection connection;
|
||||
|
||||
/**
|
||||
* @return the player controller for the client side
|
||||
* {@return the multiplayer game mode controller for the player}
|
||||
*/
|
||||
@Nullable
|
||||
public MultiPlayerGameMode getMultiPlayerGameMode() {
|
||||
return multiPlayerGameMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the player instance (if present - may be null)
|
||||
* {@return the player instance}
|
||||
*/
|
||||
@Nullable
|
||||
public LocalPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the impl connection (if present - may be null)
|
||||
* {@return the network connection for the player}
|
||||
*/
|
||||
@Nullable
|
||||
public Connection getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
ClientPlayerNetworkEvent(final MultiPlayerGameMode multiPlayerGameMode, final LocalPlayer player, final Connection connection) {
|
||||
this.multiPlayerGameMode = multiPlayerGameMode;
|
||||
this.player = player;
|
||||
@@ -52,41 +63,121 @@ public class ClientPlayerNetworkEvent extends Event {
|
||||
|
||||
/**
|
||||
* Fired when the client player logs in to the server. The player should be initialized.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class LoggedInEvent extends ClientPlayerNetworkEvent {
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#firePlayerLogin(MultiPlayerGameMode, LocalPlayer, Connection)
|
||||
*/
|
||||
public LoggedInEvent(final MultiPlayerGameMode controller, final LocalPlayer player, final Connection networkManager) {
|
||||
super(controller, player, networkManager);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the player logs out. Note this might also fire when a new integrated server is being created.
|
||||
* Fired when the client player logs out. This event may also fire when a new integrated server is being created.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems") // Shush IntelliJ, we override non-nullables as nullables in this specific event; see later comment
|
||||
public static class LoggedOutEvent extends ClientPlayerNetworkEvent {
|
||||
|
||||
public LoggedOutEvent(final MultiPlayerGameMode controller, final LocalPlayer player, final Connection networkManager) {
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#firePlayerLogout(MultiPlayerGameMode, LocalPlayer)
|
||||
*/
|
||||
public LoggedOutEvent(@Nullable final MultiPlayerGameMode controller, @Nullable final LocalPlayer player, @Nullable final Connection networkManager) {
|
||||
//noinspection ConstantConditions we know these are nullable, but we don't want to annotate the super as nullable since this is the only event with nullables
|
||||
super(controller, player, networkManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the multiplayer game mode controller for the player, may be {@code null}}. This may be {@code null}
|
||||
* in certain situations such as the creating a new integrated server (singleplayer world) or connecting to
|
||||
* a multiplayer server.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public MultiPlayerGameMode getMultiPlayerGameMode()
|
||||
{
|
||||
return super.getMultiPlayerGameMode();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the player instance, may be {@code null}}. This may be {@code null}
|
||||
* in certain situations such as the creating a new integrated server (singleplayer world) or connecting to
|
||||
* a multiplayer server.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public LocalPlayer getPlayer()
|
||||
{
|
||||
return super.getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the network connection for the player, may be {@code null}}. This may be {@code null}
|
||||
* in certain situations such as the creating a new integrated server (singleplayer world) or connecting to
|
||||
* a multiplayer server.
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public Connection getConnection()
|
||||
{
|
||||
return super.getConnection();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the player object respawns, such as dimension changes.
|
||||
* Fired when the client player respawns, creating a new player instance to replace the old player instance.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class RespawnEvent extends ClientPlayerNetworkEvent {
|
||||
private final LocalPlayer oldPlayer;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#firePlayerRespawn(MultiPlayerGameMode, LocalPlayer, LocalPlayer, Connection)
|
||||
*/
|
||||
public RespawnEvent(final MultiPlayerGameMode pc, final LocalPlayer oldPlayer, final LocalPlayer newPlayer, final Connection networkManager) {
|
||||
super(pc, newPlayer, networkManager);
|
||||
this.oldPlayer = oldPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the previous player instance}
|
||||
*/
|
||||
public LocalPlayer getOldPlayer() {
|
||||
return oldPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the newly created player instance}
|
||||
*/
|
||||
public LocalPlayer getNewPlayer() {
|
||||
return super.getPlayer();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the newly created player instance}
|
||||
* @see #getNewPlayer()
|
||||
*/
|
||||
@Override
|
||||
public LocalPlayer getPlayer() {
|
||||
return super.getPlayer();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,48 +5,107 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.client.color.block.BlockColor;
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.client.color.item.ItemColors;
|
||||
import net.minecraft.world.level.ItemLike;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
/**
|
||||
* Use these events to register block/item
|
||||
* color handlers at the appropriate time.
|
||||
* Fired for registering block and item color handlers at the appropriate time.
|
||||
* See the two subclasses for registering block or item color handlers.
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ColorHandlerEvent.Block
|
||||
* @see ColorHandlerEvent.Item
|
||||
*/
|
||||
public abstract class ColorHandlerEvent extends Event implements IModBusEvent
|
||||
{
|
||||
/**
|
||||
* @hidden This should only be invoked by subclasses.
|
||||
*/
|
||||
public ColorHandlerEvent()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired for registering block color handlers.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class Block extends ColorHandlerEvent
|
||||
{
|
||||
private final BlockColors blockColors;
|
||||
|
||||
/**
|
||||
* @hidden This should only be invoked by the client hook.
|
||||
* @see ForgeHooksClient#onBlockColorsInit(BlockColors)
|
||||
*/
|
||||
public Block(BlockColors blockColors)
|
||||
{
|
||||
this.blockColors = blockColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the block colors registry}
|
||||
* @see BlockColors#register(BlockColor, net.minecraft.world.level.block.Block...)
|
||||
*/
|
||||
public BlockColors getBlockColors()
|
||||
{
|
||||
return blockColors;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired for registering item color handlers.
|
||||
*
|
||||
* <p>The block colors should only be used for referencing or delegating item colors to their respective block
|
||||
* colors. Use {@link ColorHandlerEvent.Block} for registering your block color handlers. </p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class Item extends ColorHandlerEvent
|
||||
{
|
||||
private final ItemColors itemColors;
|
||||
private final BlockColors blockColors;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onItemColorsInit(ItemColors, BlockColors)
|
||||
*/
|
||||
public Item(ItemColors itemColors, BlockColors blockColors)
|
||||
{
|
||||
this.itemColors = itemColors;
|
||||
this.blockColors = blockColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the item colors registry}
|
||||
* @see ItemColors#register(ItemColor, ItemLike...)
|
||||
*/
|
||||
public ItemColors getItemColors()
|
||||
{
|
||||
return itemColors;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the block colors registry}
|
||||
* This should only be used for referencing or delegating item colors to their respective block colors.
|
||||
*/
|
||||
public BlockColors getBlockColors()
|
||||
{
|
||||
return blockColors;
|
||||
|
||||
@@ -7,31 +7,53 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Event class for handling GuiContainer specific events.
|
||||
* Fired for hooking into {@link AbstractContainerScreen} rendering.
|
||||
* See the two subclasses to listen for foreground or background rendering.
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ContainerScreenEvent.DrawForeground
|
||||
* @see ContainerScreenEvent.DrawBackground
|
||||
*/
|
||||
public class ContainerScreenEvent extends Event
|
||||
{
|
||||
|
||||
private final AbstractContainerScreen<?> containerScreen;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public ContainerScreenEvent(AbstractContainerScreen<?> containerScreen)
|
||||
{
|
||||
this.containerScreen = containerScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the container screen}
|
||||
*/
|
||||
public AbstractContainerScreen<?> getContainerScreen()
|
||||
{
|
||||
return containerScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired directly after the GuiContainer has draw any foreground elements,
|
||||
* But before the "dragged" stack, and before any tooltips.
|
||||
* This is useful for any slot / item specific overlays.
|
||||
* Things that need to be on top of All GUI elements but bellow tooltips and dragged stacks.
|
||||
* Fired after the container screen's foreground layer and elements are drawn, but
|
||||
* before rendering the tooltips and the item stack being dragged by the player.
|
||||
*
|
||||
* <p>This can be used for rendering elements that must be above other screen elements, but
|
||||
* below tooltips and the dragged stack, such as slot or item stack specific overlays. </p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class DrawForeground extends ContainerScreenEvent
|
||||
{
|
||||
@@ -40,12 +62,7 @@ public class ContainerScreenEvent extends Event
|
||||
private final int mouseY;
|
||||
|
||||
/**
|
||||
* Called directly after the GuiContainer has drawn any foreground elements.
|
||||
*
|
||||
* @param guiContainer The container.
|
||||
* @param poseStack The pose stack.
|
||||
* @param mouseX The current X position of the players mouse.
|
||||
* @param mouseY The current Y position of the players mouse.
|
||||
* @hidden
|
||||
*/
|
||||
public DrawForeground(AbstractContainerScreen<?> guiContainer, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
@@ -55,25 +72,39 @@ public class ContainerScreenEvent extends Event
|
||||
this.mouseY = mouseY;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseX()
|
||||
{
|
||||
return mouseX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseY()
|
||||
{
|
||||
return mouseY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This event is fired directly after the GuiContainer has draw any background elements,
|
||||
* This is useful for drawing new background elements.
|
||||
* Fired after the container screen's background layer and elements are drawn.
|
||||
* This can be used for rendering new background elements.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class DrawBackground extends ContainerScreenEvent
|
||||
{
|
||||
@@ -82,12 +113,7 @@ public class ContainerScreenEvent extends Event
|
||||
private final int mouseY;
|
||||
|
||||
/**
|
||||
* Called directly after the GuiContainer has drawn any background elements.
|
||||
*
|
||||
* @param guiContainer The container.
|
||||
* @param poseStack The PoseStack.
|
||||
* @param mouseX The current X position of the players mouse.
|
||||
* @param mouseY The current Y position of the players mouse.
|
||||
* @hidden
|
||||
*/
|
||||
public DrawBackground(AbstractContainerScreen<?> guiContainer, PoseStack poseStack, int mouseX, int mouseY)
|
||||
{
|
||||
@@ -97,16 +123,25 @@ public class ContainerScreenEvent extends Event
|
||||
this.mouseY = mouseY;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseX()
|
||||
{
|
||||
return mouseX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseY()
|
||||
{
|
||||
return mouseY;
|
||||
|
||||
@@ -9,15 +9,20 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* An event called whenever the selection highlight around a block or entity is about to be rendered.
|
||||
* Canceling this event stops the selection highlight from being rendered.
|
||||
* Fired before a selection highlight is rendered.
|
||||
* See the two subclasses to listen for blocks or entities.
|
||||
*
|
||||
* @see DrawSelectionEvent.HighlightBlock
|
||||
* @see DrawSelectionEvent.HighlightEntity
|
||||
*/
|
||||
@Cancelable
|
||||
public class DrawSelectionEvent extends Event
|
||||
@@ -25,38 +30,72 @@ public class DrawSelectionEvent extends Event
|
||||
private final LevelRenderer levelRenderer;
|
||||
private final Camera camera;
|
||||
private final HitResult target;
|
||||
private final float partialTicks;
|
||||
private final float partialTick;
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
|
||||
public DrawSelectionEvent(LevelRenderer levelRenderer, Camera camera, HitResult target, float partialTicks, PoseStack poseStack, MultiBufferSource multiBufferSource)
|
||||
/**
|
||||
* @hidden
|
||||
* @see net.minecraftforge.client.ForgeHooksClient#onDrawHighlight(LevelRenderer, Camera, HitResult, float, PoseStack, MultiBufferSource)
|
||||
*/
|
||||
public DrawSelectionEvent(LevelRenderer levelRenderer, Camera camera, HitResult target, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource)
|
||||
{
|
||||
this.levelRenderer = levelRenderer;
|
||||
this.camera = camera;
|
||||
this.target = target;
|
||||
this.partialTicks = partialTicks;
|
||||
this.partialTick = partialTick;
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level renderer}
|
||||
*/
|
||||
public LevelRenderer getLevelRenderer() { return levelRenderer; }
|
||||
/**
|
||||
* {@return the camera information}
|
||||
*/
|
||||
public Camera getCamera() { return camera; }
|
||||
/**
|
||||
* {@return the hit result which triggered the selection highlight}
|
||||
*/
|
||||
public HitResult getTarget() { return target; }
|
||||
public float getPartialTicks() { return partialTicks; }
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick() { return partialTick; }
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() { return poseStack; }
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() { return multiBufferSource; }
|
||||
|
||||
/**
|
||||
* A variant of the DrawSelectionEvent only called when a block is highlighted.
|
||||
* Fired before a block's selection highlight is rendered.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, then the selection highlight will not be rendered. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class HighlightBlock extends DrawSelectionEvent
|
||||
{
|
||||
public HighlightBlock(LevelRenderer levelRenderer, Camera camera, HitResult target, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public HighlightBlock(LevelRenderer levelRenderer, Camera camera, BlockHitResult target, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource)
|
||||
{
|
||||
super(levelRenderer, camera, target, partialTick, poseStack, bufferSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the block hit result}
|
||||
*/
|
||||
@Override
|
||||
public BlockHitResult getTarget()
|
||||
{
|
||||
@@ -65,17 +104,26 @@ public class DrawSelectionEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* A variant of the DrawSelectionEvent only called when an entity is highlighted.
|
||||
* Canceling this event has no effect.
|
||||
* Fired before a block's selection highlight is rendered.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class HighlightEntity extends DrawSelectionEvent
|
||||
{
|
||||
public HighlightEntity(LevelRenderer levelRenderer, Camera camera, HitResult target, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public HighlightEntity(LevelRenderer levelRenderer, Camera camera, EntityHitResult target, float partialTick, PoseStack poseStack, MultiBufferSource bufferSource)
|
||||
{
|
||||
super(levelRenderer, camera, target, partialTick, poseStack, bufferSource);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the entity hit result}
|
||||
*/
|
||||
@Override
|
||||
public EntityHitResult getTarget()
|
||||
{
|
||||
|
||||
@@ -8,9 +8,11 @@ package net.minecraftforge.client.event;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.EntityModel;
|
||||
import net.minecraft.client.model.SkullModel;
|
||||
import net.minecraft.client.model.SkullModelBase;
|
||||
import net.minecraft.client.model.geom.EntityModelSet;
|
||||
import net.minecraft.client.model.geom.ModelLayerLocation;
|
||||
import net.minecraft.client.model.geom.ModelLayers;
|
||||
import net.minecraft.client.model.geom.builders.LayerDefinition;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
@@ -18,6 +20,7 @@ import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@@ -27,24 +30,62 @@ import net.minecraft.world.level.block.SkullBlock.Type;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Fired for on different events/actions relating to {@linkplain EntityRenderer entity renderers}.
|
||||
* See the various subclasses for listening to different events.
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see EntityRenderersEvent.RegisterLayerDefinitions
|
||||
* @see EntityRenderersEvent.RegisterRenderers
|
||||
* @see EntityRenderersEvent.AddLayers
|
||||
*/
|
||||
public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public EntityRenderersEvent()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired for registering layer definitions at the appropriate time.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class RegisterLayerDefinitions extends EntityRenderersEvent
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RegisterLayerDefinitions()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a layer definition supplier with the given {@link ModelLayerLocation}.
|
||||
* These will be inserted into the main layer definition map for entity model layers at the appropriate time.
|
||||
*
|
||||
* @param layerLocation The model layer location, which should be used in conjunction with {@link EntityRendererProvider.Context#bakeLayer(ModelLayerLocation)}
|
||||
* @param supplier A supplier to create a {@link LayerDefinition}, generally a static method reference in the entity model class
|
||||
* @param layerLocation the model layer location, which should be used in conjunction with
|
||||
* {@link EntityRendererProvider.Context#bakeLayer(ModelLayerLocation)}
|
||||
* @param supplier a supplier to create a {@link LayerDefinition}, generally a static method reference in
|
||||
* the entity model class
|
||||
*/
|
||||
public void registerLayerDefinition(ModelLayerLocation layerLocation, Supplier<LayerDefinition> supplier)
|
||||
{
|
||||
@@ -53,15 +94,29 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a safe place to register entity renderers and layer renderers.
|
||||
* Fired for registering entity and block entity renderers at the appropriate time.
|
||||
* For registering entity renderer layers to existing entity renderers (whether vanilla or registered through this
|
||||
* event), listen for the {@link AddLayers} event instead.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class RegisterRenderers extends EntityRenderersEvent
|
||||
{
|
||||
/**
|
||||
* Registers an entity renderer.
|
||||
* @hidden
|
||||
*/
|
||||
public RegisterRenderers()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an entity renderer for the given entity type.
|
||||
*
|
||||
* @param entityType The EntityType to register a renderer for
|
||||
* @param entityRendererProvider The renderer provider, can be a lambda like MyRenderer::new
|
||||
* @param entityType the entity type to register a renderer for
|
||||
* @param entityRendererProvider the renderer provider
|
||||
*/
|
||||
public <T extends Entity> void registerEntityRenderer(EntityType<? extends T> entityType, EntityRendererProvider<T> entityRendererProvider)
|
||||
{
|
||||
@@ -69,10 +124,10 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a block entity renderer.
|
||||
* Registers a block entity renderer for the given block entity type.
|
||||
*
|
||||
* @param blockEntityType The BlockEntityType to register a renderer for
|
||||
* @param blockEntityRendererProvider The renderer provider, can be a lambda like MyRenderer::new
|
||||
* @param blockEntityType the block entity type to register a renderer for
|
||||
* @param blockEntityRendererProvider the renderer provider
|
||||
*/
|
||||
public <T extends BlockEntity> void registerBlockEntityRenderer(BlockEntityType<? extends T> blockEntityType, BlockEntityRendererProvider<T> blockEntityRendererProvider)
|
||||
{
|
||||
@@ -81,7 +136,13 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a safe place to register entity renderer layers.
|
||||
* Fired for registering entity renderer layers at the appropriate time, after the entity and player renderers maps
|
||||
* have been created.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class AddLayers extends EntityRenderersEvent
|
||||
{
|
||||
@@ -89,6 +150,9 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
private final Map<String, EntityRenderer<? extends Player>> skinMap;
|
||||
private final EntityModelSet entityModels = Minecraft.getInstance().getEntityModels();
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public AddLayers(Map<EntityType<?>, EntityRenderer<?>> renderers, Map<String, EntityRenderer<? extends Player>> playerRenderers)
|
||||
{
|
||||
this.renderers = renderers;
|
||||
@@ -96,7 +160,11 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of skins.
|
||||
* {@return the set of player skin names which have a renderer}
|
||||
*
|
||||
* Minecraft provides two default skin names: {@code default} for the
|
||||
* {@linkplain ModelLayers#PLAYER regular player model} and {@code slim} for the
|
||||
* {@linkplain ModelLayers#PLAYER_SLIM slim player model}.
|
||||
*/
|
||||
public Set<String> getSkins()
|
||||
{
|
||||
@@ -104,10 +172,12 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a player skin renderer. Vanilla skins are "default" and "slim".
|
||||
* @param skinName The name of the skin renderer to return
|
||||
* @param <R> The type of the skin renderer, usually PlayerRenderer
|
||||
* @return The skin renderer, or null if not found
|
||||
* Returns a player skin renderer for the given skin name.
|
||||
*
|
||||
* @param skinName the name of the skin to get the renderer for
|
||||
* @param <R> the type of the skin renderer, usually {@link PlayerRenderer}
|
||||
* @return the skin renderer, or {@code null} if no renderer is registered for that skin name
|
||||
* @see #getSkins()
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -118,10 +188,11 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
|
||||
/**
|
||||
* Returns an entity renderer for the given entity type.
|
||||
* @param entityType The entity to return a renderer for
|
||||
* @param <T> The type of entity the renderer is for
|
||||
* @param <R> The renderer type
|
||||
* @return The renderer
|
||||
*
|
||||
* @param entityType the entity type to return a renderer for
|
||||
* @param <T> the type of entity the renderer is for
|
||||
* @param <R> the type of the renderer
|
||||
* @return the renderer, or {@code null} if no renderer is registered for that entity type
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -129,6 +200,9 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
return (R) renderers.get(entityType);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the set of entity models}
|
||||
*/
|
||||
public EntityModelSet getEntityModels()
|
||||
{
|
||||
return entityModels;
|
||||
@@ -136,19 +210,27 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a safe place to register models for the skull block
|
||||
* Fired for registering additional {@linkplain net.minecraft.client.model.SkullModelBase skull models} at the appropriate time.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class CreateSkullModels extends EntityRenderersEvent
|
||||
{
|
||||
private final ImmutableMap.Builder<Type,SkullModelBase> builder;
|
||||
private final ImmutableMap.Builder<Type, SkullModelBase> builder;
|
||||
private final EntityModelSet entityModelSet;
|
||||
|
||||
public CreateSkullModels(ImmutableMap.Builder<Type,SkullModelBase> builder, EntityModelSet entityModelSet)
|
||||
public CreateSkullModels(ImmutableMap.Builder<Type, SkullModelBase> builder, EntityModelSet entityModelSet)
|
||||
{
|
||||
this.builder = builder;
|
||||
this.entityModelSet = entityModelSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the set of entity models}
|
||||
*/
|
||||
public EntityModelSet getEntityModelSet()
|
||||
{
|
||||
return entityModelSet;
|
||||
@@ -156,10 +238,14 @@ public class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
|
||||
/**
|
||||
* Registers the constructor for a skull block with the given {@link SkullBlock.Type}.
|
||||
* These will be inserted into the maps used by the item, entity, and block model renderers at the appropiate time.
|
||||
* These will be inserted into the maps used by the item, entity, and block model renderers at the appropriate
|
||||
* time.
|
||||
*
|
||||
* @param type Unique skull type. Will cause an exception if multiple mods (including vanilla) register models for the same type
|
||||
* @param model Model instance. A typical implementation will simply do {@code new SkullModel(entityModelSet.bakeLayer(layerLocation))}
|
||||
* @param type a unique skull type; an exception will be thrown later if multiple mods (including vanilla)
|
||||
* register models for the same type
|
||||
* @param model the skull model instance. A typical implementation will simply bake a model using
|
||||
* {@link EntityModelSet#bakeLayer(ModelLayerLocation)} and pass it to the constructor for
|
||||
* {@link SkullModel}.
|
||||
*/
|
||||
public void registerSkullModel(SkullBlock.Type type, SkullModelBase model)
|
||||
{
|
||||
|
||||
@@ -7,162 +7,180 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.renderer.FogRenderer.FogMode;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.world.level.material.FogType;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.renderer.FogRenderer;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
import com.mojang.blaze3d.shaders.FogShape;
|
||||
|
||||
/**
|
||||
* Event that hooks into GameRenderer, allowing any feature to customize visual attributes
|
||||
* the player sees.
|
||||
* Fired for hooking into the entity view rendering in {@link GameRenderer}.
|
||||
* These can be used for customizing the visual features visible to the player.
|
||||
* See the various subclasses for listening to different features.
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see EntityViewRenderEvent.RenderFogEvent
|
||||
* @see EntityViewRenderEvent.FogColors
|
||||
* @see EntityViewRenderEvent.CameraSetup
|
||||
* @see EntityViewRenderEvent.FieldOfView
|
||||
*/
|
||||
public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
private final GameRenderer renderer;
|
||||
private final Camera camera;
|
||||
private final double partialTicks;
|
||||
private final double partialTick;
|
||||
|
||||
public EntityViewRenderEvent(GameRenderer renderer, Camera camera, double partialTicks)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public EntityViewRenderEvent(GameRenderer renderer, Camera camera, double partialTick)
|
||||
{
|
||||
this.renderer = renderer;
|
||||
this.camera = camera;
|
||||
this.partialTicks = partialTicks;
|
||||
this.partialTick = partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the game renderer}
|
||||
*/
|
||||
public GameRenderer getRenderer()
|
||||
{
|
||||
return renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the camera information}
|
||||
*/
|
||||
public Camera getCamera()
|
||||
{
|
||||
return camera;
|
||||
}
|
||||
|
||||
public double getPartialTicks()
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public double getPartialTick()
|
||||
{
|
||||
return partialTicks;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
private static class FogEvent extends EntityViewRenderEvent
|
||||
{
|
||||
private final FogMode mode;
|
||||
@SuppressWarnings("resource")
|
||||
protected FogEvent(FogMode mode, Camera camera, double partialTick)
|
||||
{
|
||||
super(Minecraft.getInstance().gameRenderer, camera, partialTick);
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public FogMode getMode() { return mode; }
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use RenderFogEvent. This event will be removed as the other event has better functionality.
|
||||
* Fired for customizing the <b>rendering</b> of the fog visible to the player. The plane distances are based on
|
||||
* the player's render distance.
|
||||
*
|
||||
* Event that allows any feature to customize the fog density the player sees.
|
||||
* NOTE: In order to make this event have an effect, you must cancel the event
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and {@linkplain HasResult has a result}. <br/>
|
||||
* The event must be cancelled for any changes to the plane distances to take effect.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public static class FogDensity extends FogEvent
|
||||
public static class RenderFogEvent extends EntityViewRenderEvent
|
||||
{
|
||||
private float density;
|
||||
|
||||
public FogDensity(FogMode type, Camera camera, float partialTick, float density)
|
||||
{
|
||||
super(type, camera, partialTick);
|
||||
this.setDensity(density);
|
||||
}
|
||||
|
||||
public float getDensity()
|
||||
{
|
||||
return density;
|
||||
}
|
||||
|
||||
public void setDensity(float density)
|
||||
{
|
||||
this.density = density;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This event allows for customization of parameters related to fog rendering. The plane distances are based on the player's render distance.
|
||||
* For the event to have an effect, you must cancel it.
|
||||
*
|
||||
* The FogMode is NOT customizable. It describes the type of fog being modified.
|
||||
* A FogMode of FOG_SKY is the skybox's fog.
|
||||
* A FogMode of FOG_TERRAIN is what the fog induced by render distance uses. This works best for reducing the camera's visibility.
|
||||
*/
|
||||
@HasResult // TODO: remove in 1.19. Setting a result for this event has no effect.
|
||||
@Cancelable
|
||||
public static class RenderFogEvent extends FogEvent // TODO: In 1.19, change superclass to EntityViewRenderEvent
|
||||
{
|
||||
private final FogMode type;
|
||||
private final FogType type;
|
||||
private float farPlaneDistance;
|
||||
private float nearPlaneDistance;
|
||||
private FogShape fogShape;
|
||||
|
||||
/**
|
||||
* @deprecated Use other constructor with all the params. Will be removed in 1.19
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onFogRender(FogType, Camera, float, float, float, FogShape)
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18.2")
|
||||
public RenderFogEvent(FogMode type, Camera camera, float partialTicks, float distance)
|
||||
public RenderFogEvent(FogType type, Camera camera, float partialTicks, float nearPlaneDistance, float farPlaneDistance, FogShape fogShape)
|
||||
{
|
||||
this(type, camera, partialTicks, -8f, distance, FogShape.SPHERE);
|
||||
}
|
||||
|
||||
public RenderFogEvent(FogMode type, Camera camera, float partialTicks, float nearPlaneDistance, float farPlaneDistance, FogShape fogShape)
|
||||
{
|
||||
super(type, camera, partialTicks);
|
||||
super(Minecraft.getInstance().gameRenderer, camera, partialTicks);
|
||||
this.type = type;
|
||||
setFarPlaneDistance(farPlaneDistance);
|
||||
setNearPlaneDistance(nearPlaneDistance);
|
||||
setFogShape(fogShape);
|
||||
}
|
||||
|
||||
public FogMode getMode()
|
||||
/**
|
||||
* {@return the type of fog being rendered}
|
||||
*/
|
||||
public FogType getMode()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the distance to the far plane where the fog ends}
|
||||
*/
|
||||
public float getFarPlaneDistance()
|
||||
{
|
||||
return farPlaneDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the distance to the near plane where the fog starts}
|
||||
*/
|
||||
public float getNearPlaneDistance()
|
||||
{
|
||||
return nearPlaneDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the shape of the fog being rendered}
|
||||
*/
|
||||
public FogShape getFogShape()
|
||||
{
|
||||
return fogShape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the distance to the far plane of the fog.
|
||||
*
|
||||
* @param distance the new distance to the far place
|
||||
* @see #scaleFarPlaneDistance(float)
|
||||
*/
|
||||
public void setFarPlaneDistance(float distance)
|
||||
{
|
||||
farPlaneDistance = distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the distance to the near plane of the fog.
|
||||
*
|
||||
* @param distance the new distance to the near plane
|
||||
* @see #scaleNearPlaneDistance(float)
|
||||
*/
|
||||
public void setNearPlaneDistance(float distance)
|
||||
{
|
||||
nearPlaneDistance = distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new shape of the fog being rendered. The new shape will only take effect if the event is cancelled.
|
||||
*
|
||||
* @param shape the new shape of the fog
|
||||
*/
|
||||
public void setFogShape(FogShape shape)
|
||||
{
|
||||
fogShape = shape;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the distance to the far plane of the fog by a given factor.
|
||||
*
|
||||
* @param factor the factor to scale the far plane distance by
|
||||
*/
|
||||
public void scaleFarPlaneDistance(float factor)
|
||||
{
|
||||
farPlaneDistance *= factor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scales the distance to the near plane of the fog by a given factor.
|
||||
*
|
||||
* @param factor the factor to scale the near plane distance by
|
||||
*/
|
||||
public void scaleNearPlaneDistance(float factor)
|
||||
{
|
||||
nearPlaneDistance *= factor;
|
||||
@@ -170,8 +188,12 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
}
|
||||
|
||||
/**
|
||||
* Event that allows any feature to customize the color of fog the player sees.
|
||||
* NOTE: Any change made to one of the color variables will affect the result seen in-game.
|
||||
* Fired for customizing the <b>color</b> of the fog visible to the player.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class FogColors extends EntityViewRenderEvent
|
||||
{
|
||||
@@ -179,7 +201,10 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
private float green;
|
||||
private float blue;
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
/**
|
||||
* @hidden
|
||||
* @see FogRenderer#setupColor(Camera, float, ClientLevel, int, float)
|
||||
*/
|
||||
public FogColors(Camera camera, float partialTicks, float red, float green, float blue)
|
||||
{
|
||||
super(Minecraft.getInstance().gameRenderer, camera, partialTicks);
|
||||
@@ -188,16 +213,46 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
this.setBlue(blue);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the red color value of the fog}
|
||||
*/
|
||||
public float getRed() { return red; }
|
||||
/**
|
||||
* Sets the new red color value of the fog.
|
||||
*
|
||||
* @param red the new red color value
|
||||
*/
|
||||
public void setRed(float red) { this.red = red; }
|
||||
/**
|
||||
* {@return the green color value of the fog}
|
||||
*/
|
||||
public float getGreen() { return green; }
|
||||
/**
|
||||
* Sets the new green color value of the fog.
|
||||
*
|
||||
* @param green the new blue color value
|
||||
*/
|
||||
public void setGreen(float green) { this.green = green; }
|
||||
/**
|
||||
* {@return the blue color value of the fog}
|
||||
*/
|
||||
public float getBlue() { return blue; }
|
||||
/**
|
||||
* Sets the new blue color value of the fog.
|
||||
*
|
||||
* @param blue the new blue color value
|
||||
*/
|
||||
public void setBlue(float blue) { this.blue = blue; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Event that allows mods to alter the angles of the player's camera. Mainly useful for applying roll.
|
||||
* Fired to allow altering the angles of the player's camera.
|
||||
* This can be used to alter the player's view for different effects, such as applying roll.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class CameraSetup extends EntityViewRenderEvent
|
||||
{
|
||||
@@ -205,6 +260,10 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
private float pitch;
|
||||
private float roll;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onCameraSetup(GameRenderer, Camera, float)
|
||||
*/
|
||||
public CameraSetup(GameRenderer renderer, Camera camera, double renderPartialTicks, float yaw, float pitch, float roll)
|
||||
{
|
||||
super(renderer, camera, renderPartialTicks);
|
||||
@@ -213,31 +272,74 @@ public abstract class EntityViewRenderEvent extends net.minecraftforge.eventbus.
|
||||
this.setRoll(roll);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the yaw of the player's camera}
|
||||
*/
|
||||
public float getYaw() { return yaw; }
|
||||
/**
|
||||
* Sets the yaw of the player's camera.
|
||||
*
|
||||
* @param yaw the new yaw
|
||||
*/
|
||||
public void setYaw(float yaw) { this.yaw = yaw; }
|
||||
/**
|
||||
* {@return the pitch of the player's camera}
|
||||
*/
|
||||
public float getPitch() { return pitch; }
|
||||
/**
|
||||
* Sets the pitch of the player's camera.
|
||||
*
|
||||
* @param pitch the new pitch
|
||||
*/
|
||||
public void setPitch(float pitch) { this.pitch = pitch; }
|
||||
/**
|
||||
* {@return the roll of the player's camera}
|
||||
*/
|
||||
public float getRoll() { return roll; }
|
||||
/**
|
||||
* Sets the roll of the player's camera.
|
||||
*
|
||||
* @param roll the new roll
|
||||
*/
|
||||
public void setRoll(float roll) { this.roll = roll; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Event that allows mods to alter the raw FOV itself.
|
||||
* This directly affects to the FOV without being modified.
|
||||
* */
|
||||
* Fired for altering the raw field of view (FOV).
|
||||
* This is after the FOV settings are applied, and before modifiers such as the Nausea effect.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see FOVModifierEvent
|
||||
*/
|
||||
public static class FieldOfView extends EntityViewRenderEvent
|
||||
{
|
||||
private double fov;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#getFieldOfView(GameRenderer, Camera, double, double)
|
||||
*/
|
||||
public FieldOfView(GameRenderer renderer, Camera camera, double renderPartialTicks, double fov) {
|
||||
super(renderer, camera, renderPartialTicks);
|
||||
this.setFOV(fov);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the raw field of view value}
|
||||
*/
|
||||
public double getFOV() {
|
||||
return fov;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the field of view value.
|
||||
*
|
||||
* @param fov the new FOV value
|
||||
*/
|
||||
public void setFOV(double fov) {
|
||||
this.fov = fov;
|
||||
}
|
||||
|
||||
@@ -8,38 +8,71 @@ package net.minecraftforge.client.event;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired after the field of vision (FOV) modifier for the player is calculated.
|
||||
* This can be used to modify the FOV before the FOV settings are applied.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see EntityViewRenderEvent.FieldOfView
|
||||
*/
|
||||
public class FOVModifierEvent extends Event
|
||||
{
|
||||
private final Player entity;
|
||||
private final Player player;
|
||||
private final float fov;
|
||||
private float newfov;
|
||||
private float newFov;
|
||||
|
||||
public FOVModifierEvent(Player entity, float fov)
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#getFieldOfView(Player, float)
|
||||
*/
|
||||
public FOVModifierEvent(Player player, float fov)
|
||||
{
|
||||
this.entity = entity;
|
||||
this.player = player;
|
||||
this.fov = fov;
|
||||
this.setNewfov(Mth.lerp(Minecraft.getInstance().options.fovEffectScale, 1.0F, fov));
|
||||
this.setNewFov((float) Mth.lerp(Minecraft.getInstance().options.fovEffectScale().get(), 1.0F, fov));
|
||||
}
|
||||
|
||||
public Player getEntity()
|
||||
/**
|
||||
* {@return the player affected by this event}
|
||||
*/
|
||||
public Player getPlayer()
|
||||
{
|
||||
return entity;
|
||||
return player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original field of vision (FOV) of the player, before any modifications or interpolation}
|
||||
*/
|
||||
public float getFov()
|
||||
{
|
||||
return fov;
|
||||
}
|
||||
|
||||
public float getNewfov()
|
||||
/**
|
||||
* {@return the current field of vision (FOV) of the player}
|
||||
*/
|
||||
public float getNewFov()
|
||||
{
|
||||
return newfov;
|
||||
return newFov;
|
||||
}
|
||||
|
||||
public void setNewfov(float newfov)
|
||||
/**
|
||||
* Sets the new field of vision (FOV) of the player.
|
||||
*
|
||||
* @param newFov the new field of vision (FOV)
|
||||
*/
|
||||
public void setNewFov(float newFov)
|
||||
{
|
||||
this.newfov = newfov;
|
||||
this.newFov = newFov;
|
||||
}
|
||||
}
|
||||
@@ -7,15 +7,37 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.MouseHandler;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
/**
|
||||
* Fired when an input is detected from the user's input devices.
|
||||
* See the various subclasses to listen for specific devices and inputs.
|
||||
*
|
||||
* @see InputEvent.RawMouseEvent
|
||||
* @see InputEvent.MouseInputEvent
|
||||
* @see InputEvent.MouseScrollEvent
|
||||
* @see InputEvent.KeyInputEvent
|
||||
* @see InputEvent.ClickInputEvent
|
||||
*/
|
||||
public class InputEvent extends Event
|
||||
{
|
||||
/**
|
||||
* A cancellable mouse event fired before key bindings are updated
|
||||
* Fired when a mouse button is clicked, <b>before</b> being processed by vanilla.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, then the mouse event will not be processed by vanilla (e.g. keymappings and screens) </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_mouse_button" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class RawMouseEvent extends InputEvent
|
||||
@@ -24,6 +46,10 @@ public class InputEvent extends Event
|
||||
private final int action;
|
||||
private final int modifiers;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onRawMouseClicked(int, int, int)
|
||||
*/
|
||||
public RawMouseEvent(int button, int action, int modifiers)
|
||||
{
|
||||
this.button = button;
|
||||
@@ -32,10 +58,11 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* The mouse button that triggered this event.
|
||||
* https://www.glfw.org/docs/latest/group__buttons.html
|
||||
* {@return the mouse button's input code}
|
||||
*
|
||||
* @see GLFW mouse constants starting with "GLFW_MOUSE_BUTTON_"
|
||||
* @see InputConstants input constants starting with {@code MOUSE_BUTTON_}
|
||||
* @see GLFW mouse constants starting with {@code GLFW_MOUSE_BUTTON_}
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__buttons.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getButton()
|
||||
{
|
||||
@@ -43,10 +70,10 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Integer representing the mouse button's action.
|
||||
* {@return the mouse button's action}
|
||||
*
|
||||
* @see GLFW#GLFW_PRESS
|
||||
* @see GLFW#GLFW_RELEASE
|
||||
* @see InputConstants#PRESS
|
||||
* @see InputConstants#RELEASE
|
||||
*/
|
||||
public int getAction()
|
||||
{
|
||||
@@ -54,13 +81,15 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Bit field representing the modifier keys pressed.
|
||||
* https://www.glfw.org/docs/latest/group__mods.html
|
||||
* {@return a bit field representing the active modifier keys}
|
||||
*
|
||||
* @see GLFW#GLFW_MOD_SHIFT
|
||||
* @see GLFW#GLFW_MOD_CONTROL
|
||||
* @see GLFW#GLFW_MOD_ALT
|
||||
* @see GLFW#GLFW_MOD_SUPER
|
||||
* @see InputConstants#MOD_CONTROL CTRL modifier key bit
|
||||
* @see GLFW#GLFW_MOD_SHIFT SHIFT modifier key bit
|
||||
* @see GLFW#GLFW_MOD_ALT ALT modifier key bit
|
||||
* @see GLFW#GLFW_MOD_SUPER SUPER modifier key bit
|
||||
* @see GLFW#GLFW_KEY_CAPS_LOCK CAPS LOCK modifier key bit
|
||||
* @see GLFW#GLFW_KEY_NUM_LOCK NUM LOCK modifier key bit
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__mods.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getModifiers()
|
||||
{
|
||||
@@ -69,13 +98,25 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires when a mouse input is detected.
|
||||
* Fired when a mouse button is clicked, <b>after</b> processing.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_mouse_button" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public static class MouseInputEvent extends InputEvent
|
||||
{
|
||||
private final int button;
|
||||
private final int action;
|
||||
private final int modifiers;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onRawMouseClicked(int, int, int)
|
||||
*/
|
||||
public MouseInputEvent(int button, int action, int modifiers)
|
||||
{
|
||||
this.button = button;
|
||||
@@ -84,10 +125,10 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* The mouse button that triggered this event.
|
||||
* https://www.glfw.org/docs/latest/group__buttons.html
|
||||
* {@return the mouse button's input code}
|
||||
*
|
||||
* @see GLFW mouse constants starting with "GLFW_MOUSE_BUTTON_"
|
||||
* @see GLFW mouse constants starting with 'GLFW_MOUSE_BUTTON_'
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__buttons.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getButton()
|
||||
{
|
||||
@@ -95,10 +136,10 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Integer representing the mouse button's action.
|
||||
* {@return the mouse button's action}
|
||||
*
|
||||
* @see GLFW#GLFW_PRESS
|
||||
* @see GLFW#GLFW_RELEASE
|
||||
* @see InputConstants#PRESS
|
||||
* @see InputConstants#RELEASE
|
||||
*/
|
||||
public int getAction()
|
||||
{
|
||||
@@ -106,13 +147,15 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Bit field representing the modifier keys pressed.
|
||||
* https://www.glfw.org/docs/latest/group__mods.html
|
||||
* {@return a bit field representing the active modifier keys}
|
||||
*
|
||||
* @see GLFW#GLFW_MOD_SHIFT
|
||||
* @see GLFW#GLFW_MOD_CONTROL
|
||||
* @see GLFW#GLFW_MOD_ALT
|
||||
* @see GLFW#GLFW_MOD_SUPER
|
||||
* @see InputConstants#MOD_CONTROL CTRL modifier key bit
|
||||
* @see GLFW#GLFW_MOD_SHIFT SHIFT modifier key bit
|
||||
* @see GLFW#GLFW_MOD_ALT ALT modifier key bit
|
||||
* @see GLFW#GLFW_MOD_SUPER SUPER modifier key bit
|
||||
* @see GLFW#GLFW_KEY_CAPS_LOCK CAPS LOCK modifier key bit
|
||||
* @see GLFW#GLFW_KEY_NUM_LOCK NUM LOCK modifier key bit
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__mods.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getModifiers()
|
||||
{
|
||||
@@ -121,7 +164,16 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires when the mouse scroll wheel is used outside of a gui.
|
||||
* Fired when a mouse scroll wheel is used outside of a screen and a player is loaded, <b>before</b> being
|
||||
* processed by vanilla.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, then the mouse scroll event will not be processed further. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_mouse_button" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class MouseScrollEvent extends InputEvent
|
||||
@@ -132,6 +184,11 @@ public class InputEvent extends Event
|
||||
private final boolean leftDown;
|
||||
private final boolean middleDown;
|
||||
private final boolean rightDown;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onMouseScroll(MouseHandler, double)
|
||||
*/
|
||||
public MouseScrollEvent(double scrollDelta, boolean leftDown, boolean middleDown, boolean rightDown, double mouseX, double mouseY)
|
||||
{
|
||||
this.scrollDelta = scrollDelta;
|
||||
@@ -142,31 +199,49 @@ public class InputEvent extends Event
|
||||
this.mouseY = mouseY;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll}
|
||||
*/
|
||||
public double getScrollDelta()
|
||||
{
|
||||
return this.scrollDelta;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the left mouse button is pressed}
|
||||
*/
|
||||
public boolean isLeftDown()
|
||||
{
|
||||
return this.leftDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the right mouse button is pressed}
|
||||
*/
|
||||
public boolean isRightDown()
|
||||
{
|
||||
return this.rightDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the middle mouse button is pressed}
|
||||
*/
|
||||
public boolean isMiddleDown()
|
||||
{
|
||||
return this.middleDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X position of the mouse cursor}
|
||||
*/
|
||||
public double getMouseX()
|
||||
{
|
||||
return this.mouseX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y position of the mouse cursor}
|
||||
*/
|
||||
public double getMouseY()
|
||||
{
|
||||
return this.mouseY;
|
||||
@@ -174,7 +249,12 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires when a keyboard input is detected.
|
||||
* Fired when a keyboard key input occurs, such as pressing, releasing, or repeating a key.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class KeyInputEvent extends InputEvent
|
||||
{
|
||||
@@ -182,6 +262,11 @@ public class InputEvent extends Event
|
||||
private final int scanCode;
|
||||
private final int action;
|
||||
private final int modifiers;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#fireKeyInput(int, int, int, int)
|
||||
*/
|
||||
public KeyInputEvent(int key, int scanCode, int action, int modifiers)
|
||||
{
|
||||
this.key = key;
|
||||
@@ -191,10 +276,11 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* The keyboard key that triggered this event.
|
||||
* https://www.glfw.org/docs/latest/group__keys.html
|
||||
* {@return the {@code GLFW} (platform-agnostic) key code}
|
||||
*
|
||||
* @see GLFW key constants starting with "GLFW_KEY_"
|
||||
* @see InputConstants input constants starting with {@code KEY_}
|
||||
* @see GLFW key constants starting with {@code GLFW_KEY_}
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__keys.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getKey()
|
||||
{
|
||||
@@ -202,12 +288,13 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Platform-specific scan code.
|
||||
* Used for {@link InputConstants#getKey(int, int)}
|
||||
* {@return the platform-specific scan code}
|
||||
*
|
||||
* The scan code is unique for every key, regardless of whether it has a key code.
|
||||
* Scan codes are platform-specific but consistent over time, so keys will have different scan codes depending
|
||||
* on the platform but they are safe to save to disk as custom key bindings.
|
||||
*
|
||||
* @see InputConstants#getKey(int, int)
|
||||
*/
|
||||
public int getScanCode()
|
||||
{
|
||||
@@ -215,11 +302,11 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Integer representing the key's action.
|
||||
* {@return the mouse button's action}
|
||||
*
|
||||
* @see GLFW#GLFW_PRESS
|
||||
* @see GLFW#GLFW_RELEASE
|
||||
* @see GLFW#GLFW_REPEAT
|
||||
* @see InputConstants#PRESS
|
||||
* @see InputConstants#RELEASE
|
||||
* @see InputConstants#REPEAT
|
||||
*/
|
||||
public int getAction()
|
||||
{
|
||||
@@ -227,13 +314,15 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Bit field representing the modifier keys pressed.
|
||||
* https://www.glfw.org/docs/latest/group__mods.html
|
||||
* {@return a bit field representing the active modifier keys}
|
||||
*
|
||||
* @see GLFW#GLFW_MOD_SHIFT
|
||||
* @see GLFW#GLFW_MOD_CONTROL
|
||||
* @see GLFW#GLFW_MOD_ALT
|
||||
* @see GLFW#GLFW_MOD_SUPER
|
||||
* @see InputConstants#MOD_CONTROL CTRL modifier key bit
|
||||
* @see GLFW#GLFW_MOD_SHIFT SHIFT modifier key bit
|
||||
* @see GLFW#GLFW_MOD_ALT ALT modifier key bit
|
||||
* @see GLFW#GLFW_MOD_SUPER SUPER modifier key bit
|
||||
* @see GLFW#GLFW_KEY_CAPS_LOCK CAPS LOCK modifier key bit
|
||||
* @see GLFW#GLFW_KEY_NUM_LOCK NUM LOCK modifier key bit
|
||||
* @see <a href="https://www.glfw.org/docs/latest/group__mods.html" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public int getModifiers()
|
||||
{
|
||||
@@ -242,11 +331,21 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* This event fires when one of the keybindings that by default involves clicking the mouse buttons
|
||||
* is triggered.
|
||||
* Fired when a keymapping that by default involves clicking the mouse buttons is triggered.
|
||||
*
|
||||
* These key bindings are use item, pick block and attack keybindings. (right, middle and left mouse click)
|
||||
* In the case that these key bindings are re-bound to a keyboard key the event will still be fired as normal.
|
||||
* <p>The key bindings that trigger this event are:</p>
|
||||
* <ul>
|
||||
* <li><b>Use Item</b> - defaults to <em>left mouse click</em></li>
|
||||
* <li><b>Pick Block</b> - defaults to <em>middle mouse click</em></li>
|
||||
* <li><b>Attack</b> - defaults to <em>right mouse click</em></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the keymapping's action is not processed further, and the hand will be swung
|
||||
* according to {@link #shouldSwingHand()}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class ClickInputEvent extends InputEvent
|
||||
@@ -255,6 +354,11 @@ public class InputEvent extends Event
|
||||
private final KeyMapping keyMapping;
|
||||
private final InteractionHand hand;
|
||||
private boolean handSwing = true;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onClickInput(int, KeyMapping, InteractionHand)
|
||||
*/
|
||||
public ClickInputEvent(int button, KeyMapping keyMapping, InteractionHand hand)
|
||||
{
|
||||
this.button = button;
|
||||
@@ -263,45 +367,62 @@ public class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to false to disable the hand swing animation.
|
||||
* Has no effect if this is a pick block input.
|
||||
* Sets whether to swing the hand. This takes effect whether or not the event is cancelled.
|
||||
*
|
||||
* @param value whether to swing the hand
|
||||
*/
|
||||
public void setSwingHand(boolean value)
|
||||
{
|
||||
handSwing = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return whether to swing the hand; always takes effect, regardless of cancellation}
|
||||
*/
|
||||
public boolean shouldSwingHand()
|
||||
{
|
||||
return handSwing;
|
||||
}
|
||||
|
||||
/**
|
||||
* The hand which is causing the event to get triggered.
|
||||
* {@return the hand that caused the input}
|
||||
*
|
||||
* The event will be called for both hands if this is a use item input regardless
|
||||
* of if either gets canceled.
|
||||
* Will always be MAIN_HAND if this is an attack or pick block input.
|
||||
* of both event's cancellation.
|
||||
* Will always be {@link InteractionHand#MAIN_HAND} if this is an attack or pick block input.
|
||||
*/
|
||||
public InteractionHand getHand()
|
||||
{
|
||||
return hand;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the mouse button is the left mouse button}
|
||||
*/
|
||||
public boolean isAttack()
|
||||
{
|
||||
return button == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the mouse button is the right mouse button}
|
||||
*/
|
||||
public boolean isUseItem()
|
||||
{
|
||||
return button == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the mouse button is the middle mouse button}
|
||||
*/
|
||||
public boolean isPickBlock()
|
||||
{
|
||||
return button == 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the key mapping which triggered this event}
|
||||
*/
|
||||
public KeyMapping getKeyMapping()
|
||||
{
|
||||
return keyMapping;
|
||||
|
||||
@@ -10,13 +10,22 @@ import java.util.Map;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.client.model.ForgeModelBakery;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
/**
|
||||
* Fired when the ModelManager is notified of the resource manager reloading.
|
||||
* Called after model registry is setup, but before it's passed to BlockModelShapes.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
// TODO: try to merge with ICustomModelLoader
|
||||
public class ModelBakeEvent extends Event implements IModBusEvent
|
||||
@@ -25,6 +34,10 @@ public class ModelBakeEvent extends Event implements IModBusEvent
|
||||
private final Map<ResourceLocation, BakedModel> modelRegistry;
|
||||
private final ForgeModelBakery modelLoader;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onModelBake(ModelManager, Map, ForgeModelBakery)
|
||||
*/
|
||||
public ModelBakeEvent(ModelManager modelManager, Map<ResourceLocation, BakedModel> modelRegistry, ForgeModelBakery modelLoader)
|
||||
{
|
||||
this.modelManager = modelManager;
|
||||
@@ -32,16 +45,25 @@ public class ModelBakeEvent extends Event implements IModBusEvent
|
||||
this.modelLoader = modelLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the model manager}
|
||||
*/
|
||||
public ModelManager getModelManager()
|
||||
{
|
||||
return modelManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the modifiable registry map of models and their model names}
|
||||
*/
|
||||
public Map<ResourceLocation, BakedModel> getModelRegistry()
|
||||
{
|
||||
return modelRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the model loader}
|
||||
*/
|
||||
public ForgeModelBakery getModelLoader()
|
||||
{
|
||||
return modelLoader;
|
||||
|
||||
@@ -8,14 +8,29 @@ package net.minecraftforge.client.event;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.model.IModelLoader;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
/**
|
||||
* Fired when the {@link ModelLoaderRegistry} is ready to register model loaders
|
||||
* Fired when the {@link ModelLoaderRegistry} is ready for model loader registrations.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ModelLoaderRegistry#registerLoader(ResourceLocation, IModelLoader)
|
||||
*/
|
||||
public class ModelRegistryEvent extends Event implements IModBusEvent
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
* @see ModelLoaderRegistry#onModelLoadingStart()
|
||||
*/
|
||||
public ModelRegistryEvent()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -7,22 +7,37 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.client.player.Input;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* This event is fired after player movement inputs are updated.<br>
|
||||
* Handlers can freely manipulate {@link Input} to cancel movement.<br>
|
||||
* <p>Fired after the player's movement inputs are updated.</p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public class MovementInputUpdateEvent extends PlayerEvent
|
||||
{
|
||||
private final Input input;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onMovementInputUpdate(Player, Input)
|
||||
*/
|
||||
public MovementInputUpdateEvent(Player player, Input input)
|
||||
{
|
||||
super(player);
|
||||
this.input = input;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the player's movement inputs}
|
||||
*/
|
||||
public Input getInput()
|
||||
{
|
||||
return input;
|
||||
|
||||
@@ -8,12 +8,31 @@ package net.minecraftforge.client.event;
|
||||
import net.minecraft.client.particle.ParticleEngine;
|
||||
import net.minecraft.client.particle.ParticleProvider;
|
||||
import net.minecraft.core.particles.ParticleType;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.RegisterEvent;
|
||||
|
||||
/**
|
||||
* Fired when you should call {@link ParticleEngine#register(ParticleType, ParticleProvider)}.
|
||||
* Note that your {@code ParticleType}s should still be registered during the usual registry events, this
|
||||
* is only for the factories.
|
||||
* Fired for registering particle providers at the appropriate time.
|
||||
*
|
||||
* <p>{@link ParticleType}s must be registered during {@link RegisterEvent} as usual;
|
||||
* this event is only for the {@link ParticleProvider}s. </p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ParticleEngine#register(ParticleType, ParticleProvider)
|
||||
*/
|
||||
public class ParticleFactoryRegisterEvent extends Event implements IModBusEvent {}
|
||||
public class ParticleFactoryRegisterEvent extends Event implements IModBusEvent {
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public ParticleFactoryRegisterEvent()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -6,24 +6,36 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired on {@link Dist#CLIENT} when {@link RecipeManager} has all of its recipes synced from the server to the client (just after a client has connected),
|
||||
* Fired when the {@link RecipeManager} has received and synced the recipes from the server to the client.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public class RecipesUpdatedEvent extends Event
|
||||
{
|
||||
|
||||
|
||||
private final RecipeManager mgr;
|
||||
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onRecipesUpdated(RecipeManager)
|
||||
*/
|
||||
public RecipesUpdatedEvent(RecipeManager mgr)
|
||||
{
|
||||
this.mgr = mgr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The newly-updated recipe manager that now contains all the recipes that were just received.
|
||||
* {@return the recipe manager}
|
||||
*/
|
||||
public RecipeManager getRecipeManager()
|
||||
{
|
||||
|
||||
@@ -9,29 +9,45 @@ import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.arguments.ObjectiveArgument;
|
||||
import net.minecraft.commands.arguments.ResourceLocationArgument;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Register commands to be executed on the client using this event.
|
||||
*
|
||||
* Some arguments behave differently:
|
||||
* Fired to allow mods to register client commands.
|
||||
*
|
||||
* <p>Some command arguments behave differently for the client commands dispatcher:</p>
|
||||
* <ul>
|
||||
* <li>{@link ResourceLocationArgument#getAdvancement(com.mojang.brigadier.context.CommandContext, String)} only returns advancements that are shown on the advancements screen
|
||||
* <li>{@link ObjectiveArgument#getObjective(com.mojang.brigadier.context.CommandContext, String)} only returns objectives that are set to display
|
||||
* <li>{@link ResourceLocationArgument#getAdvancement(com.mojang.brigadier.context.CommandContext, String)} only returns
|
||||
* advancements that are shown on the advancements screen.
|
||||
* <li>{@link ObjectiveArgument#getObjective(com.mojang.brigadier.context.CommandContext, String)} only returns
|
||||
* objectives that are displayed to the player.
|
||||
* </ul>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see net.minecraftforge.event.RegisterCommandsEvent
|
||||
*/
|
||||
public class RegisterClientCommandsEvent extends Event
|
||||
{
|
||||
|
||||
private final CommandDispatcher<CommandSourceStack> dispatcher;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see net.minecraftforge.client.ClientCommandHandler#mergeServerCommands(CommandDispatcher)
|
||||
*/
|
||||
public RegisterClientCommandsEvent(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The command dispatcher for registering commands to be executed on the client
|
||||
* {@return the command dispatcher for registering commands to be executed on the client}
|
||||
*/
|
||||
public CommandDispatcher<CommandSourceStack> getDispatcher()
|
||||
{
|
||||
|
||||
@@ -5,20 +5,44 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraftforge.event.AddReloadListenerEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
/**
|
||||
* Fired to allow mods to register their reload listeners on the client-side resource manager.
|
||||
* This event is fired once during the construction of the {@link Minecraft} instance.
|
||||
*
|
||||
* <p>For registering reload listeners on the server-side resource manager, see {@link AddReloadListenerEvent}. </p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public class RegisterClientReloadListenersEvent extends Event implements IModBusEvent
|
||||
{
|
||||
private final ReloadableResourceManager resourceManager;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RegisterClientReloadListenersEvent(ReloadableResourceManager resourceManager)
|
||||
{
|
||||
this.resourceManager = resourceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the given reload listener to the client-side resource manager.
|
||||
*
|
||||
* @param reloadListener the reload listener
|
||||
*/
|
||||
public void registerReloadListener(PreparableReloadListener reloadListener)
|
||||
{
|
||||
resourceManager.registerReloadListener(reloadListener);
|
||||
|
||||
@@ -8,28 +8,58 @@ package net.minecraftforge.client.event;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.client.renderer.ShaderInstance;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Fired to allow mods to register custom {@linkplain ShaderInstance shaders}.
|
||||
* This event is fired after the default Minecraft shaders have been registered.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public class RegisterShadersEvent extends Event implements IModBusEvent
|
||||
{
|
||||
private final ResourceManager resourceManager;
|
||||
private final List<Pair<ShaderInstance, Consumer<ShaderInstance>>> shaderList;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RegisterShadersEvent(ResourceManager resourceManager, List<Pair<ShaderInstance, Consumer<ShaderInstance>>> shaderList)
|
||||
{
|
||||
this.resourceManager = resourceManager;
|
||||
this.shaderList = shaderList;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the client-side resource manager}
|
||||
*/
|
||||
public ResourceManager getResourceManager()
|
||||
{
|
||||
return resourceManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a shader, and a callback for when the shader is loaded.
|
||||
*
|
||||
* <p>When creating a {@link ShaderInstance}, pass in the {@linkplain #getResourceManager()
|
||||
* client-side resource manager} as the resource provider. </p>
|
||||
*
|
||||
* <p>Mods should not store the shader instance passed into this method. Instead, mods should store the shader
|
||||
* passed into the registered load callback. </p>
|
||||
*
|
||||
* @param shaderInstance a shader
|
||||
* @param onLoaded a callback for when the shader is loaded
|
||||
*/
|
||||
public void registerShader(ShaderInstance shaderInstance, Consumer<ShaderInstance> onLoaded)
|
||||
{
|
||||
shaderList.add(Pair.of(shaderInstance, onLoaded));
|
||||
|
||||
@@ -7,19 +7,24 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.player.AbstractClientPlayer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.entity.HumanoidArm;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* This is a more targeted version of {@link RenderHandEvent} event that is fired specifically when
|
||||
* a player's arm is being rendered in first person, and should be used instead if the desired
|
||||
* outcome is just to replace the rendering of the arm, such as to make armor render on it or
|
||||
* instead of it.
|
||||
* Fired before the player's arm is rendered in first person. This is a more targeted version of {@link RenderHandEvent},
|
||||
* and can be used to replace the rendering of the player's arm, such as for rendering armor on the arm or outright
|
||||
* replacing the arm with armor.
|
||||
*
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}
|
||||
* Canceling the event causes the arm to not render.
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the arm will not be rendered. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public class RenderArmEvent extends Event
|
||||
@@ -30,6 +35,10 @@ public class RenderArmEvent extends Event
|
||||
private final AbstractClientPlayer player;
|
||||
private final HumanoidArm arm;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see net.minecraftforge.client.ForgeHooksClient#renderSpecificFirstPersonArm(PoseStack, MultiBufferSource, int, AbstractClientPlayer, HumanoidArm)
|
||||
*/
|
||||
public RenderArmEvent(PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, AbstractClientPlayer player, HumanoidArm arm)
|
||||
{
|
||||
this.poseStack = poseStack;
|
||||
@@ -40,30 +49,42 @@ public class RenderArmEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The arm being rendered.
|
||||
* {@return the arm being rendered}
|
||||
*/
|
||||
public HumanoidArm getArm()
|
||||
{
|
||||
return arm;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource()
|
||||
{
|
||||
return multiBufferSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight()
|
||||
{
|
||||
return packedLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the client player that is having their arm rendered. In general this will be the same as {@link net.minecraft.client.Minecraft#player}.
|
||||
* {@return the client player that is having their arm rendered} In general, this will be the same as
|
||||
* {@link net.minecraft.client.Minecraft#player}.
|
||||
*/
|
||||
public AbstractClientPlayer getPlayer()
|
||||
{
|
||||
|
||||
@@ -10,26 +10,54 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Called when a block's texture is going to be overlaid on the player's HUD. Cancel this event to prevent the overlay.
|
||||
* Fired before a block texture will be overlaid on the player's view.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the overlay will not be rendered. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public class RenderBlockOverlayEvent extends Event
|
||||
{
|
||||
|
||||
public static enum OverlayType {
|
||||
FIRE, BLOCK, WATER
|
||||
/**
|
||||
* The type of the block overlay to be rendered.
|
||||
*
|
||||
* @see RenderBlockOverlayEvent
|
||||
*/
|
||||
public enum OverlayType {
|
||||
/**
|
||||
* The type of the overlay when the player is burning / on fire.
|
||||
*/
|
||||
FIRE,
|
||||
/**
|
||||
* The type of overlay when the player is suffocating inside a solid block.
|
||||
*/
|
||||
BLOCK,
|
||||
/**
|
||||
* The type of overlay when the player is underwater.
|
||||
*/
|
||||
WATER
|
||||
}
|
||||
|
||||
|
||||
private final Player player;
|
||||
private final PoseStack poseStack;
|
||||
private final OverlayType overlayType;
|
||||
private final BlockState blockState;
|
||||
private final BlockPos blockPos;
|
||||
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RenderBlockOverlayEvent(Player player, PoseStack poseStack, OverlayType type, BlockState block, BlockPos blockPos)
|
||||
{
|
||||
this.player = player;
|
||||
@@ -37,21 +65,27 @@ public class RenderBlockOverlayEvent extends Event
|
||||
this.overlayType = type;
|
||||
this.blockState = block;
|
||||
this.blockPos = blockPos;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The player which the overlay will apply to
|
||||
* {@return the player which the overlay will apply to}
|
||||
*/
|
||||
public Player getPlayer() { return player; }
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() { return poseStack; }
|
||||
/**
|
||||
* The type of overlay to occur
|
||||
* {@return the type of the overlay}
|
||||
*/
|
||||
public OverlayType getOverlayType() { return overlayType; }
|
||||
/**
|
||||
* If the overlay type is BLOCK, then this is the block which the overlay is getting it's icon from
|
||||
* {@return the block which the overlay is gotten from}
|
||||
*/
|
||||
public BlockState getBlockState() { return blockState; }
|
||||
/**
|
||||
* {@return the position of the block which the overlay is gotten from}
|
||||
*/
|
||||
public BlockPos getBlockPos() { return blockPos; }
|
||||
}
|
||||
@@ -8,122 +8,273 @@ package net.minecraftforge.client.event;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraftforge.client.gui.ForgeIngameGui;
|
||||
import net.minecraftforge.client.gui.IIngameOverlay;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import net.minecraft.client.gui.components.LerpingBossEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired when an overlay element is rendered to the game window.
|
||||
* See the two subclasses for listening to before and after rendering.
|
||||
*
|
||||
* <p>An overlay that is not normally active cannot be forced to render, and this event will not fire. </p>
|
||||
*
|
||||
* @see RenderGameOverlayEvent.Pre
|
||||
* @see RenderGameOverlayEvent.Post
|
||||
* @see ForgeIngameGui
|
||||
*/
|
||||
@Cancelable
|
||||
public class RenderGameOverlayEvent extends Event
|
||||
{
|
||||
public PoseStack getMatrixStack()
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
return mStack;
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
public float getPartialTicks()
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick()
|
||||
{
|
||||
return partialTicks;
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@return the game window}
|
||||
*/
|
||||
public Window getWindow()
|
||||
{
|
||||
return window;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the type of the overlay element being rendered}
|
||||
*/
|
||||
public ElementType getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public static enum ElementType
|
||||
/**
|
||||
* The types of the different overlay elements that can be rendered
|
||||
*/
|
||||
public enum ElementType
|
||||
{
|
||||
/**
|
||||
* Represents all of the overlay elements; cancelling the {@link RenderGameOverlayEvent.Pre} with this type
|
||||
* will suppress rendering of all overlay elements.
|
||||
*/
|
||||
ALL,
|
||||
/**
|
||||
* An in-game overlay layer.
|
||||
*
|
||||
* @see IIngameOverlay
|
||||
* @see RenderGameOverlayEvent.PreLayer
|
||||
* @see RenderGameOverlayEvent.PostLayer
|
||||
*/
|
||||
LAYER,
|
||||
BOSSINFO, // Individual boss bar
|
||||
/**
|
||||
* An individual boss event bar.
|
||||
*
|
||||
* @see RenderGameOverlayEvent.BossInfo
|
||||
*/
|
||||
BOSSINFO,
|
||||
/**
|
||||
* For adding text to be rendered on the screen (after the debug screen text, if visible).
|
||||
*
|
||||
* @see RenderGameOverlayEvent.Text
|
||||
*/
|
||||
TEXT,
|
||||
/**
|
||||
* The chat message window overlay.
|
||||
*
|
||||
* @see RenderGameOverlayEvent.Chat
|
||||
*/
|
||||
CHAT,
|
||||
/**
|
||||
* The player list overlay, shown when the <kbd>TAB</kbd> key (or other keybind) is pressed.
|
||||
*
|
||||
* <em>See {@code ForgeIngameGui#renderPlayerList}</em>
|
||||
*/
|
||||
PLAYER_LIST,
|
||||
/**
|
||||
* The debug overlay.
|
||||
*
|
||||
* <em>See {@code ForgeIngameGui#renderHUDText.}</em>
|
||||
*/
|
||||
DEBUG
|
||||
}
|
||||
|
||||
private final PoseStack mStack;
|
||||
private final float partialTicks;
|
||||
private final PoseStack poseStack;
|
||||
private final float partialTick;
|
||||
private final Window window;
|
||||
private final ElementType type;
|
||||
|
||||
public RenderGameOverlayEvent(PoseStack mStack, float partialTicks, Window window)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RenderGameOverlayEvent(PoseStack poseStack, float partialTick, Window window)
|
||||
{
|
||||
this.mStack = mStack;
|
||||
this.partialTicks = partialTicks;
|
||||
this.poseStack = poseStack;
|
||||
this.partialTick = partialTick;
|
||||
this.window = window;
|
||||
this.type = null;
|
||||
}
|
||||
|
||||
private RenderGameOverlayEvent(PoseStack mStack, RenderGameOverlayEvent parent, ElementType type)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
private RenderGameOverlayEvent(PoseStack poseStack, RenderGameOverlayEvent parent, ElementType type)
|
||||
{
|
||||
this.mStack = mStack;
|
||||
this.partialTicks = parent.getPartialTicks();
|
||||
this.poseStack = poseStack;
|
||||
this.partialTick = parent.getPartialTick();
|
||||
this.window = parent.getWindow();
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> an active overlay element is rendered to the screen.
|
||||
* <em>See the three sub-classes for specific special overlay elements. </em>
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the overlay corresponding to this event will not be rendered, and the
|
||||
* corresponding {@link RenderGameOverlayEvent.Post} event is not fired. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see RenderGameOverlayEvent.PreLayer
|
||||
* @see RenderGameOverlayEvent.BossInfo
|
||||
* @see RenderGameOverlayEvent.Text
|
||||
* @see RenderGameOverlayEvent.Chat
|
||||
*/
|
||||
public static class Pre extends RenderGameOverlayEvent
|
||||
{
|
||||
public Pre(PoseStack mStack, RenderGameOverlayEvent parent, ElementType type)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Pre(PoseStack poseStack, RenderGameOverlayEvent parent, ElementType type)
|
||||
{
|
||||
super(mStack, parent, type);
|
||||
super(poseStack, parent, type);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> an active overlay element is rendered to the screen, if the corresponding
|
||||
* {@link RenderGameOverlayEvent.Pre} is not cancelled.
|
||||
* <em>See the specialized {@link RenderGameOverlayEvent.PostLayer} for individual overlay layer.</em>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class Post extends RenderGameOverlayEvent
|
||||
{
|
||||
public Post(PoseStack mStack, RenderGameOverlayEvent parent, ElementType type)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Post(PoseStack poseStack, RenderGameOverlayEvent parent, ElementType type)
|
||||
{
|
||||
super(mStack, parent, type);
|
||||
super(poseStack, parent, type);
|
||||
}
|
||||
@Override public boolean isCancelable(){ return false; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> an in-game overlay layer is rendered to the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the overlay layer in this event will not be rendered, and the
|
||||
* corresponding {@link RenderGameOverlayEvent.PostLayer} event is not fired. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see RenderGameOverlayEvent.PostLayer
|
||||
*/
|
||||
public static class PreLayer extends Pre
|
||||
{
|
||||
private final IIngameOverlay overlay;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public PreLayer(PoseStack mStack, RenderGameOverlayEvent parent, IIngameOverlay overlay)
|
||||
{
|
||||
super(mStack, parent, ElementType.LAYER);
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the in-game overlay layer being rendered}
|
||||
*/
|
||||
public IIngameOverlay getOverlay()
|
||||
{
|
||||
return overlay;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> an in-game overlay layer is rendered to the screen, if the corresponding
|
||||
* {@link RenderGameOverlayEvent.PreLayer} is not cancelled.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class PostLayer extends Post
|
||||
{
|
||||
private final IIngameOverlay overlay;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public PostLayer(PoseStack mStack, RenderGameOverlayEvent parent, IIngameOverlay overlay)
|
||||
{
|
||||
super(mStack, parent, ElementType.LAYER);
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the in-game overlay layer being rendered}
|
||||
*/
|
||||
public IIngameOverlay getOverlay()
|
||||
{
|
||||
return overlay;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> a boss health bar is rendered to the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the boss health bar corresponding to this event will not be rendered, and the
|
||||
* corresponding {@link RenderGameOverlayEvent.Post} is not fired. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ElementType#BOSSINFO
|
||||
*/
|
||||
public static class BossInfo extends Pre
|
||||
{
|
||||
private final LerpingBossEvent bossEvent;
|
||||
private final int x;
|
||||
private final int y;
|
||||
private int increment;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public BossInfo(PoseStack mStack, RenderGameOverlayEvent parent, ElementType type, LerpingBossEvent bossEvent, int x, int y, int increment)
|
||||
{
|
||||
super(mStack, parent, type);
|
||||
@@ -134,7 +285,7 @@ public class RenderGameOverlayEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The {@link LerpingBossEvent} currently being rendered
|
||||
* {@return the boss health bar currently being rendered}
|
||||
*/
|
||||
public LerpingBossEvent getBossEvent()
|
||||
{
|
||||
@@ -142,7 +293,7 @@ public class RenderGameOverlayEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current x position we are rendering at
|
||||
* {@return the X position of the boss health bar}
|
||||
*/
|
||||
public int getX()
|
||||
{
|
||||
@@ -150,7 +301,7 @@ public class RenderGameOverlayEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current y position we are rendering at
|
||||
* {@return the Y position of the boss health bar}
|
||||
*/
|
||||
public int getY()
|
||||
{
|
||||
@@ -158,7 +309,7 @@ public class RenderGameOverlayEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return How much to move down before rendering the next bar
|
||||
* {@return the Y position increment before rendering the next boss health bar}
|
||||
*/
|
||||
public int getIncrement()
|
||||
{
|
||||
@@ -166,8 +317,9 @@ public class RenderGameOverlayEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the amount to move down before rendering the next bar
|
||||
* @param increment The increment to set
|
||||
* Sets the Y position increment before rendering the next boss health bar.
|
||||
*
|
||||
* @param increment the new Y position increment
|
||||
*/
|
||||
public void setIncrement(int increment)
|
||||
{
|
||||
@@ -175,10 +327,26 @@ public class RenderGameOverlayEvent extends Event
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> textual information is rendered to the debug screen.
|
||||
* This can be used to add or remove text information.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the text will not be rendered; <em>this includes the debug overlay text</em>. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ElementType#TEXT
|
||||
*/
|
||||
public static class Text extends Pre
|
||||
{
|
||||
private final ArrayList<String> left;
|
||||
private final ArrayList<String> right;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Text(PoseStack mStack, RenderGameOverlayEvent parent, ArrayList<String> left, ArrayList<String> right)
|
||||
{
|
||||
super(mStack, parent, ElementType.TEXT);
|
||||
@@ -186,22 +354,42 @@ public class RenderGameOverlayEvent extends Event
|
||||
this.right = right;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the modifiable list of text to render on the left side}
|
||||
*/
|
||||
public ArrayList<String> getLeft()
|
||||
{
|
||||
return left;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the modifiable list of text to render on the right side}
|
||||
*/
|
||||
public ArrayList<String> getRight()
|
||||
{
|
||||
return right;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the chat messages overlay is rendered to the screen.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the chat messages overlay will not be rendered. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ElementType#CHAT
|
||||
*/
|
||||
public static class Chat extends Pre
|
||||
{
|
||||
private int posX;
|
||||
private int posY;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Chat(PoseStack mStack, RenderGameOverlayEvent parent, int posX, int posY)
|
||||
{
|
||||
super(mStack, parent, ElementType.CHAT);
|
||||
@@ -209,21 +397,37 @@ public class RenderGameOverlayEvent extends Event
|
||||
this.setPosY(posY);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X position of the chat messages overlay}
|
||||
*/
|
||||
public int getPosX()
|
||||
{
|
||||
return posX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new X position for rendering the chat messages overlay
|
||||
*
|
||||
* @param posX the new X position
|
||||
*/
|
||||
public void setPosX(int posX)
|
||||
{
|
||||
this.posX = posX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y position of the chat messages overlay}
|
||||
*/
|
||||
public int getPosY()
|
||||
{
|
||||
return posY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new Y position for rendering the chat messages overlay
|
||||
*
|
||||
* @param posY the new y position
|
||||
*/
|
||||
public void setPosY(int posY)
|
||||
{
|
||||
this.posY = posY;
|
||||
|
||||
@@ -5,20 +5,27 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}
|
||||
* whenever a hand is rendered in first person.
|
||||
* Canceling the event causes the hand to not render.
|
||||
* Fired before a hand is rendered in the first person view.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the hand will not be rendered. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see RenderArmEvent
|
||||
*/
|
||||
@Cancelable
|
||||
public class RenderHandEvent extends Event
|
||||
@@ -27,53 +34,73 @@ public class RenderHandEvent extends Event
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
private final float partialTicks;
|
||||
private final float partialTick;
|
||||
private final float interpolatedPitch;
|
||||
private final float swingProgress;
|
||||
private final float equipProgress;
|
||||
@Nonnull
|
||||
private final ItemStack stack;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see net.minecraftforge.client.ForgeHooksClient#renderSpecificFirstPersonHand(InteractionHand, PoseStack, MultiBufferSource, int, float, float, float, float, ItemStack)
|
||||
*/
|
||||
public RenderHandEvent(InteractionHand hand, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight,
|
||||
float partialTicks, float interpolatedPitch,
|
||||
float swingProgress, float equipProgress, @Nonnull ItemStack stack)
|
||||
float partialTick, float interpolatedPitch,
|
||||
float swingProgress, float equipProgress, ItemStack stack)
|
||||
{
|
||||
this.hand = hand;
|
||||
this.poseStack = poseStack;
|
||||
this.multiBufferSource = multiBufferSource;
|
||||
this.packedLight = packedLight;
|
||||
this.partialTicks = partialTicks;
|
||||
this.partialTick = partialTick;
|
||||
this.interpolatedPitch = interpolatedPitch;
|
||||
this.swingProgress = swingProgress;
|
||||
this.equipProgress = equipProgress;
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the hand being rendered}
|
||||
*/
|
||||
public InteractionHand getHand()
|
||||
{
|
||||
return hand;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() {
|
||||
return multiBufferSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight() {
|
||||
return packedLight;
|
||||
}
|
||||
|
||||
public float getPartialTicks()
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick()
|
||||
{
|
||||
return partialTicks;
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The interpolated pitch of the player entity
|
||||
* {@return the interpolated pitch of the player entity}
|
||||
*/
|
||||
public float getInterpolatedPitch()
|
||||
{
|
||||
@@ -81,7 +108,7 @@ public class RenderHandEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The swing progress of the hand being rendered
|
||||
* {@return the swing progress of the hand being rendered}
|
||||
*/
|
||||
public float getSwingProgress()
|
||||
{
|
||||
@@ -89,7 +116,7 @@ public class RenderHandEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The progress of the equip animation. 1.0 is fully equipped.
|
||||
* {@return the progress of the equip animation, from {@code 0.0} to {@code 1.0}}
|
||||
*/
|
||||
public float getEquipProgress()
|
||||
{
|
||||
@@ -97,9 +124,8 @@ public class RenderHandEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The ItemStack to be rendered
|
||||
* {@return the item stack to be rendered}
|
||||
*/
|
||||
@Nonnull
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return stack;
|
||||
|
||||
@@ -6,31 +6,43 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.entity.ItemFrameRenderer;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* This event is called when an item is rendered in an item frame.
|
||||
* Fired before an item stack is rendered in an item frame.
|
||||
* This can be used to prevent normal rendering or add custom rendering.
|
||||
*
|
||||
* You can set canceled to do no further vanilla processing.
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If the event is cancelled, then the item stack will not be rendered</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see ItemFrameRenderer
|
||||
*/
|
||||
@Cancelable
|
||||
public class RenderItemInFrameEvent extends Event
|
||||
{
|
||||
private final ItemStack itemStack;
|
||||
private final ItemFrame itemFrameEntity;
|
||||
private final ItemFrameRenderer renderer;
|
||||
private final ItemFrameRenderer<?> renderer;
|
||||
private final PoseStack poseStack;
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
|
||||
public RenderItemInFrameEvent(ItemFrame itemFrame, ItemFrameRenderer renderItemFrame, PoseStack poseStack,
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RenderItemInFrameEvent(ItemFrame itemFrame, ItemFrameRenderer<?> renderItemFrame, PoseStack poseStack,
|
||||
MultiBufferSource multiBufferSource, int packedLight)
|
||||
{
|
||||
itemStack = itemFrame.getItem();
|
||||
@@ -41,30 +53,49 @@ public class RenderItemInFrameEvent extends Event
|
||||
this.packedLight = packedLight;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
/**
|
||||
* {@return the item stack being rendered}
|
||||
*/
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the item frame entity}
|
||||
*/
|
||||
public ItemFrame getItemFrameEntity()
|
||||
{
|
||||
return itemFrameEntity;
|
||||
}
|
||||
|
||||
public ItemFrameRenderer getRenderer()
|
||||
/**
|
||||
* {@return the renderer for the item frame entity}
|
||||
*/
|
||||
public ItemFrameRenderer<?> getRenderer()
|
||||
{
|
||||
return renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() {
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() {
|
||||
return multiBufferSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight() {
|
||||
return packedLight;
|
||||
}
|
||||
|
||||
@@ -7,9 +7,26 @@ package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired after all level rendering.
|
||||
* This can be used for custom rendering outside of e.g. a block entity or entity renderer.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see GameRenderer
|
||||
* @see LevelRenderer
|
||||
*/
|
||||
public class RenderLevelLastEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
private final LevelRenderer levelRenderer;
|
||||
@@ -18,6 +35,10 @@ public class RenderLevelLastEvent extends net.minecraftforge.eventbus.api.Event
|
||||
private final Matrix4f projectionMatrix;
|
||||
private final long startNanos;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#dispatchRenderLast(LevelRenderer, PoseStack, float, Matrix4f, long)
|
||||
*/
|
||||
public RenderLevelLastEvent(LevelRenderer levelRenderer, PoseStack poseStack, float partialTick, Matrix4f projectionMatrix, long startNanos)
|
||||
{
|
||||
this.levelRenderer = levelRenderer;
|
||||
@@ -27,26 +48,41 @@ public class RenderLevelLastEvent extends net.minecraftforge.eventbus.api.Event
|
||||
this.startNanos = startNanos;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level renderer}
|
||||
*/
|
||||
public LevelRenderer getLevelRenderer()
|
||||
{
|
||||
return levelRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick()
|
||||
{
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the projection matrix}
|
||||
*/
|
||||
public Matrix4f getProjectionMatrix()
|
||||
{
|
||||
return projectionMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the time when rendering started, in nanoseconds}
|
||||
*/
|
||||
public long getStartNanos()
|
||||
{
|
||||
return startNanos;
|
||||
|
||||
@@ -6,13 +6,31 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraft.client.renderer.entity.LivingEntityRenderer;
|
||||
import net.minecraft.client.model.EntityModel;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired when a {@link LivingEntity} is rendered.
|
||||
* See the two subclasses to listen for before and after rendering.
|
||||
*
|
||||
* <p>Despite this event's use of generic type parameters, this is not a {@link net.minecraftforge.eventbus.api.GenericEvent},
|
||||
* and should not be treated as such (such as using generic-specific listeners, which may cause a {@link ClassCastException}).</p>
|
||||
*
|
||||
* @param <T> the living entity that is being rendered
|
||||
* @param <M> the model for the living entity
|
||||
*
|
||||
* @see RenderLivingEvent.Pre
|
||||
* @see RenderLivingEvent.Post
|
||||
* @see RenderPlayerEvent
|
||||
* @see LivingEntityRenderer
|
||||
*/
|
||||
public abstract class RenderLivingEvent<T extends LivingEntity, M extends EntityModel<T>> extends Event
|
||||
{
|
||||
|
||||
@@ -23,6 +41,9 @@ public abstract class RenderLivingEvent<T extends LivingEntity, M extends Entity
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RenderLivingEvent(LivingEntity entity, LivingEntityRenderer<T, M> renderer, float partialTick, PoseStack poseStack,
|
||||
MultiBufferSource multiBufferSource, int packedLight)
|
||||
{
|
||||
@@ -34,23 +55,74 @@ public abstract class RenderLivingEvent<T extends LivingEntity, M extends Entity
|
||||
this.packedLight = packedLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the living entity being rendered
|
||||
*/
|
||||
public LivingEntity getEntity() { return entity; }
|
||||
/**
|
||||
* @return the renderer for the living entity
|
||||
*/
|
||||
public LivingEntityRenderer<T, M> getRenderer() { return renderer; }
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick() { return partialTick; }
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() { return poseStack; }
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() { return multiBufferSource; }
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight() { return packedLight; }
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> an entity is rendered.
|
||||
* This can be used to render additional effects or suppress rendering.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancelable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the entity will not be rendered and the corresponding
|
||||
* {@link RenderLivingEvent.Post} will not be fired. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @param <T> the living entity that is being rendered
|
||||
* @param <M> the model for the living entity
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre<T extends LivingEntity, M extends EntityModel<T>> extends RenderLivingEvent<T, M>
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Pre(LivingEntity entity, LivingEntityRenderer<T, M> renderer, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
super(entity, renderer, partialTick, poseStack, multiBufferSource, packedLight);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> an entity is rendered, if the corresponding {@link RenderLivingEvent.Post} is not cancelled.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancelable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @param <T> the living entity that was rendered
|
||||
* @param <M> the model for the living entity
|
||||
*/
|
||||
public static class Post<T extends LivingEntity, M extends EntityModel<T>> extends RenderLivingEvent<T, M>
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Post(LivingEntity entity, LivingEntityRenderer<T, M> renderer, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
super(entity, renderer, partialTick, poseStack, multiBufferSource, packedLight);
|
||||
}
|
||||
|
||||
@@ -12,29 +12,25 @@ import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.EntityEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* RenderNameplateEvent is fired whenever the entity renderer attempts to render a name plate/tag of an entity.
|
||||
* <br>
|
||||
* {@link #nameplateContent} contains the content being rendered on the name plate/tag. This can be changed by mods.<br>
|
||||
* {@link #originalContent} contains the original content being rendered on the name plate/tag. This cannot be
|
||||
* changed by mods.<br>
|
||||
* {@link #entityRenderer} contains the entity renderer instance that renders the name plate/tag. This cannot be
|
||||
* changed by mods.<br>
|
||||
* {@link #poseStack} contains the matrix stack instance involved in rendering the name plate/tag. This cannot
|
||||
* be changed by mods.<br>
|
||||
* {@link #multiBufferSource} contains the render type buffer instance involved in rendering the name plate/tag.
|
||||
* This cannot be changed by mods.<br>
|
||||
* {@link #packedLight} contains the sky and block light values used in rendering the name plate/tag.<br>
|
||||
* {@link #partialTick} contains the partial ticks used in rendering the name plate/tag. This cannot be changed by mods.<br>
|
||||
* <br>
|
||||
* This event has a result. {@link HasResult}. <br>
|
||||
* ALLOW will force-render name plate/tag, DEFAULT will ignore the hook and continue using the vanilla check
|
||||
* and DENY will prevent name plate/tag from rendering<br>
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.
|
||||
**/
|
||||
* Fired before an entity renderer renders the nameplate of an entity.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and {@linkplain HasResult has a result}. </p>
|
||||
* <ul>
|
||||
* <li>{@link Result#ALLOW} - the nameplate will be forcibly rendered.</li>
|
||||
* <li>{@link Result#DEFAULT} - the vanilla logic will be used.</li>
|
||||
* <li>{@link Result#DENY} - the nameplate will not be rendered.</li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see EntityRenderer
|
||||
*/
|
||||
@Event.HasResult
|
||||
public class RenderNameplateEvent extends EntityEvent
|
||||
{
|
||||
@@ -46,7 +42,10 @@ public class RenderNameplateEvent extends EntityEvent
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
private final float partialTick;
|
||||
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RenderNameplateEvent(Entity entity, Component content, EntityRenderer<?> entityRenderer, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, float partialTick)
|
||||
{
|
||||
super(entity);
|
||||
@@ -60,7 +59,9 @@ public class RenderNameplateEvent extends EntityEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content that is to be rendered on the name plate/tag
|
||||
* Sets the new text on the nameplate.
|
||||
*
|
||||
* @param contents the new text
|
||||
*/
|
||||
public void setContent(Component contents)
|
||||
{
|
||||
@@ -68,7 +69,7 @@ public class RenderNameplateEvent extends EntityEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* The content being rendered on the name plate/tag
|
||||
* {@return the text on the nameplate that will be rendered, if the event is not {@link Result#DENY DENIED}}
|
||||
*/
|
||||
public Component getContent()
|
||||
{
|
||||
@@ -76,7 +77,7 @@ public class RenderNameplateEvent extends EntityEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* The original content being rendered on the name plate/tag
|
||||
* {@return the original text on the nameplate}
|
||||
*/
|
||||
public Component getOriginalContent()
|
||||
{
|
||||
@@ -84,7 +85,7 @@ public class RenderNameplateEvent extends EntityEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* The entity renderer that renders the name plate/tag, if it was provided
|
||||
* {@return the entity renderer rendering the nameplate}
|
||||
*/
|
||||
public EntityRenderer<?> getEntityRenderer()
|
||||
{
|
||||
@@ -92,7 +93,7 @@ public class RenderNameplateEvent extends EntityEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* The matrix stack used during the rendering of the name plate/tag
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
@@ -100,7 +101,7 @@ public class RenderNameplateEvent extends EntityEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* The render type buffer used during the rendering of the name plate/tag
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource()
|
||||
{
|
||||
@@ -108,15 +109,17 @@ public class RenderNameplateEvent extends EntityEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* The packed values of sky and block light used during the rendering of the name plate/tag
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see net.minecraft.client.renderer.LightTexture
|
||||
*/
|
||||
public int getPackedLight()
|
||||
{
|
||||
return this.packedLight;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The partial ticks used during the rendering of the name plate/tag
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick()
|
||||
{
|
||||
|
||||
@@ -6,12 +6,23 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraft.client.renderer.entity.player.PlayerRenderer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired when a player is being rendered.
|
||||
* See the two subclasses for listening for before and after rendering.
|
||||
*
|
||||
* @see RenderPlayerEvent.Pre
|
||||
* @see RenderPlayerEvent.Post
|
||||
* @see PlayerRenderer
|
||||
*/
|
||||
public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
{
|
||||
private final PlayerRenderer renderer;
|
||||
@@ -20,6 +31,9 @@ public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
private final MultiBufferSource multiBufferSource;
|
||||
private final int packedLight;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RenderPlayerEvent(Player player, PlayerRenderer renderer, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight)
|
||||
{
|
||||
super(player);
|
||||
@@ -30,22 +44,64 @@ public abstract class RenderPlayerEvent extends PlayerEvent
|
||||
this.packedLight = packedLight;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the player entity renderer}
|
||||
*/
|
||||
public PlayerRenderer getRenderer() { return renderer; }
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick() { return partialTick; }
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() { return poseStack; }
|
||||
/**
|
||||
* {@return the source of rendering buffers}
|
||||
*/
|
||||
public MultiBufferSource getMultiBufferSource() { return multiBufferSource; }
|
||||
/**
|
||||
* {@return the amount of packed (sky and block) light for rendering}
|
||||
*
|
||||
* @see LightTexture
|
||||
*/
|
||||
public int getPackedLight() { return packedLight; }
|
||||
|
||||
/**
|
||||
* Fired <b>before</b> the player is rendered.
|
||||
* This can be used for rendering additional effects or suppressing rendering.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the player will not be rendered and the corresponding
|
||||
* {@link RenderPlayerEvent.Post} will not be fired. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends RenderPlayerEvent
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Pre(Player player, PlayerRenderer renderer, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
super(player, renderer, partialTick, poseStack, multiBufferSource, packedLight);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired <b>after</b> the player is rendered, if the corresponding {@link RenderPlayerEvent.Pre} is not cancelled.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class Post extends RenderPlayerEvent
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Post(Player player, PlayerRenderer renderer, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight) {
|
||||
super(player, renderer, partialTick, poseStack, multiBufferSource, packedLight);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ package net.minecraftforge.client.event;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.datafixers.util.Either;
|
||||
import net.minecraft.client.gui.Font;
|
||||
@@ -17,24 +15,24 @@ import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent
|
||||
import net.minecraft.world.inventory.tooltip.TooltipComponent;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* A set of events which are fired at various points during tooltip rendering.
|
||||
* <p>
|
||||
* Can be used to change the rendering parameters, draw something extra, etc.
|
||||
* <p>
|
||||
* Do not use this event directly, use one of the subclasses:
|
||||
* <ul>
|
||||
* <li>{@link RenderTooltipEvent.Pre}</li>
|
||||
* <li>{@link RenderTooltipEvent.GatherComponents}</li>
|
||||
* <li>{@link RenderTooltipEvent.Color}</li>
|
||||
* </ul>
|
||||
* Fired during tooltip rendering.
|
||||
* See the various subclasses for listening to specific events.
|
||||
*
|
||||
* @see RenderTooltipEvent.GatherComponents
|
||||
* @see RenderTooltipEvent.Pre
|
||||
* @see RenderTooltipEvent.Color
|
||||
*/
|
||||
public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api.Event
|
||||
{
|
||||
@Nonnull
|
||||
@NotNull
|
||||
protected final ItemStack itemStack;
|
||||
protected final PoseStack poseStack;
|
||||
protected int x;
|
||||
@@ -43,7 +41,10 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
protected final List<ClientTooltipComponent> components;
|
||||
|
||||
|
||||
public RenderTooltipEvent(@Nonnull ItemStack itemStack, PoseStack poseStack, int x, int y, @Nonnull Font font, @Nonnull List<ClientTooltipComponent> components)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public RenderTooltipEvent(@NotNull ItemStack itemStack, PoseStack poseStack, int x, int y, @NotNull Font font, @NotNull List<ClientTooltipComponent> components)
|
||||
{
|
||||
this.itemStack = itemStack;
|
||||
this.poseStack = poseStack;
|
||||
@@ -54,9 +55,10 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The stack which the tooltip is being rendered for. As tooltips can be drawn without itemstacks, this stack may be empty.
|
||||
* {@return the item stack which the tooltip is being rendered for, or an {@linkplain ItemStack#isEmpty() empty
|
||||
* item stack} if there is no associated item stack}
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return itemStack;
|
||||
@@ -64,23 +66,23 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
|
||||
|
||||
/**
|
||||
* @return The PoseStack rendering context.
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack() { return poseStack; }
|
||||
|
||||
/**
|
||||
* The components to be drawn.
|
||||
* To modify this list use {@link GatherComponents}.
|
||||
* @return an unmodifiable list of tooltip components to be drawn.
|
||||
* {@return the unmodifiable list of tooltip components}
|
||||
*
|
||||
* <p>Use {@link ItemTooltipEvent} or {@link GatherComponents} to modify tooltip contents or components. </p>
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public List<ClientTooltipComponent> getComponents()
|
||||
{
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The X position of the tooltip box. By default, the mouse X position.
|
||||
*{@return the X position of the tooltip box} By default, this is the mouse X position.
|
||||
*/
|
||||
public int getX()
|
||||
{
|
||||
@@ -88,27 +90,32 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Y position of the tooltip box. By default, the mouse Y position.
|
||||
* {@return the Y position of the tooltip box} By default, this is the mouse Y position.
|
||||
*/
|
||||
public int getY()
|
||||
{
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The {@link Font} instance the current render is using.
|
||||
* {@return The font used to render the text}
|
||||
*/
|
||||
@Nonnull
|
||||
@NotNull
|
||||
public Font getFont()
|
||||
{
|
||||
return font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fires when a tooltip gathers the {@link TooltipComponent}s to render. This event fires before any text wrapping
|
||||
* or text processing.
|
||||
* This event allows modifying the components to be rendered as well as specifying a maximum width for the tooltip.
|
||||
* The maximum width will cause any text components to be wrapped.
|
||||
* Fired when a tooltip gathers the {@link TooltipComponent}s to be rendered, before any text wrapping or processing.
|
||||
* The list of components and the maximum width of the tooltip can be modified through this event.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the list of components will be empty, causing the tooltip to not be rendered and
|
||||
* the corresponding {@link RenderTooltipEvent.Pre} and {@link RenderTooltipEvent.Color} to not be fired. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class GatherComponents extends Event
|
||||
@@ -119,6 +126,9 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
private final List<Either<FormattedText, TooltipComponent>> tooltipElements;
|
||||
private int maxWidth;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public GatherComponents(ItemStack itemStack, int screenWidth, int screenHeight, List<Either<FormattedText, TooltipComponent>> tooltipElements, int maxWidth)
|
||||
{
|
||||
this.itemStack = itemStack;
|
||||
@@ -129,7 +139,8 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ItemStack whose tooltip is being rendered or an empty stack if this tooltip is not for a stack
|
||||
* {@return the item stack which the tooltip is being rendered for, or an {@linkplain ItemStack#isEmpty() empty
|
||||
* item stack} if there is no associated item stack}
|
||||
*/
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
@@ -137,7 +148,9 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the width of the screen
|
||||
* {@return the width of the screen}.
|
||||
* The lines of text within the tooltip are wrapped to be within the screen width, and the tooltip box itself
|
||||
* is moved to be within the screen width.
|
||||
*/
|
||||
public int getScreenWidth()
|
||||
{
|
||||
@@ -145,7 +158,8 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the height of the screen
|
||||
* {@return the height of the screen}
|
||||
* The tooltip box is moved to be within the screen height.
|
||||
*/
|
||||
public int getScreenHeight()
|
||||
{
|
||||
@@ -153,8 +167,8 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* The elements to be rendered. These can be either formatted text or custom tooltip components.
|
||||
* This list is modifiable.
|
||||
* {@return the modifiable list of elements to be rendered on the tooltip} These elements can be either
|
||||
* formatted text or custom tooltip components.
|
||||
*/
|
||||
public List<Either<FormattedText, TooltipComponent>> getTooltipElements()
|
||||
{
|
||||
@@ -162,7 +176,10 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current maximum width for the text components of the tooltip (or -1 for no maximum width)
|
||||
* {@return the maximum width of the tooltip when being rendered}
|
||||
*
|
||||
* <p>A value of {@code -1} means an unlimited maximum width. However, an unlimited maximum width will still
|
||||
* be wrapped to be within the screen bounds.</p>
|
||||
*/
|
||||
public int getMaxWidth()
|
||||
{
|
||||
@@ -170,7 +187,9 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum width for the text components of the tooltip (or -1 for no maximum width)
|
||||
* Sets the maximum width of the tooltip. Use {@code -1} for unlimited maximum width.
|
||||
*
|
||||
* @param maxWidth the new maximum width
|
||||
*/
|
||||
public void setMaxWidth(int maxWidth)
|
||||
{
|
||||
@@ -179,43 +198,65 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired before any tooltip calculations are done. It provides setters for all aspects of the tooltip, so the final render can be modified.
|
||||
* <p>
|
||||
* This event is {@link Cancelable}.
|
||||
* Fired <b>before</b> the tooltip is rendered.
|
||||
* This can be used to modify the positioning and font of the tooltip.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the tooltip will not be rendered and the corresponding
|
||||
* {@link RenderTooltipEvent.Color} will not be fired. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends RenderTooltipEvent
|
||||
{
|
||||
private int screenWidth;
|
||||
private int screenHeight;
|
||||
private final int screenWidth;
|
||||
private final int screenHeight;
|
||||
|
||||
public Pre(@Nonnull ItemStack stack, PoseStack poseStack, int x, int y, int screenWidth, int screenHeight, @Nonnull Font font, @Nonnull List<ClientTooltipComponent> components)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Pre(@NotNull ItemStack stack, PoseStack poseStack, int x, int y, int screenWidth, int screenHeight, @NotNull Font font, @NotNull List<ClientTooltipComponent> components)
|
||||
{
|
||||
super(stack, poseStack, x, y, font, components);
|
||||
this.screenWidth = screenWidth;
|
||||
this.screenHeight = screenHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the width of the screen}.
|
||||
* The lines of text within the tooltip are wrapped to be within the screen width, and the tooltip box itself
|
||||
* is moved to be within the screen width.
|
||||
*/
|
||||
public int getScreenWidth()
|
||||
{
|
||||
return screenWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the height of the screen}
|
||||
* The tooltip box is moved to be within the screen height.
|
||||
*/
|
||||
public int getScreenHeight()
|
||||
{
|
||||
return screenHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link Font} to be used to render text.
|
||||
* Sets the font to be used to render text.
|
||||
*
|
||||
* @param fr the new font
|
||||
*/
|
||||
public void setFont(@Nonnull Font fr)
|
||||
public void setFont(@NotNull Font fr)
|
||||
{
|
||||
this.font = fr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the X origin of the tooltip.
|
||||
* Sets the X origin of the tooltip.
|
||||
*
|
||||
* @param x the new X origin
|
||||
*/
|
||||
public void setX(int x)
|
||||
{
|
||||
@@ -223,7 +264,9 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Y origin of the tooltip.
|
||||
* Sets the Y origin of the tooltip.
|
||||
*
|
||||
* @param y the new Y origin
|
||||
*/
|
||||
public void setY(int y)
|
||||
{
|
||||
@@ -232,7 +275,13 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired when the colours for the tooltip background are determined.
|
||||
* Fired when the colours for the tooltip background are determined.
|
||||
* This can be used to modify the background color and the border's gradient colors.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class Color extends RenderTooltipEvent
|
||||
{
|
||||
@@ -244,7 +293,10 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
private int borderStart;
|
||||
private int borderEnd;
|
||||
|
||||
public Color(@Nonnull ItemStack stack, PoseStack poseStack, int x, int y, @Nonnull Font fr, int background, int borderStart, int borderEnd, @Nonnull List<ClientTooltipComponent> components)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public Color(@NotNull ItemStack stack, PoseStack poseStack, int x, int y, @NotNull Font fr, int background, int borderStart, int borderEnd, @NotNull List<ClientTooltipComponent> components)
|
||||
{
|
||||
super(stack, poseStack, x, y, fr, components);
|
||||
this.originalBackground = background;
|
||||
@@ -256,67 +308,118 @@ public abstract class RenderTooltipEvent extends net.minecraftforge.eventbus.api
|
||||
this.borderEnd = borderEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the gradient start color for the tooltip background}
|
||||
*/
|
||||
public int getBackgroundStart()
|
||||
{
|
||||
return backgroundStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the gradient end color for the tooltip background}
|
||||
*/
|
||||
public int getBackgroundEnd()
|
||||
{
|
||||
return backgroundEnd;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the new color for the tooltip background. This sets both the gradient start and end color for the
|
||||
* background to this color.
|
||||
*
|
||||
* @param background the new color for the tooltip background
|
||||
*/
|
||||
public void setBackground(int background)
|
||||
{
|
||||
this.backgroundStart = background;
|
||||
this.backgroundEnd = background;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new start color for the gradient of the tooltip background.
|
||||
*
|
||||
* @param backgroundStart the new start color for the tooltip background
|
||||
*/
|
||||
public void setBackgroundStart(int backgroundStart)
|
||||
{
|
||||
this.backgroundStart = backgroundStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new end color for the gradient of the tooltip background.
|
||||
*
|
||||
* @param backgroundEnd the new end color for the tooltip background
|
||||
*/
|
||||
public void setBackgroundEnd(int backgroundEnd)
|
||||
{
|
||||
this.backgroundEnd = backgroundEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the gradient start color for the tooltip border}
|
||||
*/
|
||||
public int getBorderStart()
|
||||
{
|
||||
return borderStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new start color for the gradient of the tooltip border.
|
||||
*
|
||||
* @param borderStart the new start color for the tooltip border
|
||||
*/
|
||||
public void setBorderStart(int borderStart)
|
||||
{
|
||||
this.borderStart = borderStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the gradient end color for the tooltip border}
|
||||
*/
|
||||
public int getBorderEnd()
|
||||
{
|
||||
return borderEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new end color for the gradient of the tooltip border.
|
||||
*
|
||||
* @param borderEnd the new end color for the tooltip border
|
||||
*/
|
||||
public void setBorderEnd(int borderEnd)
|
||||
{
|
||||
this.borderEnd = borderEnd;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original tooltip background's gradient start color}
|
||||
*/
|
||||
public int getOriginalBackgroundStart()
|
||||
{
|
||||
return originalBackground;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original tooltip background's gradient end color}
|
||||
*/
|
||||
public int getOriginalBackgroundEnd()
|
||||
{
|
||||
return originalBackground;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original tooltip border's gradient start color}
|
||||
*/
|
||||
public int getOriginalBorderStart()
|
||||
{
|
||||
return originalBorderStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original tooltip border's gradient end color}
|
||||
*/
|
||||
public int getOriginalBorderEnd()
|
||||
{
|
||||
return originalBorderEnd;
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -5,30 +5,50 @@
|
||||
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* This event is called before any Screen will open.
|
||||
* If you don't want this to happen, cancel the event.
|
||||
* If you want to override this Screen, simply set the screen variable to your own Screen.
|
||||
* Fired before any {@link Screen} will be opened, to allow changing or preventing it from being opened. All screen
|
||||
* layers on the screen are closed before this event is fired.
|
||||
*
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the {@code Screen} shall be prevented from opening and any previous screen
|
||||
* will remain open. However, cancelling this event will not prevent the closing of screen layers which happened before
|
||||
* this event fired.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
@Cancelable
|
||||
public class ScreenOpenEvent extends Event
|
||||
{
|
||||
private Screen screen;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public ScreenOpenEvent(Screen screen)
|
||||
{
|
||||
this.setScreen(screen);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the screen that will be opened, if the event is not cancelled}
|
||||
*/
|
||||
public Screen getScreen()
|
||||
{
|
||||
return screen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new screen to be opened, if the event is not cancelled.
|
||||
*
|
||||
* @param screen the new screen
|
||||
*/
|
||||
public void setScreen(Screen screen)
|
||||
{
|
||||
this.screen = screen;
|
||||
|
||||
@@ -6,68 +6,105 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import net.minecraft.client.Screenshot;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This event is fired before and after a screenshot is taken
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}
|
||||
* This event is {@link Cancelable}
|
||||
* Fired when a screenshot is taken, but before it is written to disk.
|
||||
*
|
||||
* {@link #screenshotFile} contains the file the screenshot will be/was saved to
|
||||
* {@link #image} contains the {@link NativeImage} that will be saved
|
||||
* {@link #resultMessage} contains the {@link Component} to be returned. If {@code null}, the default vanilla message will be used instead
|
||||
* <p>This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
|
||||
* If this event is cancelled, then the screenshot is not written to disk, and the message in the event will be posted
|
||||
* to the player's chat.</p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see Screenshot
|
||||
*/
|
||||
@Cancelable
|
||||
public class ScreenshotEvent extends Event
|
||||
{
|
||||
|
||||
public static final Component DEFAULT_CANCEL_REASON = new TextComponent("Screenshot canceled");
|
||||
public static final Component DEFAULT_CANCEL_REASON = Component.literal("Screenshot canceled");
|
||||
|
||||
private NativeImage image;
|
||||
private final NativeImage image;
|
||||
private File screenshotFile;
|
||||
|
||||
private Component resultMessage = null;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see net.minecraftforge.client.ForgeHooksClient#onScreenshot(NativeImage, File)
|
||||
*/
|
||||
public ScreenshotEvent(NativeImage image, File screenshotFile)
|
||||
{
|
||||
this.image = image;
|
||||
this.screenshotFile = screenshotFile;
|
||||
try {
|
||||
this.screenshotFile = screenshotFile.getCanonicalFile(); // FORGE: Fix errors on Windows with paths that include \.\
|
||||
} catch (IOException e) {}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the in-memory image of the screenshot}
|
||||
*/
|
||||
public NativeImage getImage()
|
||||
{
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the file where the screenshot will be saved to
|
||||
*/
|
||||
public File getScreenshotFile()
|
||||
{
|
||||
return screenshotFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new file where the screenshot will be saved to.
|
||||
*
|
||||
* @param screenshotFile the new filepath
|
||||
*/
|
||||
public void setScreenshotFile(File screenshotFile)
|
||||
{
|
||||
this.screenshotFile = screenshotFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the custom cancellation message, or {@code null} if no custom message is set}
|
||||
*/
|
||||
public Component getResultMessage()
|
||||
{
|
||||
return resultMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new custom cancellation message used to inform the player.
|
||||
* It may be {@code null}, in which case the {@linkplain #DEFAULT_CANCEL_REASON default cancel reason} will be used.
|
||||
*
|
||||
* @param resultMessage the new result message
|
||||
*/
|
||||
public void setResultMessage(Component resultMessage)
|
||||
{
|
||||
this.resultMessage = resultMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the cancellation message to be used in informing the player.
|
||||
*
|
||||
* <p>If there is no custom message given ({@link #getResultMessage()} returns {@code null}), then
|
||||
* the message will be the {@linkplain #DEFAULT_CANCEL_REASON default cancel reason message}.</p>
|
||||
*
|
||||
* @return the cancel message for the player
|
||||
*/
|
||||
public Component getCancelMessage()
|
||||
{
|
||||
return getResultMessage() != null ? getResultMessage() : DEFAULT_CANCEL_REASON;
|
||||
|
||||
@@ -6,35 +6,62 @@
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Fired before and after a texture atlas stitched together.
|
||||
* See the two subclasses to listen for before and after stitching.
|
||||
*
|
||||
* @see TextureStitchEvent.Pre
|
||||
* @see TextureStitchEvent.Post
|
||||
* @see TextureAtlas
|
||||
*/
|
||||
public class TextureStitchEvent extends Event implements IModBusEvent
|
||||
{
|
||||
private final TextureAtlas atlas;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public TextureStitchEvent(TextureAtlas atlas)
|
||||
{
|
||||
this.atlas = atlas;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the texture atlas}
|
||||
*/
|
||||
public TextureAtlas getAtlas()
|
||||
{
|
||||
return atlas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the TextureMap is told to refresh it's stitched texture.
|
||||
* Called before the {@link net.minecraft.client.renderer.texture.TextureAtlasSprite} are loaded.
|
||||
* <p>Fired <b>before</b> a texture atlas is stitched together.
|
||||
* This can be used to add custom sprites to be stitched into the atlas. </p>
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus()} mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class Pre extends TextureStitchEvent
|
||||
{
|
||||
private final Set<ResourceLocation> sprites;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onTextureStitchedPre(TextureAtlas, Set)
|
||||
*/
|
||||
public Pre(TextureAtlas map, Set<ResourceLocation> sprites)
|
||||
{
|
||||
super(map);
|
||||
@@ -42,7 +69,12 @@ public class TextureStitchEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a sprite to be stitched into the Texture Atlas.
|
||||
* Adds a sprite to be stitched into the texture atlas.
|
||||
*
|
||||
* <p>Callers should check that the atlas which the event is fired for is the atlas they wish to stitch the
|
||||
* sprite into, as otherwise they would be stitching the sprite into all atlases.</p>
|
||||
*
|
||||
* @param sprite the location of the sprite
|
||||
*/
|
||||
public boolean addSprite(ResourceLocation sprite) {
|
||||
return this.sprites.add(sprite);
|
||||
@@ -50,12 +82,19 @@ public class TextureStitchEvent extends Event implements IModBusEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* This event is fired once the texture map has loaded all textures and
|
||||
* stitched them together. All Icons should have there locations defined
|
||||
* by the time this is fired.
|
||||
* Fired <b>after</b> a texture atlas is stitched together and all textures therein has been loaded.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus()} mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public static class Post extends TextureStitchEvent
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
* @see ForgeHooksClient#onTextureStitchedPost(TextureAtlas)
|
||||
*/
|
||||
public Post(TextureAtlas map){ super(map); }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
/**
|
||||
* Events fired only on the client-side, chiefly related to rendering and user interfaces (screens and input).
|
||||
*/
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
package net.minecraftforge.client.event;
|
||||
|
||||
import net.minecraft.FieldsAreNonnullByDefault;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -7,19 +7,35 @@ package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/***
|
||||
* Raised when the SoundManager tries to play a normal sound.
|
||||
/**
|
||||
* Fired when a sound is about to be played by the sound engine. This fires before the sound is played and before any
|
||||
* checks on the sound (such as a zeroed volume, an empty {@link net.minecraft.client.resources.sounds.Sound}, and
|
||||
* others). This can be used to change or prevent (by passing {@code null)} a sound from being played through
|
||||
* {@link #setSound(SoundInstance)}).
|
||||
*
|
||||
* If you return null from this function it will prevent the sound from being played,
|
||||
* you can return a different entry if you want to change the sound being played.
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see PlaySoundSourceEvent
|
||||
* @see PlayStreamingSourceEvent
|
||||
*/
|
||||
public class PlaySoundEvent extends SoundEvent
|
||||
{
|
||||
private final String name;
|
||||
private final SoundInstance originalSound;
|
||||
@Nullable
|
||||
private SoundInstance sound;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public PlaySoundEvent(SoundEngine manager, SoundInstance sound)
|
||||
{
|
||||
super(manager);
|
||||
@@ -28,23 +44,38 @@ public class PlaySoundEvent extends SoundEvent
|
||||
this.setSound(sound);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the name of the original sound} This is equivalent to the path of the location of the original sound.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original sound that was to be played}
|
||||
*/
|
||||
public SoundInstance getOriginalSound()
|
||||
{
|
||||
return originalSound;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the sound to be played, or {@code null} if no sound will be played}
|
||||
*/
|
||||
@Nullable
|
||||
public SoundInstance getSound()
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
|
||||
public void setSound(SoundInstance result)
|
||||
/**
|
||||
* Sets the sound to be played, which may be {@code null} to prevent any sound from being played.
|
||||
*
|
||||
* @param newSound the new sound to be played, or {@code null} for no sound
|
||||
*/
|
||||
public void setSound(@Nullable SoundInstance newSound)
|
||||
{
|
||||
this.sound = result;
|
||||
this.sound = newSound;
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,29 @@ import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import com.mojang.blaze3d.audio.Channel;
|
||||
import net.minecraftforge.client.event.sound.SoundEvent.SoundSourceEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired when a <em>non-streaming</em> sound is being played. A non-streaming sound is loaded fully into memory
|
||||
* in a buffer before being played, and used for most sounds of short length such as sound effects for clicking
|
||||
* buttons.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see PlayStreamingSourceEvent
|
||||
*/
|
||||
public class PlaySoundSourceEvent extends SoundSourceEvent
|
||||
{
|
||||
public PlaySoundSourceEvent(SoundEngine manager, SoundInstance sound, Channel source)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public PlaySoundSourceEvent(SoundEngine engine, SoundInstance sound, Channel channel)
|
||||
{
|
||||
super(manager, sound, source);
|
||||
super(engine, sound, channel);
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,29 @@ import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import com.mojang.blaze3d.audio.Channel;
|
||||
import net.minecraftforge.client.event.sound.SoundEvent.SoundSourceEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
/**
|
||||
* Fired when a <em>streaming</em> sound is being played. A streaming sound is streamed directly from its source
|
||||
* (such as a file), and used for sounds of long length which are unsuitable to keep fully loaded in-memory in a buffer
|
||||
* (as is done for regular non-streaming sounds), such as background music or music discs.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see PlayStreamingSourceEvent
|
||||
*/
|
||||
public class PlayStreamingSourceEvent extends SoundSourceEvent
|
||||
{
|
||||
public PlayStreamingSourceEvent(SoundEngine manager, SoundInstance sound, Channel source)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public PlayStreamingSourceEvent(SoundEngine engine, SoundInstance sound, Channel channel)
|
||||
{
|
||||
super(manager, sound, source);
|
||||
super(engine, sound, channel);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
/**
|
||||
* Fired when the {@link SoundEngine} is constructed or (re)loaded, such as during game initialization or when the sound
|
||||
* output device is changed.
|
||||
*
|
||||
* <p>This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}. </p>
|
||||
*
|
||||
* <p>This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*/
|
||||
public class SoundEngineLoadEvent extends SoundEvent implements IModBusEvent
|
||||
{
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public SoundEngineLoadEvent(SoundEngine manager)
|
||||
{
|
||||
super(manager);
|
||||
}
|
||||
}
|
||||
@@ -8,44 +8,85 @@ package net.minecraftforge.client.event.sound;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import com.mojang.blaze3d.audio.Channel;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
|
||||
public class SoundEvent extends net.minecraftforge.eventbus.api.Event
|
||||
/**
|
||||
* Superclass for sound related events.
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see SoundSourceEvent
|
||||
* @see PlaySoundEvent
|
||||
* @see SoundEngineLoadEvent
|
||||
*/
|
||||
public class SoundEvent extends Event
|
||||
{
|
||||
private final SoundEngine engine;
|
||||
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public SoundEvent(SoundEngine engine)
|
||||
{
|
||||
this.engine = engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the sound engine}
|
||||
*/
|
||||
public SoundEngine getEngine()
|
||||
{
|
||||
return engine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Superclass for when a sound has started to play on an audio channel.
|
||||
*
|
||||
* <p>These events are fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}. </p>
|
||||
*
|
||||
* @see PlaySoundSourceEvent
|
||||
* @see PlayStreamingSourceEvent
|
||||
*/
|
||||
public static class SoundSourceEvent extends SoundEvent
|
||||
{
|
||||
private final SoundInstance sound;
|
||||
private final Channel channel;
|
||||
private final String name;
|
||||
|
||||
public SoundSourceEvent(SoundEngine manager, SoundInstance sound, Channel channel)
|
||||
/**
|
||||
* @hidden
|
||||
*/
|
||||
public SoundSourceEvent(SoundEngine engine, SoundInstance sound, Channel channel)
|
||||
{
|
||||
super(manager);
|
||||
super(engine);
|
||||
this.name = sound.getLocation().getPath();
|
||||
this.sound = sound;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the sound being played}
|
||||
*/
|
||||
public SoundInstance getSound()
|
||||
{
|
||||
return sound;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the audio channel on which the sound is playing on}
|
||||
*/
|
||||
public Channel getChannel()
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the name of the sound being played} This is equivalent to the path of the location of the original sound.
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
import net.minecraftforge.fml.event.IModBusEvent;
|
||||
|
||||
/**
|
||||
* Raised by the SoundManager.loadSoundSettings, this would be a good place for
|
||||
* adding your custom sounds to the SoundPool.
|
||||
*/
|
||||
public class SoundLoadEvent extends SoundEvent implements IModBusEvent
|
||||
{
|
||||
public SoundLoadEvent(SoundEngine manager)
|
||||
{
|
||||
super(manager);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.client.sounds.SoundEngine;
|
||||
|
||||
/**
|
||||
* This event is raised by the SoundManager when it does its first setup of the
|
||||
* SoundSystemConfig's codecs, use this function to add your own codecs.
|
||||
*/
|
||||
public class SoundSetupEvent extends SoundEvent
|
||||
{
|
||||
public SoundSetupEvent(SoundEngine manager)
|
||||
{
|
||||
super(manager);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
/**
|
||||
* Client-only events relating to sounds.
|
||||
*/
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
package net.minecraftforge.client.event.sound;
|
||||
|
||||
import net.minecraft.FieldsAreNonnullByDefault;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -7,14 +7,11 @@ package net.minecraftforge.client.extensions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.ItemBlockRenderTypes;
|
||||
@@ -27,7 +24,12 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link IForgeBakedModel}.
|
||||
*/
|
||||
public interface IForgeBakedModel
|
||||
{
|
||||
private BakedModel self()
|
||||
@@ -35,8 +37,8 @@ public interface IForgeBakedModel
|
||||
return (BakedModel) this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
default List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
|
||||
@NotNull
|
||||
default List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
|
||||
{
|
||||
return self().getQuads(state, side, rand);
|
||||
}
|
||||
@@ -57,12 +59,12 @@ public interface IForgeBakedModel
|
||||
return net.minecraftforge.client.ForgeHooksClient.handlePerspective(self(), cameraTransformType, poseStack);
|
||||
}
|
||||
|
||||
default @Nonnull IModelData getModelData(@Nonnull BlockAndTintGetter level, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData modelData)
|
||||
default @NotNull IModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull IModelData modelData)
|
||||
{
|
||||
return modelData;
|
||||
}
|
||||
|
||||
default TextureAtlasSprite getParticleIcon(@Nonnull IModelData data)
|
||||
default TextureAtlasSprite getParticleIcon(@NotNull IModelData data)
|
||||
{
|
||||
return self().getParticleIcon();
|
||||
}
|
||||
|
||||
@@ -5,18 +5,23 @@
|
||||
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.minecraftforge.client.settings.IKeyConflictContext;
|
||||
import net.minecraftforge.client.settings.KeyModifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link KeyMapping}.
|
||||
*/
|
||||
public interface IForgeKeyMapping
|
||||
{
|
||||
private KeyMapping self() { return (KeyMapping) this; }
|
||||
|
||||
@Nonnull InputConstants.Key getKey();
|
||||
private KeyMapping self()
|
||||
{
|
||||
return (KeyMapping) this;
|
||||
}
|
||||
|
||||
@NotNull InputConstants.Key getKey();
|
||||
|
||||
/**
|
||||
* Checks that the key conflict context and modifier are active, and that the keyCode matches this binding.
|
||||
@@ -25,7 +30,7 @@ public interface IForgeKeyMapping
|
||||
{
|
||||
return keyCode != InputConstants.UNKNOWN && keyCode.equals(getKey()) && getKeyConflictContext().isActive() && getKeyModifier().isActive(getKeyConflictContext());
|
||||
}
|
||||
|
||||
|
||||
default void setToDefault()
|
||||
{
|
||||
setKeyModifierAndCode(getDefaultKeyModifier(), self().getDefaultKey());
|
||||
|
||||
@@ -9,15 +9,29 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraftforge.client.ForgeHooksClient;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link IForgeMinecraft}.
|
||||
*/
|
||||
public interface IForgeMinecraft
|
||||
{
|
||||
private Minecraft self() { return (Minecraft)this; }
|
||||
private Minecraft self()
|
||||
{
|
||||
return (Minecraft) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes a screen as a new GUI layer.
|
||||
*
|
||||
* @param screen the new GUI layer
|
||||
*/
|
||||
default void pushGuiLayer(Screen screen)
|
||||
{
|
||||
ForgeHooksClient.pushGuiLayer(self(), screen);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pops a GUI layer from the screen.
|
||||
*/
|
||||
default void popGuiLayer()
|
||||
{
|
||||
ForgeHooksClient.popGuiLayer(self());
|
||||
|
||||
@@ -6,18 +6,27 @@
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import com.mojang.math.Transformation;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
|
||||
/**
|
||||
* An {@code IModelState} is a function from model part to a transformation that should be applied
|
||||
* when that part is baked, thus representing the current "state" of the model and its parts.
|
||||
* Extension interface for {@link ModelState}. An {@code ModelState} is a function from model part to a
|
||||
* transformation that should be applied when that part is baked, thus representing the current "state" of the model
|
||||
* and its parts.
|
||||
*/
|
||||
public interface IForgeModelState
|
||||
{
|
||||
private ModelState self()
|
||||
{
|
||||
return (ModelState) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param part Part of the model we are wanting to transform. An empty optional means
|
||||
* {@return A transformation to apply to the part} This may be an {@linkplain Transformation#isIdentity() identity
|
||||
* transformation} if there is no transformation to be applied. The coordinate system of the transform is determined
|
||||
* by the part type.
|
||||
*
|
||||
* @param part part of the model we are wanting to transform. An empty optional means
|
||||
* we want a transform for the entire model.
|
||||
* @return A transformation to apply to the part, if any. The coordinate system of the transform
|
||||
* is determined by the part type.
|
||||
*/
|
||||
default Transformation getPartTransformation(Object part)
|
||||
{
|
||||
|
||||
@@ -13,18 +13,32 @@ import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
import com.mojang.math.Vector4f;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link Transformation}.
|
||||
*/
|
||||
public interface IForgeTransformation
|
||||
{
|
||||
private Transformation self()
|
||||
{
|
||||
return (Transformation)this;
|
||||
return (Transformation) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return whether this transformation is the identity transformation}
|
||||
*
|
||||
* @see Transformation#identity()
|
||||
*/
|
||||
default boolean isIdentity()
|
||||
{
|
||||
return self().equals(Transformation.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Pushes and applies this transformation to the pose stack. The effects of this method can be reversed by a
|
||||
* corresponding {@link PoseStack#popPose()}.
|
||||
*
|
||||
* @param stack the pose stack to modify
|
||||
*/
|
||||
default void push(PoseStack stack)
|
||||
{
|
||||
stack.pushPose();
|
||||
@@ -41,24 +55,45 @@ public interface IForgeTransformation
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the position according to this transformation.
|
||||
*
|
||||
* @param position the position to transform
|
||||
*/
|
||||
default void transformPosition(Vector4f position)
|
||||
{
|
||||
position.transform(self().getMatrix());
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the normal according to this transformation and normalizes it.
|
||||
*
|
||||
* @param normal the normal to transform
|
||||
*/
|
||||
default void transformNormal(Vector3f normal)
|
||||
{
|
||||
normal.transform(self().getNormalMatrix());
|
||||
normal.normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rotates the direction according to this transformation and returns the nearest {@code Direction} to the
|
||||
* resulting direction.
|
||||
*
|
||||
* @param facing the direction to transform
|
||||
* @return the {@code Direction} value nearest to the resulting transformed direction
|
||||
* @see Direction#rotate(Matrix4f, Direction)
|
||||
*/
|
||||
default Direction rotateTransform(Direction facing)
|
||||
{
|
||||
return Direction.rotate(self().getMatrix(), facing);
|
||||
}
|
||||
|
||||
/**
|
||||
* convert transformation from assuming center-block system to opposing-corner-block system
|
||||
* Converts and returns a new transformation based on this transformation from assuming a center-block system to an
|
||||
* opposing-corner-block system.
|
||||
*
|
||||
* @return a new transformation using the opposing-corner-block system
|
||||
*/
|
||||
default Transformation blockCenterToCorner()
|
||||
{
|
||||
@@ -66,7 +101,10 @@ public interface IForgeTransformation
|
||||
}
|
||||
|
||||
/**
|
||||
* convert transformation from assuming opposing-corner-block system to center-block system
|
||||
* Converts and returns a new transformation based on this transformation from assuming an opposing-corner-block
|
||||
* system to a center-block system.
|
||||
*
|
||||
* @return a new transformation using the center-block system
|
||||
*/
|
||||
default Transformation blockCornerToCenter()
|
||||
{
|
||||
@@ -74,11 +112,14 @@ public interface IForgeTransformation
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply this transformation to a different origin.
|
||||
* Can be used for switching between coordinate systems.
|
||||
* Parameter is relative to the current origin.
|
||||
* Returns a new transformation with a changed origin by applying the given parameter (which is relative to the
|
||||
* current origin). This can be used for switching between coordinate systems.
|
||||
*
|
||||
* @param origin the new origin as relative to the current origin
|
||||
* @return a new transformation with a changed origin
|
||||
*/
|
||||
default Transformation applyOrigin(Vector3f origin) {
|
||||
default Transformation applyOrigin(Vector3f origin)
|
||||
{
|
||||
Transformation transform = self();
|
||||
if (transform.isIdentity()) return Transformation.identity();
|
||||
|
||||
|
||||
@@ -24,8 +24,16 @@ import com.mojang.math.Vector3f;
|
||||
import com.mojang.math.Vector4f;
|
||||
import net.minecraft.core.Vec3i;
|
||||
|
||||
/**
|
||||
* Extension interface for {@link VertexConsumer}.
|
||||
*/
|
||||
public interface IForgeVertexConsumer
|
||||
{
|
||||
private VertexConsumer self()
|
||||
{
|
||||
return (VertexConsumer) this;
|
||||
}
|
||||
|
||||
// Copy of putBulkData, but enables tinting and per-vertex alpha
|
||||
default void putBulkData(PoseStack.Pose poseStack, BakedQuad bakedQuad, float red, float green, float blue, int packedLight, int packedOverlay, boolean readExistingColor) {
|
||||
putBulkData(poseStack, bakedQuad, red, green, blue, 1.0f, packedLight, packedOverlay, readExistingColor);
|
||||
@@ -87,7 +95,7 @@ public interface IForgeVertexConsumer
|
||||
Vector4f pos = new Vector4f(f, f1, f2, 1.0F);
|
||||
pos.transform(matrix4f);
|
||||
applyBakedNormals(normal, bytebuffer, pose.normal());
|
||||
((VertexConsumer)this).vertex(pos.x(), pos.y(), pos.z(), cr, cg, cb, ca, f9, f10, packedOverlay, lightmapCoord, normal.x(), normal.y(), normal.z());
|
||||
self().vertex(pos.x(), pos.y(), pos.z(), cr, cg, cb, ca, f9, f10, packedOverlay, lightmapCoord, normal.x(), normal.y(), normal.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
/**
|
||||
* Extension interfaces for {@link net.minecraftforge.api.distmarker.Dist#CLIENT client}-only classes.
|
||||
*
|
||||
* <p>Extension interfaces allow the convenient addition of methods to the target class, as the target class is patched
|
||||
* to implement the interface. Because of this, these interfaces must only be implemented by the target classes, and must
|
||||
* not be implemented manually by mods.</p>
|
||||
*
|
||||
* <p>These interfaces hold at least one method: the {@code self()} method which casts the object into the type of the
|
||||
* targeted class, to allow methods in the extension interface to reference methods from the target class. Additional
|
||||
* methods are usually {@code default} with an implementation in the interface itself, but methods may be implemented
|
||||
* in the target class instead if it requires access to (patched-in or original) fields in the instance.</p>
|
||||
*/
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
package net.minecraftforge.client.extensions;
|
||||
|
||||
import net.minecraft.FieldsAreNonnullByDefault;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -45,12 +45,11 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class ForgeIngameGui extends Gui
|
||||
{
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
@@ -319,7 +318,7 @@ public class ForgeIngameGui extends Gui
|
||||
|
||||
public ForgeIngameGui(Minecraft mc)
|
||||
{
|
||||
super(mc);
|
||||
super(mc, mc.getItemRenderer());
|
||||
debugOverlay = new ForgeDebugScreenOverlay(mc);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -11,11 +11,9 @@ import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.screens.ErrorScreen;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraftforge.common.ForgeI18n;
|
||||
import net.minecraftforge.fml.LoadingFailedException;
|
||||
@@ -46,7 +44,7 @@ public class LoadingErrorScreen extends ErrorScreen {
|
||||
|
||||
public LoadingErrorScreen(LoadingFailedException loadingException, List<ModLoadingWarning> warnings, final File dumpedLocation)
|
||||
{
|
||||
super(new TextComponent("Loading Error"), null);
|
||||
super(Component.literal("Loading Error"), null);
|
||||
this.modLoadWarnings = warnings;
|
||||
this.modLoadErrors = loadingException == null ? Collections.emptyList() : loadingException.getErrors();
|
||||
this.modsDir = FMLPaths.MODSDIR.get();
|
||||
@@ -60,18 +58,18 @@ public class LoadingErrorScreen extends ErrorScreen {
|
||||
super.init();
|
||||
this.clearWidgets();
|
||||
|
||||
this.errorHeader = new TextComponent(ChatFormatting.RED + ForgeI18n.parseMessage("fml.loadingerrorscreen.errorheader", this.modLoadErrors.size()) + ChatFormatting.RESET);
|
||||
this.warningHeader = new TextComponent(ChatFormatting.YELLOW + ForgeI18n.parseMessage("fml.loadingerrorscreen.warningheader", this.modLoadErrors.size()) + ChatFormatting.RESET);
|
||||
this.errorHeader = Component.literal(ChatFormatting.RED + ForgeI18n.parseMessage("fml.loadingerrorscreen.errorheader", this.modLoadErrors.size()) + ChatFormatting.RESET);
|
||||
this.warningHeader = Component.literal(ChatFormatting.YELLOW + ForgeI18n.parseMessage("fml.loadingerrorscreen.warningheader", this.modLoadErrors.size()) + ChatFormatting.RESET);
|
||||
|
||||
int yOffset = 46;
|
||||
this.addRenderableWidget(new ExtendedButton(50, this.height - yOffset, this.width / 2 - 55, 20, new TextComponent(ForgeI18n.parseMessage("fml.button.open.mods.folder")), b -> Util.getPlatform().openFile(modsDir.toFile())));
|
||||
this.addRenderableWidget(new ExtendedButton(this.width / 2 + 5, this.height - yOffset, this.width / 2 - 55, 20, new TextComponent(ForgeI18n.parseMessage("fml.button.open.file", logFile.getFileName())), b -> Util.getPlatform().openFile(logFile.toFile())));
|
||||
this.addRenderableWidget(new ExtendedButton(50, this.height - yOffset, this.width / 2 - 55, 20, Component.literal(ForgeI18n.parseMessage("fml.button.open.mods.folder")), b -> Util.getPlatform().openFile(modsDir.toFile())));
|
||||
this.addRenderableWidget(new ExtendedButton(this.width / 2 + 5, this.height - yOffset, this.width / 2 - 55, 20, Component.literal(ForgeI18n.parseMessage("fml.button.open.file", logFile.getFileName())), b -> Util.getPlatform().openFile(logFile.toFile())));
|
||||
if (this.modLoadErrors.isEmpty()) {
|
||||
this.addRenderableWidget(new ExtendedButton(this.width / 4, this.height - 24, this.width / 2, 20, new TextComponent(ForgeI18n.parseMessage("fml.button.continue.launch")), b -> {
|
||||
this.addRenderableWidget(new ExtendedButton(this.width / 4, this.height - 24, this.width / 2, 20, Component.literal(ForgeI18n.parseMessage("fml.button.continue.launch")), b -> {
|
||||
this.minecraft.setScreen(null);
|
||||
}));
|
||||
} else {
|
||||
this.addRenderableWidget(new ExtendedButton(this.width / 4, this.height - 24, this.width / 2, 20, new TextComponent(ForgeI18n.parseMessage("fml.button.open.file", dumpedLocation.getFileName())), b -> Util.getPlatform().openFile(dumpedLocation.toFile())));
|
||||
this.addRenderableWidget(new ExtendedButton(this.width / 4, this.height - 24, this.width / 2, 20, Component.literal(ForgeI18n.parseMessage("fml.button.open.file", dumpedLocation.getFileName())), b -> Util.getPlatform().openFile(dumpedLocation.toFile())));
|
||||
}
|
||||
|
||||
this.entryList = new LoadingEntryList(this, this.modLoadErrors, this.modLoadWarnings);
|
||||
@@ -100,13 +98,13 @@ public class LoadingErrorScreen extends ErrorScreen {
|
||||
boolean both = !errors.isEmpty() && !warnings.isEmpty();
|
||||
if (both)
|
||||
addEntry(new LoadingMessageEntry(parent.errorHeader, true));
|
||||
errors.forEach(e->addEntry(new LoadingMessageEntry(new TextComponent(e.formatToString()))));
|
||||
errors.forEach(e->addEntry(new LoadingMessageEntry(Component.literal(e.formatToString()))));
|
||||
if (both) {
|
||||
int maxChars = (this.width - 10) / parent.minecraft.font.width("-");
|
||||
addEntry(new LoadingMessageEntry(new TextComponent("\n" + Strings.repeat("-", maxChars) + "\n")));
|
||||
addEntry(new LoadingMessageEntry(Component.literal("\n" + Strings.repeat("-", maxChars) + "\n")));
|
||||
addEntry(new LoadingMessageEntry(parent.warningHeader, true));
|
||||
}
|
||||
warnings.forEach(w->addEntry(new LoadingMessageEntry(new TextComponent(w.formatToString()))));
|
||||
warnings.forEach(w->addEntry(new LoadingMessageEntry(Component.literal(w.formatToString()))));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -136,7 +134,7 @@ public class LoadingErrorScreen extends ErrorScreen {
|
||||
|
||||
@Override
|
||||
public Component getNarration() {
|
||||
return new TranslatableComponent("narrator.select", message);
|
||||
return Component.translatable("narrator.select", message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -57,7 +57,6 @@ import net.minecraftforge.forgespi.language.IModInfo;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
public class ModListScreen extends Screen
|
||||
{
|
||||
@@ -79,7 +78,7 @@ public class ModListScreen extends Screen
|
||||
}
|
||||
|
||||
Component getButtonText() {
|
||||
return new TranslatableComponent("fml.menu.mods." + StringUtils.toLowerCase(name()));
|
||||
return Component.translatable("fml.menu.mods." + StringUtils.toLowerCase(name()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +105,7 @@ public class ModListScreen extends Screen
|
||||
|
||||
public ModListScreen(Screen parentScreen)
|
||||
{
|
||||
super(new TranslatableComponent("fml.menu.mods.title"));
|
||||
super(Component.translatable("fml.menu.mods.title"));
|
||||
this.parentScreen = parentScreen;
|
||||
this.mods = Collections.unmodifiableList(ModList.get().getMods());
|
||||
this.unsortedMods = Collections.unmodifiableList(this.mods);
|
||||
@@ -263,12 +262,12 @@ public class ModListScreen extends Screen
|
||||
int y = this.height - 20 - PADDING;
|
||||
int fullButtonHeight = PADDING + 20 + PADDING;
|
||||
|
||||
doneButton = new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, new TranslatableComponent("gui.done"), b -> ModListScreen.this.onClose());
|
||||
openModsFolderButton = new Button(6, y, this.listWidth, 20, new TranslatableComponent("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile()));
|
||||
doneButton = new Button(((listWidth + PADDING + this.width - doneButtonWidth) / 2), y, doneButtonWidth, 20, Component.translatable("gui.done"), b -> ModListScreen.this.onClose());
|
||||
openModsFolderButton = new Button(6, y, this.listWidth, 20, Component.translatable("fml.menu.mods.openmodsfolder"), b -> Util.getPlatform().openFile(FMLPaths.MODSDIR.get().toFile()));
|
||||
y -= 20 + PADDING;
|
||||
configButton = new Button(6, y, this.listWidth, 20, new TranslatableComponent("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig());
|
||||
configButton = new Button(6, y, this.listWidth, 20, Component.translatable("fml.menu.mods.config"), b -> ModListScreen.this.displayModConfig());
|
||||
y -= 14 + PADDING;
|
||||
search = new EditBox(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, new TranslatableComponent("fml.menu.mods.search"));
|
||||
search = new EditBox(getFontRenderer(), PADDING + 1, y, listWidth - 2, 14, Component.translatable("fml.menu.mods.search"));
|
||||
|
||||
this.modList = new ModListWidget(this, listWidth, fullButtonHeight, search.y - getFontRenderer().lineHeight - PADDING);
|
||||
this.modList.setLeftPos(6);
|
||||
@@ -366,7 +365,7 @@ public class ModListScreen extends Screen
|
||||
if (this.modInfo != null)
|
||||
this.modInfo.render(poseStack, mouseX, mouseY, partialTick);
|
||||
|
||||
Component text = new TranslatableComponent("fml.menu.mods.search");
|
||||
Component text = Component.translatable("fml.menu.mods.search");
|
||||
int x = modList.getLeft() + ((modList.getRight() - modList.getLeft()) / 2) - (getFontRenderer().width(text) / 2);
|
||||
this.search.render(poseStack, mouseX , mouseY, partialTick);
|
||||
super.render(poseStack, mouseX, mouseY, partialTick);
|
||||
|
||||
@@ -47,8 +47,6 @@ import net.minecraft.network.chat.HoverEvent.Action;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.FormattedCharSequence;
|
||||
import net.minecraftforge.common.ForgeI18n;
|
||||
@@ -105,9 +103,9 @@ public class ModMismatchDisconnectedScreen extends Screen
|
||||
this.addRenderableWidget(new MismatchInfoPanel(minecraft, listWidth, listHeight, (this.height - this.listHeight) / 2, listLeft));
|
||||
|
||||
int buttonWidth = Math.min(210, this.width / 2 - 20);
|
||||
this.addRenderableWidget(new Button(Math.max(this.width / 4 - buttonWidth / 2, listLeft), upperButtonHeight, buttonWidth, 20, new TextComponent(ForgeI18n.parseMessage("fml.button.open.file", logFile.getFileName())), button -> Util.getPlatform().openFile(logFile.toFile())));
|
||||
this.addRenderableWidget(new Button(Math.min(this.width * 3 / 4 - buttonWidth / 2, listLeft + listWidth - buttonWidth), upperButtonHeight, buttonWidth, 20, new TextComponent(ForgeI18n.parseMessage("fml.button.open.mods.folder")), button -> Util.getPlatform().openFile(modsDir.toFile())));
|
||||
this.addRenderableWidget(new Button((this.width - buttonWidth) / 2, lowerButtonHeight, buttonWidth, 20, new TranslatableComponent("gui.toMenu"), button -> this.minecraft.setScreen(this.parent)));
|
||||
this.addRenderableWidget(new Button(Math.max(this.width / 4 - buttonWidth / 2, listLeft), upperButtonHeight, buttonWidth, 20, Component.literal(ForgeI18n.parseMessage("fml.button.open.file", logFile.getFileName())), button -> Util.getPlatform().openFile(logFile.toFile())));
|
||||
this.addRenderableWidget(new Button(Math.min(this.width * 3 / 4 - buttonWidth / 2, listLeft + listWidth - buttonWidth), upperButtonHeight, buttonWidth, 20, Component.literal(ForgeI18n.parseMessage("fml.button.open.mods.folder")), button -> Util.getPlatform().openFile(modsDir.toFile())));
|
||||
this.addRenderableWidget(new Button((this.width - buttonWidth) / 2, lowerButtonHeight, buttonWidth, 20, Component.translatable("gui.toMenu"), button -> this.minecraft.setScreen(this.parent)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -138,36 +136,36 @@ public class ModMismatchDisconnectedScreen extends Screen
|
||||
if (!missingModData.isEmpty())
|
||||
{
|
||||
//The header of the section, colored in gray
|
||||
rawTable.add(Pair.of(new TextComponent(ForgeI18n.parseMessage(mismatchedDataFromServer ? "fml.modmismatchscreen.missingmods.server" : "fml.modmismatchscreen.missingmods.client")).withStyle(ChatFormatting.GRAY), null));
|
||||
rawTable.add(Pair.of(Component.literal(ForgeI18n.parseMessage(mismatchedDataFromServer ? "fml.modmismatchscreen.missingmods.server" : "fml.modmismatchscreen.missingmods.client")).withStyle(ChatFormatting.GRAY), null));
|
||||
//This table section contains the mod name and mod version of each mod that has a missing remote counterpart (if the mod is missing on the server, the client mod version is displayed, and vice versa)
|
||||
rawTable.add(Pair.of(new TextComponent(ForgeI18n.parseMessage("fml.modmismatchscreen.table.modname")).withStyle(ChatFormatting.UNDERLINE), Pair.of("", ForgeI18n.parseMessage(mismatchedDataFromServer ? "fml.modmismatchscreen.table.youhave" : "fml.modmismatchscreen.table.youneed"))));
|
||||
rawTable.add(Pair.of(Component.literal(ForgeI18n.parseMessage("fml.modmismatchscreen.table.modname")).withStyle(ChatFormatting.UNDERLINE), Pair.of("", ForgeI18n.parseMessage(mismatchedDataFromServer ? "fml.modmismatchscreen.table.youhave" : "fml.modmismatchscreen.table.youneed"))));
|
||||
int i = 0;
|
||||
for (ResourceLocation mod : missingModData) {
|
||||
rawTable.add(Pair.of(toModNameComponent(mod, presentModData.get(mod).getLeft(), i), Pair.of("", presentModData.getOrDefault(mod, Pair.of("", "")).getRight())));
|
||||
if (++i >= 10) {
|
||||
//If too many missing mod entries are present, append a line referencing how to see the full list and stop rendering any more entries
|
||||
rawTable.add(Pair.of(new TextComponent(ForgeI18n.parseMessage("fml.modmismatchscreen.additional", missingModData.size() - i)).withStyle(ChatFormatting.ITALIC), Pair.of("", "")));
|
||||
rawTable.add(Pair.of(Component.literal(ForgeI18n.parseMessage("fml.modmismatchscreen.additional", missingModData.size() - i)).withStyle(ChatFormatting.ITALIC), Pair.of("", "")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
rawTable.add(Pair.of(new TextComponent(" "), null)); //padding
|
||||
rawTable.add(Pair.of(Component.literal(" "), null)); //padding
|
||||
}
|
||||
if (!mismatchedModData.isEmpty())
|
||||
{
|
||||
//The header of the table section, colored in gray
|
||||
rawTable.add(Pair.of(new TextComponent(ForgeI18n.parseMessage("fml.modmismatchscreen.mismatchedmods")).withStyle(ChatFormatting.GRAY), null));
|
||||
rawTable.add(Pair.of(Component.literal(ForgeI18n.parseMessage("fml.modmismatchscreen.mismatchedmods")).withStyle(ChatFormatting.GRAY), null));
|
||||
//This table section contains the mod name and both mod versions of each mod that has a mismatching client and server version
|
||||
rawTable.add(Pair.of(new TextComponent(ForgeI18n.parseMessage("fml.modmismatchscreen.table.modname")).withStyle(ChatFormatting.UNDERLINE), Pair.of(ForgeI18n.parseMessage(mismatchedDataFromServer ? "fml.modmismatchscreen.table.youhave" : "fml.modmismatchscreen.table.serverhas"), ForgeI18n.parseMessage(mismatchedDataFromServer ? "fml.modmismatchscreen.table.serverhas" : "fml.modmismatchscreen.table.youhave"))));
|
||||
rawTable.add(Pair.of(Component.literal(ForgeI18n.parseMessage("fml.modmismatchscreen.table.modname")).withStyle(ChatFormatting.UNDERLINE), Pair.of(ForgeI18n.parseMessage(mismatchedDataFromServer ? "fml.modmismatchscreen.table.youhave" : "fml.modmismatchscreen.table.serverhas"), ForgeI18n.parseMessage(mismatchedDataFromServer ? "fml.modmismatchscreen.table.serverhas" : "fml.modmismatchscreen.table.youhave"))));
|
||||
int i = 0;
|
||||
for (Map.Entry<ResourceLocation, String> modData : mismatchedModData.entrySet()) {
|
||||
rawTable.add(Pair.of(toModNameComponent(modData.getKey(), presentModData.get(modData.getKey()).getLeft(), i), Pair.of(presentModData.getOrDefault(modData.getKey(), Pair.of("", "")).getRight(), modData.getValue())));
|
||||
if (++i >= 10) {
|
||||
//If too many mismatched mod entries are present, append a line referencing how to see the full list and stop rendering any more entries
|
||||
rawTable.add(Pair.of(new TextComponent(ForgeI18n.parseMessage("fml.modmismatchscreen.additional", mismatchedModData.size() - i)).withStyle(ChatFormatting.ITALIC), Pair.of("", "")));
|
||||
rawTable.add(Pair.of(Component.literal(ForgeI18n.parseMessage("fml.modmismatchscreen.additional", mismatchedModData.size() - i)).withStyle(ChatFormatting.ITALIC), Pair.of("", "")));
|
||||
break;
|
||||
}
|
||||
}
|
||||
rawTable.add(Pair.of(new TextComponent(" "), null)); //padding
|
||||
rawTable.add(Pair.of(Component.literal(" "), null)); //padding
|
||||
}
|
||||
|
||||
this.lineTable = rawTable.stream().flatMap(p -> splitLineToWidth(p.getKey(), p.getValue()).stream()).collect(Collectors.toList());
|
||||
@@ -187,8 +185,8 @@ public class ModMismatchDisconnectedScreen extends Screen
|
||||
int versionColumns = versions == null ? 0 : (versions.getLeft().isEmpty() ? (versions.getRight().isEmpty() ? 0 : 1) : 2);
|
||||
int adaptedNameWidth = nameWidth + versionWidth * (2 - versionColumns) - 4; //the name width may be expanded when the version column string is missing
|
||||
List<FormattedCharSequence> nameLines = font.split(name, adaptedNameWidth);
|
||||
List<FormattedCharSequence> clientVersionLines = font.split(new TextComponent(versions != null ? versions.getLeft() : "").setStyle(style), versionWidth - 4);
|
||||
List<FormattedCharSequence> serverVersionLines = font.split(new TextComponent(versions != null ? versions.getRight() : "").setStyle(style), versionWidth - 4);
|
||||
List<FormattedCharSequence> clientVersionLines = font.split(Component.literal(versions != null ? versions.getLeft() : "").setStyle(style), versionWidth - 4);
|
||||
List<FormattedCharSequence> serverVersionLines = font.split(Component.literal(versions != null ? versions.getRight() : "").setStyle(style), versionWidth - 4);
|
||||
List<Pair<FormattedCharSequence, Pair<FormattedCharSequence, FormattedCharSequence>>> splitLines = new ArrayList<>();
|
||||
int rowsOccupied = Math.max(nameLines.size(), Math.max(clientVersionLines.size(), serverVersionLines.size()));
|
||||
for (int i = 0; i < rowsOccupied; i++) {
|
||||
@@ -209,8 +207,8 @@ public class ModMismatchDisconnectedScreen extends Screen
|
||||
{
|
||||
String modId = id.getNamespace();
|
||||
String tooltipId = id.getPath().isEmpty() ? id.getNamespace() : id.toString();
|
||||
return new TextComponent(modName).withStyle(color % 2 == 0 ? ChatFormatting.GOLD : ChatFormatting.YELLOW)
|
||||
.withStyle(s -> s.withHoverEvent(new HoverEvent(Action.SHOW_TEXT, new TextComponent(tooltipId + (!presentModUrls.getOrDefault(modId, "").isEmpty() ? "\n" + ForgeI18n.parseMessage("fml.modmismatchscreen.homepage") : "")))))
|
||||
return Component.literal(modName).withStyle(color % 2 == 0 ? ChatFormatting.GOLD : ChatFormatting.YELLOW)
|
||||
.withStyle(s -> s.withHoverEvent(new HoverEvent(Action.SHOW_TEXT, Component.literal(tooltipId + (!presentModUrls.getOrDefault(modId, "").isEmpty() ? "\n" + ForgeI18n.parseMessage("fml.modmismatchscreen.homepage") : "")))))
|
||||
.withStyle(s -> s.withClickEvent(!presentModUrls.getOrDefault(modId, "").isEmpty() ? new ClickEvent(ClickEvent.Action.OPEN_URL, presentModUrls.get(modId)) : null));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.screens.TitleScreen;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.fml.loading.FMLConfig;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
@@ -32,7 +32,7 @@ public class NotificationModUpdateScreen extends Screen
|
||||
|
||||
public NotificationModUpdateScreen(Button modButton)
|
||||
{
|
||||
super(new TranslatableComponent("forge.menu.updatescreen.title"));
|
||||
super(Component.translatable("forge.menu.updatescreen.title"));
|
||||
this.modButton = modButton;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ package net.minecraftforge.client.gui;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -23,7 +23,7 @@ public class OverlayRegistry
|
||||
* @param overlay An instance, lambda or method reference for the logic used in rendering the overlay.
|
||||
* @return The same object passed into the {@code overlay} parameter.
|
||||
*/
|
||||
public static synchronized IIngameOverlay registerOverlayBottom(@Nonnull String displayName, @Nonnull IIngameOverlay overlay)
|
||||
public static synchronized IIngameOverlay registerOverlayBottom(@NotNull String displayName, @NotNull IIngameOverlay overlay)
|
||||
{
|
||||
return registerOverlay(-1, null, displayName, overlay);
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class OverlayRegistry
|
||||
* @param overlay An instance, lambda or method reference for the logic used in rendering the overlay.
|
||||
* @return The same object passed into the {@code overlay} parameter.
|
||||
*/
|
||||
public static synchronized IIngameOverlay registerOverlayBelow(@Nonnull IIngameOverlay other, @Nonnull String displayName, @Nonnull IIngameOverlay overlay)
|
||||
public static synchronized IIngameOverlay registerOverlayBelow(@NotNull IIngameOverlay other, @NotNull String displayName, @NotNull IIngameOverlay overlay)
|
||||
{
|
||||
return registerOverlay(-1, other, displayName, overlay);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class OverlayRegistry
|
||||
* @param overlay An instance, lambda or method reference for the logic used in rendering the overlay.
|
||||
* @return The same object passed into the {@code overlay} parameter.
|
||||
*/
|
||||
public static synchronized IIngameOverlay registerOverlayAbove(@Nonnull IIngameOverlay other, @Nonnull String displayName, @Nonnull IIngameOverlay overlay)
|
||||
public static synchronized IIngameOverlay registerOverlayAbove(@NotNull IIngameOverlay other, @NotNull String displayName, @NotNull IIngameOverlay overlay)
|
||||
{
|
||||
return registerOverlay(1, other, displayName, overlay);
|
||||
}
|
||||
@@ -61,12 +61,12 @@ public class OverlayRegistry
|
||||
* @param overlay An instance, lambda or method reference for the logic used in rendering the overlay.
|
||||
* @return The same object passed into the {@code overlay} parameter.
|
||||
*/
|
||||
public static synchronized IIngameOverlay registerOverlayTop(@Nonnull String displayName, @Nonnull IIngameOverlay overlay)
|
||||
public static synchronized IIngameOverlay registerOverlayTop(@NotNull String displayName, @NotNull IIngameOverlay overlay)
|
||||
{
|
||||
return registerOverlay(1, null, displayName, overlay);
|
||||
}
|
||||
|
||||
private static IIngameOverlay registerOverlay(int sort, @Nullable IIngameOverlay other, @Nonnull String displayName, @Nonnull IIngameOverlay overlay)
|
||||
private static IIngameOverlay registerOverlay(int sort, @Nullable IIngameOverlay other, @NotNull String displayName, @NotNull IIngameOverlay overlay)
|
||||
{
|
||||
OverlayEntry entry = overlays.get(overlay);
|
||||
|
||||
@@ -108,7 +108,7 @@ public class OverlayRegistry
|
||||
* @param overlay The overlay object to enable or disable
|
||||
* @param enable The new state
|
||||
*/
|
||||
public static synchronized void enableOverlay(@Nonnull IIngameOverlay overlay, boolean enable)
|
||||
public static synchronized void enableOverlay(@NotNull IIngameOverlay overlay, boolean enable)
|
||||
{
|
||||
OverlayEntry entry = overlays.get(overlay);
|
||||
if (entry != null)
|
||||
@@ -123,7 +123,7 @@ public class OverlayRegistry
|
||||
* @return The registration entry for this overlay.
|
||||
*/
|
||||
@Nullable
|
||||
public static synchronized OverlayEntry getEntry(@Nonnull IIngameOverlay overlay)
|
||||
public static synchronized OverlayEntry getEntry(@NotNull IIngameOverlay overlay)
|
||||
{
|
||||
return overlays.get(overlay);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.client.gui.GuiUtils;
|
||||
|
||||
/**
|
||||
@@ -46,7 +45,7 @@ public class ExtendedButton extends Button
|
||||
|
||||
if (strWidth > width - 6 && strWidth > ellipsisWidth)
|
||||
//TODO, srg names make it hard to figure out how to append to an ITextProperties from this trim operation, wraping this in StringTextComponent is kinda dirty.
|
||||
buttonText = new TextComponent(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString() + "...");
|
||||
buttonText = Component.literal(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString() + "...");
|
||||
|
||||
drawCenteredString(poseStack, mc.font, buttonText, this.x + this.width / 2, this.y + (this.height - 8) / 2, getFGColor());
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.client.gui.widget;
|
||||
|
||||
import net.minecraft.client.gui.components.AbstractSliderButton;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.util.Mth;
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
@@ -47,7 +46,7 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
*/
|
||||
public ForgeSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString)
|
||||
{
|
||||
super(x, y, width, height, TextComponent.EMPTY, 0D);
|
||||
super(x, y, width, height, Component.empty(), 0D);
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
this.minValue = minValue;
|
||||
@@ -207,11 +206,11 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
{
|
||||
if (this.drawString)
|
||||
{
|
||||
this.setMessage(new TextComponent("").append(prefix).append(this.getValueString()).append(suffix));
|
||||
this.setMessage(Component.literal("").append(prefix).append(this.getValueString()).append(suffix));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setMessage(TextComponent.EMPTY);
|
||||
this.setMessage(Component.empty());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,12 +9,10 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiComponent;
|
||||
import net.minecraft.client.gui.components.ObjectSelectionList;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.FormattedText;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.client.gui.ModListScreen;
|
||||
import net.minecraftforge.versions.forge.ForgeVersion;
|
||||
import net.minecraftforge.common.util.MavenVersionStringHelper;
|
||||
@@ -73,14 +71,14 @@ public class ModListWidget extends ObjectSelectionList<ModListWidget.ModEntry>
|
||||
|
||||
@Override
|
||||
public Component getNarration() {
|
||||
return new TranslatableComponent("narrator.select", modInfo.getDisplayName());
|
||||
return Component.translatable("narrator.select", modInfo.getDisplayName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(PoseStack poseStack, int entryIdx, int top, int left, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean p_194999_5_, float partialTick)
|
||||
{
|
||||
Component name = new TextComponent(stripControlCodes(modInfo.getDisplayName()));
|
||||
Component version = new TextComponent(stripControlCodes(MavenVersionStringHelper.artifactVersionToString(modInfo.getVersion())));
|
||||
Component name = Component.literal(stripControlCodes(modInfo.getDisplayName()));
|
||||
Component version = Component.literal(stripControlCodes(MavenVersionStringHelper.artifactVersionToString(modInfo.getVersion())));
|
||||
VersionChecker.CheckResult vercheck = VersionChecker.getResult(modInfo);
|
||||
Font font = this.parent.getFontRenderer();
|
||||
font.draw(poseStack, Language.getInstance().getVisualOrder(FormattedText.composite(font.substrByWidth(name, listWidth))), left + 3, top + 2, 0xFFFFFF);
|
||||
|
||||
@@ -1,207 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.gui.widget;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.client.gui.GuiUtils;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* This class is blatantly stolen from iChunUtils with permission.
|
||||
*
|
||||
* @deprecated This class has a few issues,
|
||||
* mainly <a href="https://github.com/MinecraftForge/MinecraftForge/issues/8485">MinecraftForge/MinecraftForge#8485</a>.
|
||||
* Use {@link ForgeSlider} instead.
|
||||
*
|
||||
* @author iChun
|
||||
*/
|
||||
@Deprecated(since = "1.18.2", forRemoval = true)
|
||||
public class Slider extends ExtendedButton
|
||||
{
|
||||
/** The value of this slider control. */
|
||||
public double sliderValue = 1.0F;
|
||||
|
||||
public Component dispString;
|
||||
|
||||
/** Is this slider control being dragged. */
|
||||
public boolean dragging = false;
|
||||
public boolean showDecimal = true;
|
||||
|
||||
public double minValue = 0.0D;
|
||||
public double maxValue = 5.0D;
|
||||
public int precision = 1;
|
||||
|
||||
@Nullable
|
||||
public ISlider parent = null;
|
||||
|
||||
public Component suffix;
|
||||
|
||||
public boolean drawString = true;
|
||||
|
||||
public Slider(int xPos, int yPos, int width, int height, Component prefix, Component suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, OnPress handler)
|
||||
{
|
||||
this(xPos, yPos, width, height, prefix, suf, minVal, maxVal, currentVal, showDec, drawStr, handler, null);
|
||||
}
|
||||
|
||||
public Slider(int xPos, int yPos, int width, int height, Component prefix, Component suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, OnPress handler, @Nullable ISlider par)
|
||||
{
|
||||
super(xPos, yPos, width, height, prefix, handler);
|
||||
minValue = minVal;
|
||||
maxValue = maxVal;
|
||||
sliderValue = (currentVal - minValue) / (maxValue - minValue);
|
||||
dispString = prefix;
|
||||
parent = par;
|
||||
suffix = suf;
|
||||
showDecimal = showDec;
|
||||
String val;
|
||||
|
||||
if (showDecimal)
|
||||
{
|
||||
val = Double.toString(sliderValue * (maxValue - minValue) + minValue);
|
||||
precision = Math.min(val.substring(val.indexOf(".") + 1).length(), 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = Integer.toString((int)Math.round(sliderValue * (maxValue - minValue) + minValue));
|
||||
precision = 0;
|
||||
}
|
||||
|
||||
setMessage(new TextComponent("").append(dispString).append(val).append(suffix));
|
||||
|
||||
drawString = drawStr;
|
||||
if(!drawString)
|
||||
setMessage(new TextComponent(""));
|
||||
}
|
||||
|
||||
public Slider(int xPos, int yPos, Component displayStr, double minVal, double maxVal, double currentVal, OnPress handler, ISlider par)
|
||||
{
|
||||
this(xPos, yPos, 150, 20, displayStr, new TextComponent(""), minVal, maxVal, currentVal, true, true, handler, par);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 0 if the button is disabled, 1 if the mouse is NOT hovering over this button and 2 if it IS hovering over
|
||||
* this button.
|
||||
*/
|
||||
@Override
|
||||
public int getYImage(boolean par1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the mouse button is dragged. Equivalent of MouseListener.mouseDragged(MouseEvent e).
|
||||
*/
|
||||
@Override
|
||||
protected void renderBg(PoseStack poseStack, Minecraft minecraft, int par2, int par3)
|
||||
{
|
||||
if (this.visible)
|
||||
{
|
||||
if (this.dragging)
|
||||
{
|
||||
this.sliderValue = (par2 - (this.x + 4)) / (float)(this.width - 8);
|
||||
updateSlider();
|
||||
}
|
||||
|
||||
GuiUtils.drawContinuousTexturedBox(poseStack, WIDGETS_LOCATION, this.x + (int)(this.sliderValue * (float)(this.width - 8)), this.y, 0, 66, 8, this.height, 200, 20, 2, 3, 2, 2, this.getBlitOffset());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent
|
||||
* e).
|
||||
*/
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY)
|
||||
{
|
||||
this.sliderValue = (mouseX - (this.x + 4)) / (this.width - 8);
|
||||
updateSlider();
|
||||
this.dragging = true;
|
||||
}
|
||||
|
||||
public void updateSlider()
|
||||
{
|
||||
if (this.sliderValue < 0.0F)
|
||||
{
|
||||
this.sliderValue = 0.0F;
|
||||
}
|
||||
|
||||
if (this.sliderValue > 1.0F)
|
||||
{
|
||||
this.sliderValue = 1.0F;
|
||||
}
|
||||
|
||||
String val;
|
||||
|
||||
if (showDecimal)
|
||||
{
|
||||
val = Double.toString(sliderValue * (maxValue - minValue) + minValue);
|
||||
|
||||
if (val.substring(val.indexOf(".") + 1).length() > precision)
|
||||
{
|
||||
val = val.substring(0, val.indexOf(".") + precision + 1);
|
||||
|
||||
if (val.endsWith("."))
|
||||
{
|
||||
val = val.substring(0, val.indexOf(".") + precision);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (val.substring(val.indexOf(".") + 1).length() < precision)
|
||||
{
|
||||
val = val + "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
val = Integer.toString((int)Math.round(sliderValue * (maxValue - minValue) + minValue));
|
||||
}
|
||||
|
||||
if(drawString)
|
||||
{
|
||||
setMessage(new TextComponent("").append(dispString).append(val).append(suffix));
|
||||
}
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
parent.onChangeSliderValue(this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when the mouse button is released. Equivalent of MouseListener.mouseReleased(MouseEvent e).
|
||||
*/
|
||||
@Override
|
||||
public void onRelease(double mouseX, double mouseY)
|
||||
{
|
||||
this.dragging = false;
|
||||
}
|
||||
|
||||
public int getValueInt()
|
||||
{
|
||||
return (int)Math.round(sliderValue * (maxValue - minValue) + minValue);
|
||||
}
|
||||
|
||||
public double getValue()
|
||||
{
|
||||
return sliderValue * (maxValue - minValue) + minValue;
|
||||
}
|
||||
|
||||
public void setValue(double d)
|
||||
{
|
||||
this.sliderValue = (d - minValue) / (maxValue - minValue);
|
||||
}
|
||||
|
||||
public static interface ISlider
|
||||
{
|
||||
void onChangeSliderValue(Slider slider);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraftforge.client.gui.GuiUtils;
|
||||
|
||||
/**
|
||||
@@ -47,14 +46,14 @@ public class UnicodeGlyphButton extends ExtendedButton
|
||||
int totalWidth = strWidth + glyphWidth;
|
||||
|
||||
if (totalWidth > width - 6 && totalWidth > ellipsisWidth)
|
||||
buttonText = new TextComponent(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString().trim() + "...") ;
|
||||
buttonText = Component.literal(mc.font.substrByWidth(buttonText, width - 6 - ellipsisWidth).getString().trim() + "...") ;
|
||||
|
||||
strWidth = mc.font.width(buttonText);
|
||||
totalWidth = glyphWidth + strWidth;
|
||||
|
||||
poseStack.pushPose();
|
||||
poseStack.scale(glyphScale, glyphScale, 1.0F);
|
||||
this.drawCenteredString(poseStack, mc.font, new TextComponent(glyph),
|
||||
this.drawCenteredString(poseStack, mc.font, Component.literal(glyph),
|
||||
(int) (((this.x + (this.width / 2) - (strWidth / 2)) / glyphScale) - (glyphWidth / (2 * glyphScale)) + 2),
|
||||
(int) (((this.y + ((this.height - 8) / glyphScale) / 2) - 1) / glyphScale), getFGColor());
|
||||
poseStack.popPose();
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.util.Map.Entry;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.packs.repository.RepositorySource;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.packs.repository.PackSource;
|
||||
@@ -40,7 +41,6 @@ import net.minecraft.client.resources.ClientPackSource;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.client.model.ModelLoaderRegistry;
|
||||
@@ -209,7 +209,7 @@ public class ClientModLoader
|
||||
}
|
||||
}
|
||||
final Pack packInfo = Pack.create("mod_resources", true, () -> new DelegatingResourcePack("mod_resources", "Mod Resources",
|
||||
new PackMetadataSection(new TranslatableComponent("fml.resources.modresources", hiddenPacks.size()), PackType.CLIENT_RESOURCES.getVersion(SharedConstants.getCurrentVersion())),
|
||||
new PackMetadataSection(Component.translatable("fml.resources.modresources", hiddenPacks.size()), PackType.CLIENT_RESOURCES.getVersion(SharedConstants.getCurrentVersion())),
|
||||
hiddenPacks), factory, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
consumer.accept(packInfo);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ public class EarlyLoaderGUI {
|
||||
|
||||
private void renderBackground() {
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
boolean isDarkBackground = minecraft.options.darkMojangStudiosBackground;
|
||||
boolean isDarkBackground = minecraft.options.darkMojangStudiosBackground().get();
|
||||
GL11.glColor4f(isDarkBackground ? 0 : (239F / 255F), isDarkBackground ? 0 : (50F / 255F), isDarkBackground ? 0 : (61F / 255F), 1); //Color from LoadingOverlay
|
||||
GL11.glVertex3f(0, 0, -10);
|
||||
GL11.glVertex3f(0, window.getGuiScaledHeight(), -10);
|
||||
|
||||
@@ -5,14 +5,12 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import com.mojang.math.Transformation;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
@@ -21,6 +19,7 @@ import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.core.Direction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BakedItemModel implements BakedModel
|
||||
{
|
||||
@@ -55,7 +54,7 @@ public class BakedItemModel implements BakedModel
|
||||
@Override public ItemOverrides getOverrides() { return overrides; }
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
|
||||
{
|
||||
if (side == null)
|
||||
{
|
||||
@@ -93,7 +92,7 @@ public class BakedItemModel implements BakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads (@Nullable BlockState state, @Nullable Direction side, Random rand)
|
||||
public List<BakedQuad> getQuads (@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
|
||||
{
|
||||
if(side == null)
|
||||
{
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
@@ -21,6 +19,8 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public abstract class BakedModelWrapper<T extends BakedModel> implements BakedModel
|
||||
{
|
||||
@@ -32,7 +32,7 @@ public abstract class BakedModelWrapper<T extends BakedModel> implements BakedMo
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
|
||||
{
|
||||
return originalModel.getQuads(state, side, rand);
|
||||
}
|
||||
@@ -98,21 +98,21 @@ public abstract class BakedModelWrapper<T extends BakedModel> implements BakedMo
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleIcon(@Nonnull IModelData data)
|
||||
public TextureAtlasSprite getParticleIcon(@NotNull IModelData data)
|
||||
{
|
||||
return originalModel.getParticleIcon(data);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
|
||||
{
|
||||
return originalModel.getQuads(state, side, rand, extraData);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public IModelData getModelData(@Nonnull BlockAndTintGetter level, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData modelData)
|
||||
public IModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull IModelData modelData)
|
||||
{
|
||||
return originalModel.getModelData(level, pos, state, modelData);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -23,6 +22,7 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BlockModelConfiguration implements IModelConfiguration
|
||||
{
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
@@ -22,8 +23,6 @@ import net.minecraftforge.client.model.data.*;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
|
||||
import net.minecraftforge.client.model.geometry.IMultipartModelGeometry;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -36,6 +35,8 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CompositeModel implements IDynamicBakedModel
|
||||
{
|
||||
@@ -58,9 +59,9 @@ public class CompositeModel implements IDynamicBakedModel
|
||||
this.transforms = combinedTransform;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
|
||||
{
|
||||
List<BakedQuad> quads = new ArrayList<>();
|
||||
for(Map.Entry<String, BakedModel> entry : bakedParts.entrySet())
|
||||
@@ -70,9 +71,9 @@ public class CompositeModel implements IDynamicBakedModel
|
||||
return quads;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public IModelData getModelData(@Nonnull BlockAndTintGetter level, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nonnull IModelData modelData)
|
||||
public IModelData getModelData(@NotNull BlockAndTintGetter level, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull IModelData modelData)
|
||||
{
|
||||
CompositeModelData composite = new CompositeModelData();
|
||||
for(Map.Entry<String, BakedModel> entry : bakedParts.entrySet())
|
||||
|
||||
@@ -28,8 +28,6 @@ import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -40,6 +38,8 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class DynamicBucketModel implements IModelGeometry<DynamicBucketModel>
|
||||
{
|
||||
@@ -51,7 +51,7 @@ public final class DynamicBucketModel implements IModelGeometry<DynamicBucketMod
|
||||
private static final float NORTH_Z_FLUID = 7.498f / 16f;
|
||||
private static final float SOUTH_Z_FLUID = 8.502f / 16f;
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
private final Fluid fluid;
|
||||
|
||||
private final boolean flipGas;
|
||||
@@ -244,7 +244,7 @@ public final class DynamicBucketModel implements IModelGeometry<DynamicBucketMod
|
||||
return FluidUtil.getFluidContained(stack)
|
||||
.map(fluidStack -> {
|
||||
Fluid fluid = fluidStack.getFluid();
|
||||
String name = fluid.getRegistryName().toString();
|
||||
String name = ForgeRegistries.FLUIDS.getKey(fluid).toString();
|
||||
|
||||
if (!cache.containsKey(name))
|
||||
{
|
||||
|
||||
@@ -11,12 +11,10 @@ import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import com.mojang.math.Transformation;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
|
||||
@@ -51,6 +49,7 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class FluidModel implements IModelGeometry<FluidModel>
|
||||
{
|
||||
@@ -186,7 +185,7 @@ public final class FluidModel implements IModelGeometry<FluidModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData modelData)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, IModelData modelData)
|
||||
{
|
||||
if (side != null)
|
||||
{
|
||||
@@ -450,7 +449,7 @@ public final class FluidModel implements IModelGeometry<FluidModel>
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
|
||||
{
|
||||
return side == null ? ImmutableList.of() : faceQuads.get(side);
|
||||
}
|
||||
|
||||
@@ -23,8 +23,6 @@ import com.google.common.collect.Maps;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static net.minecraftforge.fml.Logging.MODELLOADING;
|
||||
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
@@ -32,6 +30,7 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class ForgeModelBakery extends ModelBakery
|
||||
{
|
||||
|
||||
@@ -10,8 +10,7 @@ import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometryPart;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/*
|
||||
* Interface that provides generic access to the data within BlockModel,
|
||||
|
||||
@@ -26,7 +26,6 @@ import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||
import net.minecraftforge.client.model.pipeline.TRSRTransformer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -38,6 +37,7 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Forge reimplementation of vanilla {@link ItemModelGenerator}, i.e. builtin/generated models,
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
@@ -22,12 +23,11 @@ import net.minecraft.core.Direction;
|
||||
import com.mojang.math.Transformation;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class ItemMultiLayerBakedModel implements IDynamicBakedModel
|
||||
{
|
||||
@@ -54,7 +54,7 @@ public class ItemMultiLayerBakedModel implements IDynamicBakedModel
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData modelData)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, IModelData modelData)
|
||||
{
|
||||
List<BakedQuad> quads = Lists.newArrayList();
|
||||
layerModels.forEach(lm -> quads.addAll(lm.getFirst().getQuads(state, side, rand, modelData)));
|
||||
|
||||
@@ -12,8 +12,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -27,14 +25,15 @@ import net.minecraftforge.event.world.ChunkEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
||||
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@EventBusSubscriber(modid = "forge", bus = Bus.FORGE, value = Dist.CLIENT)
|
||||
public class ModelDataManager
|
||||
{
|
||||
private static WeakReference<Level> currentLevel = new WeakReference<>(null);
|
||||
|
||||
|
||||
private static final Map<ChunkPos, Set<BlockPos>> needModelDataRefresh = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
private static final Map<ChunkPos, Map<BlockPos, IModelData>> modelDataCache = new ConcurrentHashMap<>();
|
||||
|
||||
private static void cleanCaches(Level level)
|
||||
@@ -48,7 +47,7 @@ public class ModelDataManager
|
||||
modelDataCache.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void requestModelDataRefresh(BlockEntity te)
|
||||
{
|
||||
Preconditions.checkNotNull(te, "Tile entity must not be null");
|
||||
@@ -58,9 +57,9 @@ public class ModelDataManager
|
||||
needModelDataRefresh.computeIfAbsent(new ChunkPos(te.getBlockPos()), $ -> Collections.synchronizedSet(new HashSet<>()))
|
||||
.add(te.getBlockPos());
|
||||
}
|
||||
|
||||
|
||||
private static void refreshModelData(Level level, ChunkPos chunk)
|
||||
{
|
||||
{
|
||||
cleanCaches(level);
|
||||
Set<BlockPos> needUpdate = needModelDataRefresh.remove(chunk);
|
||||
|
||||
@@ -81,22 +80,22 @@ public class ModelDataManager
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onChunkUnload(ChunkEvent.Unload event)
|
||||
{
|
||||
if (!event.getChunk().getWorldForge().isClientSide()) return;
|
||||
|
||||
|
||||
ChunkPos chunk = event.getChunk().getPos();
|
||||
needModelDataRefresh.remove(chunk);
|
||||
modelDataCache.remove(chunk);
|
||||
}
|
||||
|
||||
|
||||
public static @Nullable IModelData getModelData(Level level, BlockPos pos)
|
||||
{
|
||||
return getModelData(level, new ChunkPos(pos)).get(pos);
|
||||
}
|
||||
|
||||
|
||||
public static Map<BlockPos, IModelData> getModelData(Level level, ChunkPos pos)
|
||||
{
|
||||
Preconditions.checkArgument(level.isClientSide, "Cannot request model data for server level");
|
||||
|
||||
@@ -28,7 +28,6 @@ import net.minecraftforge.client.model.geometry.ISimpleModelGeometry;
|
||||
import net.minecraftforge.client.model.obj.OBJLoader;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
@@ -49,6 +48,7 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.minecraftforge.common.util.Lazy;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
|
||||
@@ -7,14 +7,12 @@ package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.*;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import com.mojang.math.Transformation;
|
||||
@@ -45,6 +43,8 @@ import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* A model that can be rendered in multiple {@link RenderType}.
|
||||
@@ -132,9 +132,9 @@ public final class MultiLayerModel implements IModelGeometry<MultiLayerModel>
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData)
|
||||
{
|
||||
RenderType layer = MinecraftForgeClient.getRenderType();
|
||||
if (layer == null)
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
package net.minecraftforge.client.model;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
@@ -22,15 +22,14 @@ import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverride;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class PerspectiveMapWrapper implements IDynamicBakedModel
|
||||
{
|
||||
@@ -124,7 +123,7 @@ public class PerspectiveMapWrapper implements IDynamicBakedModel
|
||||
@Override public TextureAtlasSprite getParticleIcon() { return parent.getParticleIcon(); }
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override public ItemTransforms getTransforms() { return parent.getTransforms(); }
|
||||
@Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData extraData)
|
||||
@Override public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand, IModelData extraData)
|
||||
{
|
||||
return parent.getQuads(state, side, rand, extraData);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
@@ -22,21 +22,18 @@ import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.model.geometry.IModelGeometry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.client.resources.model.Material;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SeparatePerspectiveModel implements IModelGeometry<SeparatePerspectiveModel>
|
||||
{
|
||||
@@ -94,7 +91,7 @@ public class SeparatePerspectiveModel implements IModelGeometry<SeparatePerspect
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand)
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand)
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import net.minecraft.client.resources.model.ModelState;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.client.textures.UnitSprite;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,787 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.client.model.b3d;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexFormatElement;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.ItemOverrides;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.*;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.client.model.CompositeModelState;
|
||||
import net.minecraftforge.client.model.ForgeModelBakery;
|
||||
import net.minecraftforge.client.model.ModelLoadingException;
|
||||
import net.minecraftforge.client.model.PerspectiveMapWrapper;
|
||||
import net.minecraftforge.client.model.b3d.B3DModel.*;
|
||||
import net.minecraftforge.client.model.data.IDynamicBakedModel;
|
||||
import net.minecraftforge.client.model.data.IModelData;
|
||||
import net.minecraftforge.client.model.pipeline.BakedQuadBuilder;
|
||||
import net.minecraftforge.client.model.pipeline.IVertexConsumer;
|
||||
import net.minecraftforge.common.model.TransformationHelper;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/*
|
||||
* Loader for Blitz3D models.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.18")
|
||||
public enum B3DLoader
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private ResourceManager manager;
|
||||
|
||||
private final Set<String> enabledDomains = new HashSet<>();
|
||||
private final Map<ResourceLocation, B3DModel> cache = new HashMap<>();
|
||||
|
||||
public UnbakedModel loadModel(ResourceLocation modelLocation) throws Exception
|
||||
{
|
||||
ResourceLocation file = new ResourceLocation(modelLocation.getNamespace(), modelLocation.getPath());
|
||||
if(!cache.containsKey(file))
|
||||
{
|
||||
Resource resource = null;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
resource = manager.getResource(file);
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
if(modelLocation.getPath().startsWith("models/block/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getNamespace(), "models/item/" + file.getPath().substring("models/block/".length())));
|
||||
else if(modelLocation.getPath().startsWith("models/item/"))
|
||||
resource = manager.getResource(new ResourceLocation(file.getNamespace(), "models/block/" + file.getPath().substring("models/item/".length())));
|
||||
else throw e;
|
||||
}
|
||||
B3DModel.Parser parser = new B3DModel.Parser(resource.getInputStream());
|
||||
B3DModel model = parser.parse();
|
||||
cache.put(file, model);
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
cache.put(file, null);
|
||||
throw e;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtils.closeQuietly(resource);
|
||||
}
|
||||
}
|
||||
B3DModel model = cache.get(file);
|
||||
if(model == null) throw new ModelLoadingException("Error loading model previously: " + file);
|
||||
if(!(model.getRoot().getKind() instanceof Mesh))
|
||||
{
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(), true, true, true, 1);
|
||||
}
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(model.getRoot().getName()), true, true, true, 1);
|
||||
}
|
||||
|
||||
public static final class B3DState implements ModelState
|
||||
{
|
||||
@Nullable
|
||||
private final Animation animation;
|
||||
private final int frame;
|
||||
private final int nextFrame;
|
||||
private final float progress;
|
||||
@Nullable
|
||||
private final ModelState parent;
|
||||
|
||||
public B3DState(@Nullable Animation animation, int frame)
|
||||
{
|
||||
this(animation, frame, frame, 0);
|
||||
}
|
||||
|
||||
public B3DState(@Nullable Animation animation, int frame, ModelState parent)
|
||||
{
|
||||
this(animation, frame, frame, 0, parent);
|
||||
}
|
||||
|
||||
public B3DState(@Nullable Animation animation, int frame, int nextFrame, float progress)
|
||||
{
|
||||
this(animation, frame, nextFrame, progress, null);
|
||||
}
|
||||
|
||||
public B3DState(@Nullable Animation animation, int frame, int nextFrame, float progress, @Nullable ModelState parent)
|
||||
{
|
||||
this.animation = animation;
|
||||
this.frame = frame;
|
||||
this.nextFrame = nextFrame;
|
||||
this.progress = Mth.clamp(progress, 0, 1);
|
||||
this.parent = getParent(parent);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ModelState getParent(@Nullable ModelState parent)
|
||||
{
|
||||
if (parent == null) return null;
|
||||
else if (parent instanceof B3DState) return ((B3DState)parent).parent;
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Animation getAnimation()
|
||||
{
|
||||
return animation;
|
||||
}
|
||||
|
||||
public int getFrame()
|
||||
{
|
||||
return frame;
|
||||
}
|
||||
|
||||
public int getNextFrame()
|
||||
{
|
||||
return nextFrame;
|
||||
}
|
||||
|
||||
public float getProgress()
|
||||
{
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ModelState getParent()
|
||||
{
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Transformation getRotation()
|
||||
{
|
||||
if(parent != null)
|
||||
{
|
||||
return parent.getRotation();
|
||||
}
|
||||
return Transformation.identity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Transformation getPartTransformation(Object part)
|
||||
{
|
||||
// TODO make more use of Optional
|
||||
|
||||
if(!(part instanceof NodeJoint))
|
||||
{
|
||||
return Transformation.identity();
|
||||
}
|
||||
Node<?> node = ((NodeJoint)part).getNode();
|
||||
Transformation nodeTransform;
|
||||
if(progress < 1e-5 || frame == nextFrame)
|
||||
{
|
||||
nodeTransform = getNodeMatrix(node, frame);
|
||||
}
|
||||
else if(progress > 1 - 1e-5)
|
||||
{
|
||||
nodeTransform = getNodeMatrix(node, nextFrame);
|
||||
}
|
||||
else
|
||||
{
|
||||
nodeTransform = getNodeMatrix(node, frame);
|
||||
nodeTransform = TransformationHelper.slerp(nodeTransform,getNodeMatrix(node, nextFrame), progress);
|
||||
}
|
||||
if(parent != null && node.getParent() == null)
|
||||
{
|
||||
return parent.getPartTransformation(part).compose(nodeTransform);
|
||||
}
|
||||
return nodeTransform;
|
||||
}
|
||||
|
||||
private static LoadingCache<Triple<Animation, Node<?>, Integer>, Transformation> cache = CacheBuilder.newBuilder()
|
||||
.maximumSize(16384)
|
||||
.expireAfterAccess(2, TimeUnit.MINUTES)
|
||||
.build(new CacheLoader<Triple<Animation, Node<?>, Integer>, Transformation>()
|
||||
{
|
||||
@Override
|
||||
public Transformation load(Triple<Animation, Node<?>, Integer> key) throws Exception
|
||||
{
|
||||
return getNodeMatrix(key.getLeft(), key.getMiddle(), key.getRight());
|
||||
}
|
||||
});
|
||||
|
||||
public Transformation getNodeMatrix(Node<?> node)
|
||||
{
|
||||
return getNodeMatrix(node, frame);
|
||||
}
|
||||
|
||||
public Transformation getNodeMatrix(Node<?> node, int frame)
|
||||
{
|
||||
return cache.getUnchecked(Triple.of(animation, node, frame));
|
||||
}
|
||||
|
||||
public static Transformation getNodeMatrix(@Nullable Animation animation, Node<?> node, int frame)
|
||||
{
|
||||
Transformation ret = Transformation.identity();
|
||||
Key key = null;
|
||||
if(animation != null) key = animation.getKeys().get(frame, node);
|
||||
else if(node.getAnimation() != null) key = node.getAnimation().getKeys().get(frame, node);
|
||||
if(key != null)
|
||||
{
|
||||
Node<?> parent = node.getParent();
|
||||
if(parent != null)
|
||||
{
|
||||
// parent model-global current pose
|
||||
Transformation pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
|
||||
ret = ret.compose(pm);
|
||||
// joint offset in the parent coords
|
||||
ret = ret.compose(new Transformation(parent.getPos(), parent.getRot(), parent.getScale(), null));
|
||||
}
|
||||
// current node local pose
|
||||
ret = ret.compose(new Transformation(key.getPos(), key.getRot(), key.getScale(), null));
|
||||
// this part moved inside the model
|
||||
// inverse bind of the current node
|
||||
/*Matrix4f rm = new TRSRTransformation(node.getPos(), node.getRot(), node.getScale(), null).getMatrix();
|
||||
rm.invert();
|
||||
ret = ret.compose(new TRSRTransformation(rm));
|
||||
if(parent != null)
|
||||
{
|
||||
// inverse bind of the parent
|
||||
rm = new TRSRTransformation(parent.getPos(), parent.getRot(), parent.getScale(), null).getMatrix();
|
||||
rm.invert();
|
||||
ret = ret.compose(new TRSRTransformation(rm));
|
||||
}*/
|
||||
// TODO cache
|
||||
Transformation invBind = new NodeJoint(node).getInvBindPose();
|
||||
ret = ret.compose(invBind);
|
||||
}
|
||||
else
|
||||
{
|
||||
Node<?> parent = node.getParent();
|
||||
if(parent != null)
|
||||
{
|
||||
// parent model-global current pose
|
||||
Transformation pm = cache.getUnchecked(Triple.of(animation, node.getParent(), frame));
|
||||
ret = ret.compose(pm);
|
||||
// joint offset in the parent coords
|
||||
ret = ret.compose(new Transformation(parent.getPos(), parent.getRot(), parent.getScale(), null));
|
||||
}
|
||||
ret = ret.compose(new Transformation(node.getPos(), node.getRot(), node.getScale(), null));
|
||||
// TODO cache
|
||||
Transformation invBind = new NodeJoint(node).getInvBindPose();
|
||||
ret = ret.compose(invBind);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
static final class NodeJoint
|
||||
{
|
||||
private final Node<?> node;
|
||||
|
||||
public NodeJoint(Node<?> node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
public Transformation getInvBindPose()
|
||||
{
|
||||
Matrix4f m = new Transformation(node.getPos(), node.getRot(), node.getScale(), null).getMatrix();
|
||||
m.invert();
|
||||
Transformation pose = new Transformation(m);
|
||||
|
||||
if(node.getParent() != null)
|
||||
{
|
||||
Transformation parent = new NodeJoint(node.getParent()).getInvBindPose();
|
||||
pose = pose.compose(parent);
|
||||
}
|
||||
return pose;
|
||||
}
|
||||
|
||||
public Optional<NodeJoint> getParent()
|
||||
{
|
||||
// FIXME cache?
|
||||
if(node.getParent() == null) return Optional.empty();
|
||||
return Optional.of(new NodeJoint(node.getParent()));
|
||||
}
|
||||
|
||||
public Node<?> getNode()
|
||||
{
|
||||
return node;
|
||||
}
|
||||
|
||||
public int hashCode()
|
||||
{
|
||||
return node.hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if (this == obj) return true;
|
||||
if (!super.equals(obj)) return false;
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
NodeJoint other = (NodeJoint) obj;
|
||||
return Objects.equal(node, other.node);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ModelWrapper implements UnbakedModel
|
||||
{
|
||||
private final ResourceLocation modelLocation;
|
||||
private final B3DModel model;
|
||||
private final ImmutableSet<String> meshes;
|
||||
private final ImmutableMap<String, String> textures;
|
||||
private final boolean smooth;
|
||||
private final boolean gui3d;
|
||||
private final boolean isSideLit;
|
||||
private final int defaultKey;
|
||||
|
||||
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, boolean smooth, boolean gui3d, boolean isSideLit, int defaultKey)
|
||||
{
|
||||
this(modelLocation, model, meshes, smooth, gui3d, isSideLit, defaultKey, buildTextures(model.getTextures()));
|
||||
}
|
||||
|
||||
public ModelWrapper(ResourceLocation modelLocation, B3DModel model, ImmutableSet<String> meshes, boolean smooth, boolean gui3d, boolean isSideLit, int defaultKey, ImmutableMap<String, String> textures)
|
||||
{
|
||||
this.modelLocation = modelLocation;
|
||||
this.model = model;
|
||||
this.meshes = meshes;
|
||||
this.isSideLit = isSideLit;
|
||||
this.textures = textures;
|
||||
this.smooth = smooth;
|
||||
this.gui3d = gui3d;
|
||||
this.defaultKey = defaultKey;
|
||||
}
|
||||
|
||||
private static ImmutableMap<String, String> buildTextures(List<Texture> textures)
|
||||
{
|
||||
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
|
||||
for(Texture t : textures)
|
||||
{
|
||||
String path = t.getPath();
|
||||
String location = getLocation(path);
|
||||
if(!location.startsWith("#")) location = "#" + location;
|
||||
builder.put(path, location);
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
private static String getLocation(String path)
|
||||
{
|
||||
if(path.endsWith(".png")) path = path.substring(0, path.length() - ".png".length());
|
||||
return path;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public Collection<Material> getMaterials(Function<ResourceLocation, UnbakedModel> modelGetter, Set<com.mojang.datafixers.util.Pair<String, String>> missingTextureErrors)
|
||||
{
|
||||
return textures.values().stream().filter(loc -> !loc.startsWith("#"))
|
||||
.map(t -> new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(t)))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ResourceLocation> getDependencies()
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Nullable
|
||||
@Override
|
||||
public BakedModel bake(ModelBakery bakery, Function<Material, TextureAtlasSprite> spriteGetter, ModelState modelTransform, ResourceLocation modelLocation)
|
||||
{
|
||||
ImmutableMap.Builder<String, TextureAtlasSprite> builder = ImmutableMap.builder();
|
||||
TextureAtlasSprite missing = spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, MissingTextureAtlasSprite.getLocation()));
|
||||
for(Map.Entry<String, String> e : textures.entrySet())
|
||||
{
|
||||
if(e.getValue().startsWith("#"))
|
||||
{
|
||||
LOGGER.fatal("unresolved texture '{}' for b3d model '{}'", e.getValue(), this.modelLocation);
|
||||
builder.put(e.getKey(), missing);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.put(e.getKey(), spriteGetter.apply(new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation(e.getValue()))));
|
||||
}
|
||||
}
|
||||
builder.put("missingno", missing);
|
||||
return new BakedWrapper(model.getRoot(), modelTransform, smooth, gui3d, isSideLit, meshes, builder.build());
|
||||
}
|
||||
|
||||
public ModelWrapper retexture(ImmutableMap<String, String> textures)
|
||||
{
|
||||
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
for(Map.Entry<String, String> e : this.textures.entrySet())
|
||||
{
|
||||
String path = e.getKey();
|
||||
String loc = getLocation(path);
|
||||
// FIXME: Backward compatibilty: support finding textures that start with #, even though this is not how vanilla works
|
||||
if(loc.startsWith("#") && (textures.containsKey(loc) || textures.containsKey(loc.substring(1))))
|
||||
{
|
||||
String alt = loc.substring(1);
|
||||
String newLoc = textures.get(loc);
|
||||
if(newLoc == null) newLoc = textures.get(alt);
|
||||
if(newLoc == null) newLoc = path.substring(1);
|
||||
builder.put(e.getKey(), newLoc);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.put(e);
|
||||
}
|
||||
}
|
||||
return new ModelWrapper(modelLocation, model, meshes, smooth, gui3d, isSideLit, defaultKey, builder.build());
|
||||
}
|
||||
|
||||
public ModelWrapper process(ImmutableMap<String, String> data)
|
||||
{
|
||||
ImmutableSet<String> newMeshes = this.meshes;
|
||||
int newDefaultKey = this.defaultKey;
|
||||
boolean hasChanged = false;
|
||||
if(data.containsKey("mesh"))
|
||||
{
|
||||
JsonElement e = new JsonParser().parse(data.get("mesh"));
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isString())
|
||||
{
|
||||
return new ModelWrapper(modelLocation, model, ImmutableSet.of(e.getAsString()), smooth, gui3d, isSideLit, defaultKey, textures);
|
||||
}
|
||||
else if (e.isJsonArray())
|
||||
{
|
||||
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
|
||||
for(JsonElement s : e.getAsJsonArray())
|
||||
{
|
||||
if(s.isJsonPrimitive() && s.getAsJsonPrimitive().isString())
|
||||
{
|
||||
builder.add(s.getAsString());
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.fatal("unknown mesh definition '{}' in array for b3d model '{}'", s.toString(), modelLocation);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
newMeshes = builder.build();
|
||||
hasChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.fatal("unknown mesh definition '{}' for b3d model '{}'", e.toString(), modelLocation);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
if(data.containsKey("key"))
|
||||
{
|
||||
JsonElement e = new JsonParser().parse(data.get("key"));
|
||||
if(e.isJsonPrimitive() && e.getAsJsonPrimitive().isNumber())
|
||||
{
|
||||
newDefaultKey = e.getAsNumber().intValue();
|
||||
hasChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGGER.fatal("unknown keyframe definition '{}' for b3d model '{}'", e.toString(), modelLocation);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
return hasChanged ? new ModelWrapper(modelLocation, model, newMeshes, smooth, gui3d, isSideLit, newDefaultKey, textures) : this;
|
||||
}
|
||||
|
||||
public ModelState getDefaultState()
|
||||
{
|
||||
return new B3DState(model.getRoot().getAnimation(), defaultKey, defaultKey, 0);
|
||||
}
|
||||
|
||||
public ModelWrapper smoothLighting(boolean value)
|
||||
{
|
||||
if(value == smooth)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
return new ModelWrapper(modelLocation, model, meshes, value, gui3d, isSideLit, defaultKey, textures);
|
||||
}
|
||||
|
||||
public ModelWrapper gui3d(boolean value)
|
||||
{
|
||||
if(value == gui3d)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
return new ModelWrapper(modelLocation, model, meshes, smooth, value, isSideLit, defaultKey, textures);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BakedWrapper implements IDynamicBakedModel
|
||||
{
|
||||
private final Node<?> node;
|
||||
private final ModelState state;
|
||||
private final boolean smooth;
|
||||
private final boolean gui3d;
|
||||
private final boolean isSideLit;
|
||||
private final ImmutableSet<String> meshes;
|
||||
private final ImmutableMap<String, TextureAtlasSprite> textures;
|
||||
private final LoadingCache<Integer, B3DState> cache;
|
||||
|
||||
private ImmutableList<BakedQuad> quads;
|
||||
|
||||
public record HiddenModelPart(ImmutableList<String> path) { }
|
||||
|
||||
public BakedWrapper(final Node<?> node, final ModelState state, final boolean smooth, final boolean gui3d, boolean isSideLit, final ImmutableSet<String> meshes, final ImmutableMap<String, TextureAtlasSprite> textures)
|
||||
{
|
||||
this(node, state, smooth, gui3d, isSideLit, meshes, textures, CacheBuilder.newBuilder()
|
||||
.maximumSize(128)
|
||||
.expireAfterAccess(2, TimeUnit.MINUTES)
|
||||
.build(new CacheLoader<Integer, B3DState>()
|
||||
{
|
||||
@Override
|
||||
public B3DState load(Integer frame) throws Exception
|
||||
{
|
||||
ModelState parent = state;
|
||||
Animation newAnimation = node.getAnimation();
|
||||
if(parent instanceof B3DState)
|
||||
{
|
||||
B3DState ps = (B3DState)parent;
|
||||
parent = ps.getParent();
|
||||
}
|
||||
return new B3DState(newAnimation, frame, frame, 0, parent);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public BakedWrapper(Node<?> node, ModelState state, boolean smooth, boolean gui3d, boolean isSideLit, ImmutableSet<String> meshes, ImmutableMap<String, TextureAtlasSprite> textures, LoadingCache<Integer, B3DState> cache)
|
||||
{
|
||||
this.node = node;
|
||||
this.state = state;
|
||||
this.smooth = smooth;
|
||||
this.gui3d = gui3d;
|
||||
this.isSideLit = isSideLit;
|
||||
this.meshes = meshes;
|
||||
this.textures = textures;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand, IModelData data)
|
||||
{
|
||||
if(side != null) return ImmutableList.of();
|
||||
ModelState modelState = this.state;
|
||||
ModelState newState = data.getData(Properties.AnimationProperty);
|
||||
if(newState != null)
|
||||
{
|
||||
// FIXME: should animation state handle the parent state, or should it remain here?
|
||||
ModelState parent = this.state;
|
||||
if(parent instanceof B3DState)
|
||||
{
|
||||
B3DState ps = (B3DState)parent;
|
||||
parent = ps.getParent();
|
||||
}
|
||||
if (parent == null)
|
||||
{
|
||||
modelState = newState;
|
||||
}
|
||||
else
|
||||
{
|
||||
modelState = new CompositeModelState(parent, newState);
|
||||
}
|
||||
}
|
||||
if(quads == null)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
generateQuads(builder, node, this.state, ImmutableList.of());
|
||||
quads = builder.build();
|
||||
}
|
||||
// TODO: caching?
|
||||
if(this.state != modelState)
|
||||
{
|
||||
ImmutableList.Builder<BakedQuad> builder = ImmutableList.builder();
|
||||
generateQuads(builder, node, modelState, ImmutableList.of());
|
||||
return builder.build();
|
||||
}
|
||||
return quads;
|
||||
}
|
||||
|
||||
private void generateQuads(ImmutableList.Builder<BakedQuad> builder, Node<?> node, final ModelState state, ImmutableList<String> path)
|
||||
{
|
||||
ImmutableList.Builder<String> pathBuilder = ImmutableList.builder();
|
||||
pathBuilder.addAll(path);
|
||||
pathBuilder.add(node.getName());
|
||||
ImmutableList<String> newPath = pathBuilder.build();
|
||||
for(Node<?> child : node.getNodes().values())
|
||||
{
|
||||
generateQuads(builder, child, state, newPath);
|
||||
}
|
||||
if(node.getKind() instanceof Mesh && meshes.contains(node.getName()) && state.getPartTransformation(new HiddenModelPart(newPath)).isIdentity())
|
||||
{
|
||||
Mesh mesh = (Mesh)node.getKind();
|
||||
Collection<Face> faces = mesh.bake(new Function<Node<?>, Matrix4f>()
|
||||
{
|
||||
private final Transformation global = state.getRotation();
|
||||
private final LoadingCache<Node<?>, Transformation> localCache = CacheBuilder.newBuilder()
|
||||
.maximumSize(32)
|
||||
.build(new CacheLoader<Node<?>, Transformation>()
|
||||
{
|
||||
@Override
|
||||
public Transformation load(Node<?> node) throws Exception
|
||||
{
|
||||
return state.getPartTransformation(new NodeJoint(node));
|
||||
}
|
||||
});
|
||||
|
||||
@Override
|
||||
public Matrix4f apply(Node<?> node)
|
||||
{
|
||||
return global.compose(localCache.getUnchecked(node)).getMatrix();
|
||||
}
|
||||
});
|
||||
for(Face f : faces)
|
||||
{
|
||||
List<Texture> textures = null;
|
||||
if(f.getBrush() != null) textures = f.getBrush().getTextures();
|
||||
TextureAtlasSprite sprite;
|
||||
if(textures == null || textures.isEmpty()) sprite = this.textures.get("missingno");
|
||||
else if(textures.get(0) == B3DModel.Texture.White) sprite = ForgeModelBakery.White.instance();
|
||||
else sprite = this.textures.get(textures.get(0).getPath());
|
||||
BakedQuadBuilder quadBuilder = new BakedQuadBuilder(sprite);
|
||||
quadBuilder.setContractUVs(true);
|
||||
quadBuilder.setQuadOrientation(Direction.getNearest(f.getNormal().x(), f.getNormal().y(), f.getNormal().z()));
|
||||
putVertexData(quadBuilder, f.getV1(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV2(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);
|
||||
putVertexData(quadBuilder, f.getV3(), f.getNormal(), sprite);
|
||||
builder.add(quadBuilder.build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final void putVertexData(IVertexConsumer consumer, Vertex v, Vector3f faceNormal, TextureAtlasSprite sprite)
|
||||
{
|
||||
// TODO handle everything not handled (texture transformations, bones, transformations, normals, e.t.c)
|
||||
ImmutableList<VertexFormatElement> vertexFormatElements = consumer.getVertexFormat().getElements();
|
||||
for(int e = 0; e < vertexFormatElements.size(); e++)
|
||||
{
|
||||
switch(vertexFormatElements.get(e).getUsage())
|
||||
{
|
||||
case POSITION:
|
||||
consumer.put(e, v.getPos().x(), v.getPos().y(), v.getPos().z(), 1);
|
||||
break;
|
||||
case COLOR:
|
||||
if(v.getColor() != null)
|
||||
{
|
||||
consumer.put(e, v.getColor().x(), v.getColor().y(), v.getColor().z(), v.getColor().w());
|
||||
}
|
||||
else
|
||||
{
|
||||
consumer.put(e, 1, 1, 1, 1);
|
||||
}
|
||||
break;
|
||||
case UV:
|
||||
// TODO handle more brushes
|
||||
if(vertexFormatElements.get(e).getIndex() < v.getTexCoords().length)
|
||||
{
|
||||
consumer.put(e,
|
||||
sprite.getU(v.getTexCoords()[0].x() * 16),
|
||||
sprite.getV(v.getTexCoords()[0].y() * 16),
|
||||
0,
|
||||
1
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
consumer.put(e, 0, 0, 0, 1);
|
||||
}
|
||||
break;
|
||||
case NORMAL:
|
||||
if(v.getNormal() != null)
|
||||
{
|
||||
consumer.put(e, v.getNormal().x(), v.getNormal().y(), v.getNormal().z(), 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
consumer.put(e, faceNormal.x(), faceNormal.y(), faceNormal.z(), 0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
consumer.put(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useAmbientOcclusion()
|
||||
{
|
||||
return smooth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d()
|
||||
{
|
||||
return gui3d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean usesBlockLight()
|
||||
{
|
||||
return isSideLit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomRenderer()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleIcon()
|
||||
{
|
||||
// FIXME somehow specify particle texture in the model
|
||||
return textures.values().asList().get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesHandlePerspectives()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BakedModel handlePerspective(TransformType cameraTransformType, PoseStack poseStack)
|
||||
{
|
||||
return PerspectiveMapWrapper.handlePerspective(this, state, cameraTransformType, poseStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemOverrides getOverrides()
|
||||
{
|
||||
// TODO handle items
|
||||
return ItemOverrides.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,29 +6,28 @@
|
||||
package net.minecraftforge.client.model.data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.Direction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Convenience interface with default implementation of {@link BakedModel#getQuads(BlockState, Direction, Random, IModelData)}.
|
||||
* Convenience interface with default implementation of {@link BakedModel#getQuads(BlockState, Direction, RandomSource, IModelData)}.
|
||||
*/
|
||||
public interface IDynamicBakedModel extends BakedModel
|
||||
{
|
||||
@Override
|
||||
default @Nonnull List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand)
|
||||
default @NotNull List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand)
|
||||
{
|
||||
return getQuads(state, side, rand, EmptyModelData.INSTANCE);
|
||||
}
|
||||
|
||||
|
||||
// Force this to be overriden otherwise this introduces a default cycle between the two overloads.
|
||||
@Override
|
||||
@Nonnull
|
||||
List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData);
|
||||
@NotNull
|
||||
List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @NotNull RandomSource rand, @NotNull IModelData extraData);
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package net.minecraftforge.client.model.data;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IModelData
|
||||
{
|
||||
@@ -16,7 +16,7 @@ public interface IModelData
|
||||
* <p>
|
||||
* IMPORTANT: {@link #getData(ModelProperty)} <em>can</em> return {@code null}
|
||||
* even if this method returns {@code true}.
|
||||
*
|
||||
*
|
||||
* @param prop The property to check for inclusion in this model data
|
||||
* @return {@code true} if this data has the given property, even if no value is present
|
||||
*/
|
||||
@@ -24,7 +24,7 @@ public interface IModelData
|
||||
|
||||
@Nullable
|
||||
<T> T getData(ModelProperty<T> prop);
|
||||
|
||||
|
||||
@Nullable
|
||||
<T> T setData(ModelProperty<T> prop, T data);
|
||||
}
|
||||
@@ -10,8 +10,8 @@ import net.minecraft.client.resources.model.BakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockAndTintGetter;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Stub class to extend for block model data providers, eliminates some
|
||||
@@ -20,7 +19,7 @@ public abstract class BlockModelProvider extends ModelProvider<BlockModelBuilder
|
||||
super(generator, modid, BLOCK_FOLDER, BlockModelBuilder::new, existingFileHelper);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Block Models: " + modid;
|
||||
|
||||
@@ -13,12 +13,12 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.world.level.block.ButtonBlock;
|
||||
import net.minecraft.world.level.block.PressurePlateBlock;
|
||||
import net.minecraft.world.level.block.StandingSignBlock;
|
||||
import net.minecraft.world.level.block.WallSignBlock;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -47,7 +47,6 @@ import net.minecraft.world.level.block.TrapDoorBlock;
|
||||
import net.minecraft.world.level.block.WallBlock;
|
||||
import net.minecraft.world.level.block.state.properties.WallSide;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.world.level.block.state.properties.Property;
|
||||
import net.minecraft.world.level.block.state.properties.AttachFace;
|
||||
@@ -61,6 +60,7 @@ import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Direction.Axis;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Data provider for blockstate files. Extends {@link BlockModelProvider} so that
|
||||
@@ -83,15 +83,19 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
this.generator = gen;
|
||||
this.modid = modid;
|
||||
this.blockModels = new BlockModelProvider(gen, modid, exFileHelper) {
|
||||
@Override public void run(CachedOutput p_236071_) throws IOException {}
|
||||
|
||||
@Override protected void registerModels() {}
|
||||
};
|
||||
this.itemModels = new ItemModelProvider(gen, modid, this.blockModels.existingFileHelper) {
|
||||
@Override protected void registerModels() {}
|
||||
|
||||
@Override public void run(CachedOutput p_236071_) throws IOException {}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException {
|
||||
public void run(CachedOutput cache) throws IOException {
|
||||
models().clear();
|
||||
itemModels().clear();
|
||||
registeredBlocks.clear();
|
||||
@@ -145,12 +149,16 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
return new ResourceLocation(name);
|
||||
}
|
||||
|
||||
private ResourceLocation key(Block block) {
|
||||
return ForgeRegistries.BLOCKS.getKey(block);
|
||||
}
|
||||
|
||||
private String name(Block block) {
|
||||
return block.getRegistryName().getPath();
|
||||
return key(block).getPath();
|
||||
}
|
||||
|
||||
public ResourceLocation blockTexture(Block block) {
|
||||
ResourceLocation name = block.getRegistryName();
|
||||
ResourceLocation name = key(block);
|
||||
return new ResourceLocation(name.getNamespace(), ModelProvider.BLOCK_FOLDER + "/" + name.getPath());
|
||||
}
|
||||
|
||||
@@ -175,7 +183,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void simpleBlockItem(Block block, ModelFile model) {
|
||||
itemModels().getBuilder(block.getRegistryName().getPath()).parent(model);
|
||||
itemModels().getBuilder(key(block).getPath()).parent(model);
|
||||
}
|
||||
|
||||
public void simpleBlock(Block block, ConfiguredModel... models) {
|
||||
@@ -291,7 +299,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void stairsBlock(StairBlock block, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
|
||||
stairsBlockInternal(block, block.getRegistryName().toString(), side, bottom, top);
|
||||
stairsBlockInternal(block, key(block).toString(), side, bottom, top);
|
||||
}
|
||||
|
||||
public void stairsBlock(StairBlock block, String name, ResourceLocation side, ResourceLocation bottom, ResourceLocation top) {
|
||||
@@ -404,7 +412,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void fenceBlock(FenceBlock block, ResourceLocation texture) {
|
||||
String baseName = block.getRegistryName().toString();
|
||||
String baseName = key(block).toString();
|
||||
fourWayBlock(block, models().fencePost(baseName + "_post", texture), models().fenceSide(baseName + "_side", texture));
|
||||
}
|
||||
|
||||
@@ -413,7 +421,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void fenceGateBlock(FenceGateBlock block, ResourceLocation texture) {
|
||||
fenceGateBlockInternal(block, block.getRegistryName().toString(), texture);
|
||||
fenceGateBlockInternal(block, key(block).toString(), texture);
|
||||
}
|
||||
|
||||
public void fenceGateBlock(FenceGateBlock block, String name, ResourceLocation texture) {
|
||||
@@ -446,7 +454,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void wallBlock(WallBlock block, ResourceLocation texture) {
|
||||
wallBlockInternal(block, block.getRegistryName().toString(), texture);
|
||||
wallBlockInternal(block, key(block).toString(), texture);
|
||||
}
|
||||
|
||||
public void wallBlock(WallBlock block, String name, ResourceLocation texture) {
|
||||
@@ -456,7 +464,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
private void wallBlockInternal(WallBlock block, String baseName, ResourceLocation texture) {
|
||||
wallBlock(block, models().wallPost(baseName + "_post", texture), models().wallSide(baseName + "_side", texture), models().wallSideTall(baseName + "_side_tall", texture));
|
||||
}
|
||||
|
||||
|
||||
public static final ImmutableMap<Direction, Property<WallSide>> WALL_PROPS = ImmutableMap.<Direction, Property<WallSide>>builder()
|
||||
.put(Direction.EAST, BlockStateProperties.EAST_WALL)
|
||||
.put(Direction.NORTH, BlockStateProperties.NORTH_WALL)
|
||||
@@ -475,7 +483,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
wallSidePart(builder, sideTall, e, WallSide.TALL);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void wallSidePart(MultiPartBlockStateBuilder builder, ModelFile model, Map.Entry<Direction, Property<WallSide>> entry, WallSide height) {
|
||||
builder.part()
|
||||
.modelFile(model)
|
||||
@@ -486,7 +494,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void paneBlock(IronBarsBlock block, ResourceLocation pane, ResourceLocation edge) {
|
||||
paneBlockInternal(block, block.getRegistryName().toString(), pane, edge);
|
||||
paneBlockInternal(block, key(block).toString(), pane, edge);
|
||||
}
|
||||
|
||||
public void paneBlock(IronBarsBlock block, String name, ResourceLocation pane, ResourceLocation edge) {
|
||||
@@ -518,7 +526,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void doorBlock(DoorBlock block, ResourceLocation bottom, ResourceLocation top) {
|
||||
doorBlockInternal(block, block.getRegistryName().toString(), bottom, top);
|
||||
doorBlockInternal(block, key(block).toString(), bottom, top);
|
||||
}
|
||||
|
||||
public void doorBlock(DoorBlock block, String name, ResourceLocation bottom, ResourceLocation top) {
|
||||
@@ -553,7 +561,7 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}
|
||||
|
||||
public void trapdoorBlock(TrapDoorBlock block, ResourceLocation texture, boolean orientable) {
|
||||
trapdoorBlockInternal(block, block.getRegistryName().toString(), texture, orientable);
|
||||
trapdoorBlockInternal(block, key(block).toString(), texture, orientable);
|
||||
}
|
||||
|
||||
public void trapdoorBlock(TrapDoorBlock block, String name, ResourceLocation texture, boolean orientable) {
|
||||
@@ -587,19 +595,19 @@ public abstract class BlockStateProvider implements DataProvider {
|
||||
}, TrapDoorBlock.POWERED, TrapDoorBlock.WATERLOGGED);
|
||||
}
|
||||
|
||||
private void saveBlockState(HashCache cache, JsonObject stateJson, Block owner) {
|
||||
ResourceLocation blockName = Preconditions.checkNotNull(owner.getRegistryName());
|
||||
private void saveBlockState(CachedOutput cache, JsonObject stateJson, Block owner) {
|
||||
ResourceLocation blockName = Preconditions.checkNotNull(key(owner));
|
||||
Path mainOutput = generator.getOutputFolder();
|
||||
String pathSuffix = "assets/" + blockName.getNamespace() + "/blockstates/" + blockName.getPath() + ".json";
|
||||
Path outputPath = mainOutput.resolve(pathSuffix);
|
||||
try {
|
||||
DataProvider.save(GSON, cache, stateJson, outputPath);
|
||||
DataProvider.saveStable(cache, stateJson, outputPath);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Couldn't save blockstate to {}", outputPath, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Block States: " + modid;
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -20,6 +19,7 @@ import com.google.gson.JsonObject;
|
||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||
import net.minecraftforge.client.model.generators.MultiPartBlockStateBuilder.PartBuilder;
|
||||
import net.minecraftforge.client.model.generators.VariantBlockStateBuilder.PartialBlockstate;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a model with blockstate configurations, e.g. rotation, uvlock, and
|
||||
@@ -70,13 +70,13 @@ public final class ConfiguredModel {
|
||||
|
||||
/**
|
||||
* Construct a new {@link ConfiguredModel}.
|
||||
*
|
||||
*
|
||||
* @param model the underlying model
|
||||
* @param rotationX x-rotation to apply to the model
|
||||
* @param rotationY y-rotation to apply to the model
|
||||
* @param uvLock if uvlock should be enabled
|
||||
* @param weight the random weight of the model
|
||||
*
|
||||
*
|
||||
* @throws NullPointerException if {@code model} is {@code null}
|
||||
* @throws IllegalArgumentException if x and/or y rotation are not valid (see
|
||||
* {@link BlockModelRotation})
|
||||
@@ -96,12 +96,12 @@ public final class ConfiguredModel {
|
||||
/**
|
||||
* Construct a new {@link ConfiguredModel} with the {@link #DEFAULT_WEIGHT
|
||||
* default random weight}.
|
||||
*
|
||||
*
|
||||
* @param model the underlying model
|
||||
* @param rotationX x-rotation to apply to the model
|
||||
* @param rotationY y-rotation to apply to the model
|
||||
* @param uvLock if uvlock should be enabled
|
||||
*
|
||||
*
|
||||
* @throws NullPointerException if {@code model} is {@code null}
|
||||
* @throws IllegalArgumentException if x and/or y rotation are not valid (see
|
||||
* {@link BlockModelRotation})
|
||||
@@ -113,7 +113,7 @@ public final class ConfiguredModel {
|
||||
/**
|
||||
* Construct a new {@link ConfiguredModel} with the default rotation (0, 0),
|
||||
* uvlock (false), and {@link #DEFAULT_WEIGHT default random weight}.
|
||||
*
|
||||
*
|
||||
* @throws NullPointerException if {@code model} is {@code null}
|
||||
*/
|
||||
public ConfiguredModel(ModelFile model) {
|
||||
@@ -144,7 +144,7 @@ public final class ConfiguredModel {
|
||||
|
||||
/**
|
||||
* Create a new unowned {@link Builder}.
|
||||
*
|
||||
*
|
||||
* @return the builder
|
||||
* @see Builder
|
||||
*/
|
||||
@@ -197,7 +197,7 @@ public final class ConfiguredModel {
|
||||
|
||||
/**
|
||||
* Set the underlying model object for this configured model.
|
||||
*
|
||||
*
|
||||
* @param model the model
|
||||
* @return this builder
|
||||
* @throws NullPointerException if {@code model} is {@code null}
|
||||
@@ -210,7 +210,7 @@ public final class ConfiguredModel {
|
||||
|
||||
/**
|
||||
* Set the x-rotation for this model.
|
||||
*
|
||||
*
|
||||
* @param value the x-rotation value
|
||||
* @return this builder
|
||||
* @throws IllegalArgumentException if {@code value} is not a valid x-rotation
|
||||
@@ -224,7 +224,7 @@ public final class ConfiguredModel {
|
||||
|
||||
/**
|
||||
* Set the y-rotation for this model.
|
||||
*
|
||||
*
|
||||
* @param value the y-rotation value
|
||||
* @return this builder
|
||||
* @throws IllegalArgumentException if {@code value} is not a valid y-rotation
|
||||
@@ -243,7 +243,7 @@ public final class ConfiguredModel {
|
||||
|
||||
/**
|
||||
* Set the random weight for this model.
|
||||
*
|
||||
*
|
||||
* @param value the weight value
|
||||
* @return this builder
|
||||
* @throws IllegalArgumentException if {@code value} is less than or equal to
|
||||
@@ -258,7 +258,7 @@ public final class ConfiguredModel {
|
||||
/**
|
||||
* Build the most recent model, as if {@link #nextModel()} was never called.
|
||||
* Useful for single-model builders.
|
||||
*
|
||||
*
|
||||
* @return the most recently configured model
|
||||
*/
|
||||
public ConfiguredModel buildLast() {
|
||||
@@ -267,7 +267,7 @@ public final class ConfiguredModel {
|
||||
|
||||
/**
|
||||
* Build all configured models and return them as an array.
|
||||
*
|
||||
*
|
||||
* @return the array of built models.
|
||||
*/
|
||||
public ConfiguredModel[] build() {
|
||||
@@ -284,7 +284,7 @@ public final class ConfiguredModel {
|
||||
* <li>{@link PartialBlockstate#modelForState()}</li>
|
||||
* <li>{@link MultiPartBlockStateBuilder#part()}</li>
|
||||
* </ul>
|
||||
*
|
||||
*
|
||||
* @return the owning builder object
|
||||
* @throws NullPointerException if there is no owning builder (and thus no callback)
|
||||
*/
|
||||
@@ -296,7 +296,7 @@ public final class ConfiguredModel {
|
||||
/**
|
||||
* Complete the current model and return a new builder instance with the same
|
||||
* callback, and storing all previously built models.
|
||||
*
|
||||
*
|
||||
* @return a new builder for configuring the next model
|
||||
*/
|
||||
public Builder<T> nextModel() {
|
||||
|
||||
@@ -5,12 +5,14 @@
|
||||
|
||||
package net.minecraftforge.client.model.generators;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Stub class to extend for item model data providers, eliminates some
|
||||
@@ -24,7 +26,7 @@ public abstract class ItemModelProvider extends ModelProvider<ItemModelBuilder>
|
||||
|
||||
public ItemModelBuilder basicItem(Item item)
|
||||
{
|
||||
return basicItem(item.getRegistryName());
|
||||
return basicItem(Objects.requireNonNull(ForgeRegistries.ITEMS.getKey(item)));
|
||||
}
|
||||
|
||||
public ItemModelBuilder basicItem(ResourceLocation item)
|
||||
@@ -34,7 +36,7 @@ public abstract class ItemModelProvider extends ModelProvider<ItemModelBuilder>
|
||||
.texture("layer0", new ResourceLocation(item.getNamespace(), "item/" + item.getPath()));
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Item Models: " + modid;
|
||||
|
||||
@@ -15,8 +15,6 @@ import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.gson.Gson;
|
||||
@@ -28,7 +26,6 @@ import net.minecraft.client.renderer.block.model.BlockModel.GuiLight;
|
||||
import net.minecraft.client.renderer.block.model.BlockElement;
|
||||
import net.minecraft.client.renderer.block.model.BlockElementFace;
|
||||
import net.minecraft.client.renderer.block.model.BlockElementRotation;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransforms.TransformType;
|
||||
import net.minecraft.client.renderer.block.model.ItemTransform;
|
||||
import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite;
|
||||
@@ -37,6 +34,7 @@ import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* General purpose model builder, contains all the commonalities between item
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.google.common.base.Preconditions;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.HashCache;
|
||||
import net.minecraft.data.DataProvider;
|
||||
@@ -373,17 +374,17 @@ public abstract class ModelProvider<T extends ModelBuilder<T>> implements DataPr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(HashCache cache) throws IOException {
|
||||
public void run(CachedOutput cache) throws IOException {
|
||||
clear();
|
||||
registerModels();
|
||||
generateAll(cache);
|
||||
}
|
||||
|
||||
protected void generateAll(HashCache cache) {
|
||||
protected void generateAll(CachedOutput cache) {
|
||||
for (T model : generatedModels.values()) {
|
||||
Path target = getPath(model);
|
||||
try {
|
||||
DataProvider.save(GSON, cache, model.toJson(), target);
|
||||
DataProvider.saveStable(cache, model.toJson(), target);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Loaded 100 of 1485 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user