mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 18:45:09 +00:00
1.20.2-pre1
This commit is contained in:
368 files changed
+3555
-6356
No files matched your search
@@ -5,8 +5,7 @@
|
||||
|
||||
package net.minecraftforge.client;
|
||||
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
@@ -32,30 +31,26 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* overrides for {@link CommandSourceStack} so that the methods will run successfully client side
|
||||
*/
|
||||
public class ClientCommandSourceStack extends CommandSourceStack
|
||||
{
|
||||
|
||||
public ClientCommandSourceStack(CommandSource source, Vec3 position, Vec2 rotation, int permission, String plainTextName, Component displayName,
|
||||
Entity executing)
|
||||
{
|
||||
public class ClientCommandSourceStack extends CommandSourceStack {
|
||||
public ClientCommandSourceStack(CommandSource source, Vec3 position, Vec2 rotation, int permission, String plainTextName, Component displayName, Entity executing) {
|
||||
super(source, position, rotation, null, permission, plainTextName, displayName, null, executing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a success message without attempting to get the server side list of admins
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public void sendSuccess(Supplier<Component> message, boolean sendToAdmins)
|
||||
{
|
||||
public void sendSuccess(Supplier<Component> message, boolean sendToAdmins) {
|
||||
Minecraft.getInstance().player.sendSystemMessage(message.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the list of teams from the client side}
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public Collection<String> getAllTeams()
|
||||
{
|
||||
public Collection<String> getAllTeams() {
|
||||
return Minecraft.getInstance().level.getScoreboard().getTeamNames();
|
||||
}
|
||||
|
||||
@@ -63,8 +58,7 @@ public class ClientCommandSourceStack extends CommandSourceStack
|
||||
* {@return the list of online player names from the client side}
|
||||
*/
|
||||
@Override
|
||||
public Collection<String> getOnlinePlayerNames()
|
||||
{
|
||||
public Collection<String> getOnlinePlayerNames() {
|
||||
return Minecraft.getInstance().getConnection().getOnlinePlayers().stream().map((player) -> player.getProfile().getName()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -72,8 +66,7 @@ public class ClientCommandSourceStack extends CommandSourceStack
|
||||
* {@return a {@link Stream} of recipe ids that are available on the client}
|
||||
*/
|
||||
@Override
|
||||
public Stream<ResourceLocation> getRecipeNames()
|
||||
{
|
||||
public Stream<ResourceLocation> getRecipeNames() {
|
||||
return Minecraft.getInstance().getConnection().getRecipeManager().getRecipeIds();
|
||||
}
|
||||
|
||||
@@ -81,8 +74,7 @@ public class ClientCommandSourceStack extends CommandSourceStack
|
||||
* {@return a set of {@link ResourceKey} for levels from the client side}
|
||||
*/
|
||||
@Override
|
||||
public Set<ResourceKey<Level>> levels()
|
||||
{
|
||||
public Set<ResourceKey<Level>> levels() {
|
||||
return Minecraft.getInstance().getConnection().levels();
|
||||
}
|
||||
|
||||
@@ -90,17 +82,16 @@ public class ClientCommandSourceStack extends CommandSourceStack
|
||||
* {@return the {@link RegistryAccess} from the client side}
|
||||
*/
|
||||
@Override
|
||||
public RegistryAccess registryAccess()
|
||||
{
|
||||
public RegistryAccess registryAccess() {
|
||||
return Minecraft.getInstance().getConnection().registryAccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the scoreboard from the client side}
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public Scoreboard getScoreboard()
|
||||
{
|
||||
public Scoreboard getScoreboard() {
|
||||
return Minecraft.getInstance().level.getScoreboard();
|
||||
}
|
||||
|
||||
@@ -108,26 +99,24 @@ public class ClientCommandSourceStack extends CommandSourceStack
|
||||
* {@return the advancement from the id from the client side where the advancement needs to be visible to the player}
|
||||
*/
|
||||
@Override
|
||||
public Advancement getAdvancement(ResourceLocation id)
|
||||
{
|
||||
return Minecraft.getInstance().getConnection().getAdvancements().getAdvancements().get(id);
|
||||
public AdvancementHolder getAdvancement(ResourceLocation id) {
|
||||
return Minecraft.getInstance().getConnection().getAdvancements().get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the {@link RecipeManager} from the client side}
|
||||
*/
|
||||
@Override
|
||||
public RecipeManager getRecipeManager()
|
||||
{
|
||||
public RecipeManager getRecipeManager() {
|
||||
return Minecraft.getInstance().getConnection().getRecipeManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level from the client side}
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
@Override
|
||||
public Level getUnsidedLevel()
|
||||
{
|
||||
public Level getUnsidedLevel() {
|
||||
return Minecraft.getInstance().level;
|
||||
}
|
||||
|
||||
@@ -136,8 +125,7 @@ public class ClientCommandSourceStack extends CommandSourceStack
|
||||
* because the server isn't available on the client
|
||||
*/
|
||||
@Override
|
||||
public MinecraftServer getServer()
|
||||
{
|
||||
public MinecraftServer getServer() {
|
||||
throw new UnsupportedOperationException("Attempted to get server in client command");
|
||||
}
|
||||
|
||||
@@ -146,9 +134,7 @@ public class ClientCommandSourceStack extends CommandSourceStack
|
||||
* because the server side level isn't available on the client side
|
||||
*/
|
||||
@Override
|
||||
public ServerLevel getLevel()
|
||||
{
|
||||
public ServerLevel getLevel() {
|
||||
throw new UnsupportedOperationException("Attempted to get server level in client command");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -85,6 +85,7 @@ import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceMetadata;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
@@ -280,20 +281,10 @@ public class ForgeHooksClient
|
||||
}
|
||||
}
|
||||
|
||||
public static void dispatchRenderStage(RenderLevelStageEvent.Stage stage, LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, Camera camera, Frustum frustum)
|
||||
{
|
||||
var mc = Minecraft.getInstance();
|
||||
var profiler = mc.getProfiler();
|
||||
profiler.push(stage.toString());
|
||||
MinecraftForge.EVENT_BUS.post(new RenderLevelStageEvent(stage, levelRenderer, poseStack, projectionMatrix, renderTick, mc.getPartialTick(), camera, frustum));
|
||||
profiler.pop();
|
||||
}
|
||||
|
||||
public static void dispatchRenderStage(RenderType renderType, LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, Camera camera, Frustum frustum)
|
||||
{
|
||||
public static void dispatchRenderStage(RenderType renderType, LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, Camera camera, Frustum frustum) {
|
||||
RenderLevelStageEvent.Stage stage = RenderLevelStageEvent.Stage.fromRenderType(renderType);
|
||||
if (stage != null)
|
||||
dispatchRenderStage(stage, levelRenderer, poseStack, projectionMatrix, renderTick, camera, frustum);
|
||||
stage.dispatch(levelRenderer, poseStack, projectionMatrix, renderTick, camera, frustum);
|
||||
}
|
||||
|
||||
public static boolean renderSpecificFirstPersonHand(InteractionHand hand, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, float partialTick, float interpPitch, float swingProgress, float equipProgress, ItemStack stack)
|
||||
@@ -619,62 +610,6 @@ public class ForgeHooksClient
|
||||
MinecraftForge.EVENT_BUS.post(new MovementInputUpdateEvent(player, movementInput));
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseClickedPre(Screen guiScreen, double mouseX, double mouseY, int button)
|
||||
{
|
||||
Event event = new ScreenEvent.MouseButtonPressed.Pre(guiScreen, mouseX, mouseY, button);
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseClickedPost(Screen guiScreen, double mouseX, double mouseY, int button, boolean handled)
|
||||
{
|
||||
Event event = new ScreenEvent.MouseButtonPressed.Post(guiScreen, mouseX, mouseY, button, handled);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult() == Event.Result.DEFAULT ? handled : event.getResult() == Event.Result.ALLOW;
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseReleasedPre(Screen guiScreen, double mouseX, double mouseY, int button)
|
||||
{
|
||||
Event event = new ScreenEvent.MouseButtonReleased.Pre(guiScreen, mouseX, mouseY, button);
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseReleasedPost(Screen guiScreen, double mouseX, double mouseY, int button, boolean handled)
|
||||
{
|
||||
Event event = new ScreenEvent.MouseButtonReleased.Post(guiScreen, mouseX, mouseY, button, handled);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return event.getResult() == Event.Result.DEFAULT ? handled : event.getResult() == Event.Result.ALLOW;
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseDragPre(Screen guiScreen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY)
|
||||
{
|
||||
Event event = new ScreenEvent.MouseDragged.Pre(guiScreen, mouseX, mouseY, mouseButton, dragX, dragY);
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onScreenMouseDragPost(Screen guiScreen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY)
|
||||
{
|
||||
Event event = new ScreenEvent.MouseDragged.Post(guiScreen, mouseX, mouseY, mouseButton, dragX, dragY);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onScreenMouseScrollPre(MouseHandler mouseHelper, Screen guiScreen, double scrollDelta)
|
||||
{
|
||||
Window mainWindow = guiScreen.getMinecraft().getWindow();
|
||||
double mouseX = mouseHelper.xpos() * (double) mainWindow.getGuiScaledWidth() / (double) mainWindow.getScreenWidth();
|
||||
double mouseY = mouseHelper.ypos() * (double) mainWindow.getGuiScaledHeight() / (double) mainWindow.getScreenHeight();
|
||||
Event event = new ScreenEvent.MouseScrolled.Pre(guiScreen, mouseX, mouseY, scrollDelta);
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onScreenMouseScrollPost(MouseHandler mouseHelper, Screen guiScreen, double scrollDelta)
|
||||
{
|
||||
Window mainWindow = guiScreen.getMinecraft().getWindow();
|
||||
double mouseX = mouseHelper.xpos() * (double) mainWindow.getGuiScaledWidth() / (double) mainWindow.getScreenWidth();
|
||||
double mouseY = mouseHelper.ypos() * (double) mainWindow.getGuiScaledHeight() / (double) mainWindow.getScreenHeight();
|
||||
Event event = new ScreenEvent.MouseScrolled.Post(guiScreen, mouseX, mouseY, scrollDelta);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onScreenKeyPressedPre(Screen guiScreen, int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
Event event = new ScreenEvent.KeyPressed.Pre(guiScreen, keyCode, scanCode, modifiers);
|
||||
@@ -717,22 +652,6 @@ public class ForgeHooksClient
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static boolean onMouseButtonPre(int button, int action, int mods)
|
||||
{
|
||||
return MinecraftForge.EVENT_BUS.post(new InputEvent.MouseButton.Pre(button, action, mods));
|
||||
}
|
||||
|
||||
public static void onMouseButtonPost(int button, int action, int mods)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new InputEvent.MouseButton.Post(button, action, mods));
|
||||
}
|
||||
|
||||
public static boolean onMouseScroll(MouseHandler mouseHelper, double scrollDelta)
|
||||
{
|
||||
Event event = new InputEvent.MouseScrollingEvent(scrollDelta, mouseHelper.isLeftPressed(), mouseHelper.isMiddlePressed(), mouseHelper.isRightPressed(), mouseHelper.xpos(), mouseHelper.ypos());
|
||||
return MinecraftForge.EVENT_BUS.post(event);
|
||||
}
|
||||
|
||||
public static void onKeyInput(int key, int scanCode, int action, int modifiers)
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new InputEvent.Key(key, scanCode, action, modifiers));
|
||||
@@ -770,21 +689,11 @@ public class ForgeHooksClient
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SpriteContents loadSpriteContents(
|
||||
ResourceLocation name,
|
||||
Resource resource,
|
||||
FrameSize frameSize,
|
||||
NativeImage image,
|
||||
AnimationMetadataSection animationMeta
|
||||
)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static SpriteContents loadSpriteContents(ResourceLocation name, Resource resource, FrameSize frameSize, NativeImage image, ResourceMetadata animationMeta) {
|
||||
try {
|
||||
ForgeTextureMetadata forgeMeta = ForgeTextureMetadata.forResource(resource);
|
||||
return forgeMeta.getLoader() == null ? null : forgeMeta.getLoader().loadContents(name, resource, frameSize, image, animationMeta, forgeMeta);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Unable to get Forge metadata for {}, falling back to vanilla loading", name);
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import net.minecraft.client.RecipeBookCategories;
|
||||
import net.minecraft.world.inventory.RecipeBookType;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraftforge.client.event.RegisterRecipeBookCategoriesEvent;
|
||||
import net.minecraftforge.fml.ModLoader;
|
||||
@@ -39,10 +40,10 @@ public final class RecipeBookManager
|
||||
* Finds the category the specified recipe should display in, or null if none.
|
||||
*/
|
||||
@Nullable
|
||||
public static <T extends Recipe<?>> RecipeBookCategories findCategories(RecipeType<T> type, T recipe)
|
||||
public static <T extends Recipe<?>> RecipeBookCategories findCategories(RecipeType<T> type, RecipeHolder<T> recipe)
|
||||
{
|
||||
var lookup = RECIPE_CATEGORY_LOOKUPS.get(type);
|
||||
return lookup != null ? lookup.apply(recipe) : null;
|
||||
return lookup != null ? lookup.apply(recipe.value()) : null;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
|
||||
@@ -20,6 +20,7 @@ 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.client.resources.PlayerSkin;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
@@ -141,11 +142,11 @@ public abstract class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
public static class AddLayers extends EntityRenderersEvent
|
||||
{
|
||||
private final Map<EntityType<?>, EntityRenderer<?>> renderers;
|
||||
private final Map<String, EntityRenderer<? extends Player>> skinMap;
|
||||
private final Map<PlayerSkin.Model, EntityRenderer<? extends Player>> skinMap;
|
||||
private final EntityRendererProvider.Context context;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public AddLayers(Map<EntityType<?>, EntityRenderer<?>> renderers, Map<String, EntityRenderer<? extends Player>> playerRenderers, EntityRendererProvider.Context context)
|
||||
public AddLayers(Map<EntityType<?>, EntityRenderer<?>> renderers, Map<PlayerSkin.Model, EntityRenderer<? extends Player>> playerRenderers, EntityRendererProvider.Context context)
|
||||
{
|
||||
this.renderers = renderers;
|
||||
this.skinMap = playerRenderers;
|
||||
@@ -159,7 +160,7 @@ public abstract class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
* {@linkplain ModelLayers#PLAYER regular player model} and {@code slim} for the
|
||||
* {@linkplain ModelLayers#PLAYER_SLIM slim player model}.
|
||||
*/
|
||||
public Set<String> getSkins()
|
||||
public Set<PlayerSkin.Model> getSkins()
|
||||
{
|
||||
return skinMap.keySet();
|
||||
}
|
||||
@@ -174,7 +175,7 @@ public abstract class EntityRenderersEvent extends Event implements IModBusEvent
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R extends LivingEntityRenderer<? extends Player, ? extends EntityModel<? extends Player>>> R getSkin(String skinName)
|
||||
public <R extends LivingEntityRenderer<? extends Player, ? extends EntityModel<? extends Player>>> R getSkin(PlayerSkin.Model skinName)
|
||||
{
|
||||
return (R) skinMap.get(skinName);
|
||||
}
|
||||
|
||||
@@ -24,12 +24,9 @@ import org.lwjgl.glfw.GLFW;
|
||||
* @see Key
|
||||
* @see InteractionKeyMappingTriggered
|
||||
*/
|
||||
public abstract class InputEvent extends Event
|
||||
{
|
||||
public abstract class InputEvent extends Event {
|
||||
@ApiStatus.Internal
|
||||
protected InputEvent()
|
||||
{
|
||||
}
|
||||
protected InputEvent() {}
|
||||
|
||||
/**
|
||||
* Fired when a mouse button is pressed/released. Sub-events get fired {@link Pre before} and {@link Post after} this happens.
|
||||
@@ -41,15 +38,13 @@ public abstract class InputEvent extends Event
|
||||
* @see Pre
|
||||
* @see Post
|
||||
*/
|
||||
public static abstract class MouseButton extends InputEvent
|
||||
{
|
||||
public static abstract class MouseButton extends InputEvent {
|
||||
private final int button;
|
||||
private final int action;
|
||||
private final int modifiers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected MouseButton(int button, int action, int modifiers)
|
||||
{
|
||||
protected MouseButton(int button, int action, int modifiers) {
|
||||
this.button = button;
|
||||
this.action = action;
|
||||
this.modifiers = modifiers;
|
||||
@@ -61,8 +56,7 @@ public abstract class InputEvent extends Event
|
||||
* @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()
|
||||
{
|
||||
public int getButton() {
|
||||
return this.button;
|
||||
}
|
||||
|
||||
@@ -72,8 +66,7 @@ public abstract class InputEvent extends Event
|
||||
* @see InputConstants#PRESS
|
||||
* @see InputConstants#RELEASE
|
||||
*/
|
||||
public int getAction()
|
||||
{
|
||||
public int getAction() {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
@@ -88,8 +81,7 @@ public abstract class InputEvent extends Event
|
||||
* @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()
|
||||
{
|
||||
public int getModifiers() {
|
||||
return this.modifiers;
|
||||
}
|
||||
|
||||
@@ -105,11 +97,9 @@ public abstract class InputEvent extends Event
|
||||
* @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 Pre extends MouseButton
|
||||
{
|
||||
public static class Pre extends MouseButton {
|
||||
@ApiStatus.Internal
|
||||
public Pre(int button, int action, int modifiers)
|
||||
{
|
||||
public Pre(int button, int action, int modifiers) {
|
||||
super(button, action, modifiers);
|
||||
}
|
||||
}
|
||||
@@ -124,11 +114,9 @@ public abstract class InputEvent extends Event
|
||||
*
|
||||
* @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 Post extends MouseButton
|
||||
{
|
||||
public static class Post extends MouseButton {
|
||||
@ApiStatus.Internal
|
||||
public Post(int button, int action, int modifiers)
|
||||
{
|
||||
public Post(int button, int action, int modifiers) {
|
||||
super(button, action, modifiers);
|
||||
}
|
||||
}
|
||||
@@ -147,9 +135,9 @@ public abstract class InputEvent extends Event
|
||||
* @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 MouseScrollingEvent extends InputEvent
|
||||
{
|
||||
private final double scrollDelta;
|
||||
public static class MouseScrollingEvent extends InputEvent {
|
||||
private final double deltaX;
|
||||
private final double deltaY;
|
||||
private final double mouseX;
|
||||
private final double mouseY;
|
||||
private final boolean leftDown;
|
||||
@@ -157,9 +145,9 @@ public abstract class InputEvent extends Event
|
||||
private final boolean rightDown;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseScrollingEvent(double scrollDelta, boolean leftDown, boolean middleDown, boolean rightDown, double mouseX, double mouseY)
|
||||
{
|
||||
this.scrollDelta = scrollDelta;
|
||||
public MouseScrollingEvent(double deltaX, double deltaY, boolean leftDown, boolean middleDown, boolean rightDown, double mouseX, double mouseY) {
|
||||
this.deltaX = deltaX;
|
||||
this.deltaY = deltaY;
|
||||
this.leftDown = leftDown;
|
||||
this.middleDown = middleDown;
|
||||
this.rightDown = rightDown;
|
||||
@@ -168,50 +156,51 @@ public abstract class InputEvent extends Event
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll}
|
||||
* {@return the amount of change / delta of the mouse scroll in the vertical direction}
|
||||
*/
|
||||
public double getScrollDelta()
|
||||
{
|
||||
return this.scrollDelta;
|
||||
public double getDeltaX() {
|
||||
return this.deltaX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll in the horizontal direction}
|
||||
*/
|
||||
public double getDeltaY() {
|
||||
return this.deltaY;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the left mouse button is pressed}
|
||||
*/
|
||||
public boolean isLeftDown()
|
||||
{
|
||||
public boolean isLeftDown() {
|
||||
return this.leftDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the right mouse button is pressed}
|
||||
*/
|
||||
public boolean isRightDown()
|
||||
{
|
||||
public boolean isRightDown() {
|
||||
return this.rightDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the middle mouse button is pressed}
|
||||
*/
|
||||
public boolean isMiddleDown()
|
||||
{
|
||||
public boolean isMiddleDown() {
|
||||
return this.middleDown;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X position of the mouse cursor}
|
||||
*/
|
||||
public double getMouseX()
|
||||
{
|
||||
public double getMouseX() {
|
||||
return this.mouseX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y position of the mouse cursor}
|
||||
*/
|
||||
public double getMouseY()
|
||||
{
|
||||
public double getMouseY() {
|
||||
return this.mouseY;
|
||||
}
|
||||
}
|
||||
@@ -224,16 +213,14 @@ public abstract class InputEvent extends Event
|
||||
* <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 Key extends InputEvent
|
||||
{
|
||||
public static class Key extends InputEvent {
|
||||
private final int key;
|
||||
private final int scanCode;
|
||||
private final int action;
|
||||
private final int modifiers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Key(int key, int scanCode, int action, int modifiers)
|
||||
{
|
||||
public Key(int key, int scanCode, int action, int modifiers) {
|
||||
this.key = key;
|
||||
this.scanCode = scanCode;
|
||||
this.action = action;
|
||||
@@ -247,8 +234,7 @@ public abstract class InputEvent extends Event
|
||||
* @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()
|
||||
{
|
||||
public int getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
@@ -261,8 +247,7 @@ public abstract class InputEvent extends Event
|
||||
*
|
||||
* @see InputConstants#getKey(int, int)
|
||||
*/
|
||||
public int getScanCode()
|
||||
{
|
||||
public int getScanCode() {
|
||||
return this.scanCode;
|
||||
}
|
||||
|
||||
@@ -273,8 +258,7 @@ public abstract class InputEvent extends Event
|
||||
* @see InputConstants#RELEASE
|
||||
* @see InputConstants#REPEAT
|
||||
*/
|
||||
public int getAction()
|
||||
{
|
||||
public int getAction() {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
@@ -289,8 +273,7 @@ public abstract class InputEvent extends Event
|
||||
* @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()
|
||||
{
|
||||
public int getModifiers() {
|
||||
return this.modifiers;
|
||||
}
|
||||
}
|
||||
@@ -313,16 +296,14 @@ public abstract class InputEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class InteractionKeyMappingTriggered extends InputEvent
|
||||
{
|
||||
public static class InteractionKeyMappingTriggered extends InputEvent {
|
||||
private final int button;
|
||||
private final KeyMapping keyMapping;
|
||||
private final InteractionHand hand;
|
||||
private boolean handSwing = true;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public InteractionKeyMappingTriggered(int button, KeyMapping keyMapping, InteractionHand hand)
|
||||
{
|
||||
public InteractionKeyMappingTriggered(int button, KeyMapping keyMapping, InteractionHand hand) {
|
||||
this.button = button;
|
||||
this.keyMapping = keyMapping;
|
||||
this.hand = hand;
|
||||
@@ -333,16 +314,14 @@ public abstract class InputEvent extends Event
|
||||
*
|
||||
* @param value whether to swing the hand
|
||||
*/
|
||||
public void setSwingHand(boolean value)
|
||||
{
|
||||
public void setSwingHand(boolean value) {
|
||||
handSwing = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return whether to swing the hand; always takes effect, regardless of cancellation}
|
||||
*/
|
||||
public boolean shouldSwingHand()
|
||||
{
|
||||
public boolean shouldSwingHand() {
|
||||
return handSwing;
|
||||
}
|
||||
|
||||
@@ -353,40 +332,35 @@ public abstract class InputEvent extends Event
|
||||
* of both event's cancellation.
|
||||
* Will always be {@link InteractionHand#MAIN_HAND} if this is an attack or pick block input.
|
||||
*/
|
||||
public InteractionHand getHand()
|
||||
{
|
||||
public InteractionHand getHand() {
|
||||
return hand;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the mouse button is the left mouse button}
|
||||
*/
|
||||
public boolean isAttack()
|
||||
{
|
||||
public boolean isAttack() {
|
||||
return button == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the mouse button is the right mouse button}
|
||||
*/
|
||||
public boolean isUseItem()
|
||||
{
|
||||
public boolean isUseItem() {
|
||||
return button == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return {@code true} if the mouse button is the middle mouse button}
|
||||
*/
|
||||
public boolean isPickBlock()
|
||||
{
|
||||
public boolean isPickBlock() {
|
||||
return button == 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the key mapping which triggered this event}
|
||||
*/
|
||||
public KeyMapping getKeyMapping()
|
||||
{
|
||||
public KeyMapping getKeyMapping() {
|
||||
return keyMapping;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import javax.annotation.Nullable;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.LevelRenderer;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
@@ -26,6 +27,8 @@ 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.ApiStatus;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
/**
|
||||
@@ -37,8 +40,7 @@ import org.joml.Matrix4f;
|
||||
* <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 RenderLevelStageEvent extends Event
|
||||
{
|
||||
public class RenderLevelStageEvent extends Event {
|
||||
private final Stage stage;
|
||||
private final LevelRenderer levelRenderer;
|
||||
private final PoseStack poseStack;
|
||||
@@ -48,8 +50,7 @@ public class RenderLevelStageEvent extends Event
|
||||
private final Camera camera;
|
||||
private final Frustum frustum;
|
||||
|
||||
public RenderLevelStageEvent(Stage stage, LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, float partialTick, Camera camera, Frustum frustum)
|
||||
{
|
||||
public RenderLevelStageEvent(Stage stage, LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, float partialTick, Camera camera, Frustum frustum) {
|
||||
this.stage = stage;
|
||||
this.levelRenderer = levelRenderer;
|
||||
this.poseStack = poseStack;
|
||||
@@ -64,64 +65,56 @@ public class RenderLevelStageEvent extends Event
|
||||
* {@return the current {@linkplain Stage stage} that is being rendered. Check this before doing rendering to ensure
|
||||
* that rendering happens at the appropriate time.}
|
||||
*/
|
||||
public Stage getStage()
|
||||
{
|
||||
public Stage getStage() {
|
||||
return stage;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the level renderer}
|
||||
*/
|
||||
public LevelRenderer getLevelRenderer()
|
||||
{
|
||||
public LevelRenderer getLevelRenderer() {
|
||||
return levelRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the pose stack used for rendering}
|
||||
*/
|
||||
public PoseStack getPoseStack()
|
||||
{
|
||||
public PoseStack getPoseStack() {
|
||||
return poseStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the projection matrix}
|
||||
*/
|
||||
public Matrix4f getProjectionMatrix()
|
||||
{
|
||||
public Matrix4f getProjectionMatrix() {
|
||||
return projectionMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the current "ticks" value in the {@linkplain LevelRenderer level renderer}}
|
||||
*/
|
||||
public int getRenderTick()
|
||||
{
|
||||
public int getRenderTick() {
|
||||
return renderTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the current partialTick value used for rendering}
|
||||
*/
|
||||
public float getPartialTick()
|
||||
{
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the camera}
|
||||
*/
|
||||
public Camera getCamera()
|
||||
{
|
||||
public Camera getCamera() {
|
||||
return camera;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the frustum}
|
||||
*/
|
||||
public Frustum getFrustum()
|
||||
{
|
||||
public Frustum getFrustum() {
|
||||
return frustum;
|
||||
}
|
||||
|
||||
@@ -134,8 +127,7 @@ public class RenderLevelStageEvent extends Event
|
||||
* <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 RegisterStageEvent extends Event implements IModBusEvent
|
||||
{
|
||||
public static class RegisterStageEvent extends Event implements IModBusEvent {
|
||||
/**
|
||||
* @param name The name of your Stage.
|
||||
* @param renderType
|
||||
@@ -144,8 +136,7 @@ public class RenderLevelStageEvent extends Event
|
||||
*
|
||||
* @throws IllegalArgumentException if the RenderType passed is already mapped to a Stage.
|
||||
*/
|
||||
public Stage register(ResourceLocation name, @Nullable RenderType renderType) throws IllegalArgumentException
|
||||
{
|
||||
public Stage register(ResourceLocation name, @Nullable RenderType renderType) throws IllegalArgumentException {
|
||||
return Stage.register(name, renderType);
|
||||
}
|
||||
}
|
||||
@@ -154,8 +145,7 @@ public class RenderLevelStageEvent extends Event
|
||||
* A time during level rendering for you to render custom things into the world.
|
||||
* @see RegisterStageEvent
|
||||
*/
|
||||
public static class Stage
|
||||
{
|
||||
public static class Stage {
|
||||
private static final Map<RenderType, Stage> RENDER_TYPE_STAGES = new HashMap<>();
|
||||
|
||||
/**
|
||||
@@ -215,27 +205,23 @@ public class RenderLevelStageEvent extends Event
|
||||
|
||||
private final String name;
|
||||
|
||||
private Stage(String name)
|
||||
{
|
||||
private Stage(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private static Stage register(ResourceLocation name, @Nullable RenderType renderType) throws IllegalArgumentException
|
||||
{
|
||||
private static Stage register(ResourceLocation name, @Nullable RenderType renderType) throws IllegalArgumentException {
|
||||
Stage stage = new Stage(name.toString());
|
||||
if (renderType != null && RENDER_TYPE_STAGES.putIfAbsent(renderType, stage) != null)
|
||||
throw new IllegalArgumentException("Attempted to replace an existing RenderLevelStageEvent.Stage for a RenderType: Stage = " + stage + ", RenderType = " + renderType);
|
||||
return stage;
|
||||
}
|
||||
|
||||
private static Stage register(String name, @Nullable RenderType renderType) throws IllegalArgumentException
|
||||
{
|
||||
private static Stage register(String name, @Nullable RenderType renderType) throws IllegalArgumentException {
|
||||
return register(new ResourceLocation(name), renderType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
public String toString() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@@ -243,9 +229,18 @@ public class RenderLevelStageEvent extends Event
|
||||
* {@return the {@linkplain Stage stage} bound to the {@linkplain RenderType render type}, or null if no value is present}
|
||||
*/
|
||||
@Nullable
|
||||
public static Stage fromRenderType(RenderType renderType)
|
||||
{
|
||||
public static Stage fromRenderType(RenderType renderType) {
|
||||
return RENDER_TYPE_STAGES.get(renderType);
|
||||
}
|
||||
|
||||
/** Internal just to make our patch smaller, it just fires the event. If you have good reason for this to be external, ask. */
|
||||
@ApiStatus.Internal
|
||||
public void dispatch(LevelRenderer levelRenderer, PoseStack poseStack, Matrix4f projectionMatrix, int renderTick, Camera camera, Frustum frustum) {
|
||||
var mc = Minecraft.getInstance();
|
||||
var profiler = mc.getProfiler();
|
||||
profiler.push(this.toString());
|
||||
MinecraftForge.EVENT_BUS.post(new RenderLevelStageEvent(this, levelRenderer, poseStack, projectionMatrix, renderTick, mc.getPartialTick(), camera, frustum));
|
||||
profiler.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,21 +39,18 @@ import java.util.function.Consumer;
|
||||
* @see KeyInput
|
||||
*/
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public abstract class ScreenEvent extends Event
|
||||
{
|
||||
public abstract class ScreenEvent extends Event {
|
||||
private final Screen screen;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected ScreenEvent(Screen screen)
|
||||
{
|
||||
protected ScreenEvent(Screen screen) {
|
||||
this.screen = Objects.requireNonNull(screen);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the screen that caused this event}
|
||||
*/
|
||||
public Screen getScreen()
|
||||
{
|
||||
public Screen getScreen() {
|
||||
return screen;
|
||||
}
|
||||
|
||||
@@ -68,16 +65,14 @@ public abstract class ScreenEvent extends Event
|
||||
* @see Init.Pre
|
||||
* @see Init.Post
|
||||
*/
|
||||
public static abstract class Init extends ScreenEvent
|
||||
{
|
||||
public static abstract class Init extends ScreenEvent {
|
||||
private final Consumer<GuiEventListener> add;
|
||||
private final Consumer<GuiEventListener> remove;
|
||||
|
||||
private final List<GuiEventListener> listenerList;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected Init(Screen screen, List<GuiEventListener> listenerList, Consumer<GuiEventListener> add, Consumer<GuiEventListener> remove)
|
||||
{
|
||||
protected Init(Screen screen, List<GuiEventListener> listenerList, Consumer<GuiEventListener> add, Consumer<GuiEventListener> remove) {
|
||||
super(screen);
|
||||
this.listenerList = Collections.unmodifiableList(listenerList);
|
||||
this.add = add;
|
||||
@@ -87,8 +82,7 @@ public abstract class ScreenEvent extends Event
|
||||
/**
|
||||
* {@return unmodifiable view of list of event listeners on the screen}
|
||||
*/
|
||||
public List<GuiEventListener> getListenersList()
|
||||
{
|
||||
public List<GuiEventListener> getListenersList() {
|
||||
return listenerList;
|
||||
}
|
||||
|
||||
@@ -97,8 +91,7 @@ public abstract class ScreenEvent extends Event
|
||||
*
|
||||
* @param listener the listener to add
|
||||
*/
|
||||
public void addListener(GuiEventListener listener)
|
||||
{
|
||||
public void addListener(GuiEventListener listener) {
|
||||
add.accept(listener);
|
||||
}
|
||||
|
||||
@@ -107,8 +100,7 @@ public abstract class ScreenEvent extends Event
|
||||
*
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public void removeListener(GuiEventListener listener)
|
||||
{
|
||||
public void removeListener(GuiEventListener listener) {
|
||||
remove.accept(listener);
|
||||
}
|
||||
|
||||
@@ -123,11 +115,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends Init
|
||||
{
|
||||
public static class Pre extends Init {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, List<GuiEventListener> list, Consumer<GuiEventListener> add, Consumer<GuiEventListener> remove)
|
||||
{
|
||||
public Pre(Screen screen, List<GuiEventListener> list, Consumer<GuiEventListener> add, Consumer<GuiEventListener> remove) {
|
||||
super(screen, list, add, remove);
|
||||
}
|
||||
}
|
||||
@@ -140,11 +130,9 @@ public abstract class ScreenEvent extends Event
|
||||
* <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 Init
|
||||
{
|
||||
public static class Post extends Init {
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, List<GuiEventListener> list, Consumer<GuiEventListener> add, Consumer<GuiEventListener> remove)
|
||||
{
|
||||
public Post(Screen screen, List<GuiEventListener> list, Consumer<GuiEventListener> add, Consumer<GuiEventListener> remove) {
|
||||
super(screen, list, add, remove);
|
||||
}
|
||||
}
|
||||
@@ -157,16 +145,14 @@ public abstract class ScreenEvent extends Event
|
||||
* @see Render.Pre
|
||||
* @see Render.Post
|
||||
*/
|
||||
public static abstract class Render extends ScreenEvent
|
||||
{
|
||||
public static abstract class Render extends ScreenEvent {
|
||||
private final GuiGraphics guiGraphics;
|
||||
private final int mouseX;
|
||||
private final int mouseY;
|
||||
private final float partialTick;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected Render(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
protected Render(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
super(screen);
|
||||
this.guiGraphics = guiGraphics;
|
||||
this.mouseX = mouseX;
|
||||
@@ -177,32 +163,28 @@ public abstract class ScreenEvent extends Event
|
||||
/**
|
||||
* {@return the gui graphics used for rendering}
|
||||
*/
|
||||
public GuiGraphics getGuiGraphics()
|
||||
{
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the X coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseX()
|
||||
{
|
||||
public int getMouseX() {
|
||||
return mouseX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y coordinate of the mouse pointer}
|
||||
*/
|
||||
public int getMouseY()
|
||||
{
|
||||
public int getMouseY() {
|
||||
return mouseY;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the partial tick}
|
||||
*/
|
||||
public float getPartialTick()
|
||||
{
|
||||
public float getPartialTick() {
|
||||
return partialTick;
|
||||
}
|
||||
|
||||
@@ -216,11 +198,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends Render
|
||||
{
|
||||
public static class Pre extends Render {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
public Pre(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
super(screen, guiGraphics, mouseX, mouseY, partialTick);
|
||||
}
|
||||
}
|
||||
@@ -233,11 +213,9 @@ public abstract class ScreenEvent extends Event
|
||||
* <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 Render
|
||||
{
|
||||
public static class Post extends Render {
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
public Post(Screen screen, GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
super(screen, guiGraphics, mouseX, mouseY, partialTick);
|
||||
}
|
||||
}
|
||||
@@ -252,13 +230,11 @@ public abstract class ScreenEvent extends Event
|
||||
* <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 BackgroundRendered extends ScreenEvent
|
||||
{
|
||||
public static class BackgroundRendered extends ScreenEvent {
|
||||
private final GuiGraphics guiGraphics;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public BackgroundRendered(Screen screen, GuiGraphics guiGraphics)
|
||||
{
|
||||
public BackgroundRendered(Screen screen, GuiGraphics guiGraphics) {
|
||||
super(screen);
|
||||
this.guiGraphics = guiGraphics;
|
||||
}
|
||||
@@ -266,8 +242,7 @@ public abstract class ScreenEvent extends Event
|
||||
/**
|
||||
* {@return the gui graphics used for rendering}
|
||||
*/
|
||||
public GuiGraphics getGuiGraphics()
|
||||
{
|
||||
public GuiGraphics getGuiGraphics() {
|
||||
return guiGraphics;
|
||||
}
|
||||
}
|
||||
@@ -284,15 +259,13 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class RenderInventoryMobEffects extends ScreenEvent
|
||||
{
|
||||
public static class RenderInventoryMobEffects extends ScreenEvent {
|
||||
private final int availableSpace;
|
||||
private boolean compact;
|
||||
private int horizontalOffset;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public RenderInventoryMobEffects(Screen screen, int availableSpace, boolean compact, int horizontalOffset)
|
||||
{
|
||||
public RenderInventoryMobEffects(Screen screen, int availableSpace, boolean compact, int horizontalOffset) {
|
||||
super(screen);
|
||||
this.availableSpace = availableSpace;
|
||||
this.compact = compact;
|
||||
@@ -302,48 +275,42 @@ public abstract class ScreenEvent extends Event
|
||||
/**
|
||||
* The available space to the right of the inventory.
|
||||
*/
|
||||
public int getAvailableSpace()
|
||||
{
|
||||
public int getAvailableSpace() {
|
||||
return availableSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the effects should be rendered in compact mode (only icons, no text), or the default full size.
|
||||
*/
|
||||
public boolean isCompact()
|
||||
{
|
||||
public boolean isCompact() {
|
||||
return compact;
|
||||
}
|
||||
|
||||
/**
|
||||
* The distance from the left side of the screen that the effect stack is rendered. Positive values shift this more to the right.
|
||||
*/
|
||||
public int getHorizontalOffset()
|
||||
{
|
||||
public int getHorizontalOffset() {
|
||||
return horizontalOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the horizontal offset of the effect stack
|
||||
*/
|
||||
public void setHorizontalOffset(int offset)
|
||||
{
|
||||
public void setHorizontalOffset(int offset) {
|
||||
horizontalOffset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds to the horizontal offset of the effect stack. Negative values are acceptable.
|
||||
*/
|
||||
public void addHorizontalOffset(int offset)
|
||||
{
|
||||
public void addHorizontalOffset(int offset) {
|
||||
horizontalOffset += offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether the effects should be rendered in compact mode (only icons, no text), or the default full size.
|
||||
*/
|
||||
public void setCompact(boolean compact)
|
||||
{
|
||||
public void setCompact(boolean compact) {
|
||||
this.compact = compact;
|
||||
}
|
||||
}
|
||||
@@ -357,14 +324,12 @@ public abstract class ScreenEvent extends Event
|
||||
* @see MouseDragged
|
||||
* @see MouseScrolled
|
||||
*/
|
||||
private static abstract class MouseInput extends ScreenEvent
|
||||
{
|
||||
private static abstract class MouseInput extends ScreenEvent {
|
||||
private final double mouseX;
|
||||
private final double mouseY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected MouseInput(Screen screen, double mouseX, double mouseY)
|
||||
{
|
||||
protected MouseInput(Screen screen, double mouseX, double mouseY) {
|
||||
super(screen);
|
||||
this.mouseX = mouseX;
|
||||
this.mouseY = mouseY;
|
||||
@@ -373,16 +338,14 @@ public abstract class ScreenEvent extends Event
|
||||
/**
|
||||
* {@return the X position of the mouse cursor, relative to the screen}
|
||||
*/
|
||||
public double getMouseX()
|
||||
{
|
||||
public double getMouseX() {
|
||||
return mouseX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the Y position of the mouse cursor, relative to the screen}
|
||||
*/
|
||||
public double getMouseY()
|
||||
{
|
||||
public double getMouseY() {
|
||||
return mouseY;
|
||||
}
|
||||
}
|
||||
@@ -394,13 +357,11 @@ public abstract class ScreenEvent extends Event
|
||||
* @see MouseButtonPressed.Pre
|
||||
* @see MouseButtonPressed.Post
|
||||
*/
|
||||
public static abstract class MouseButtonPressed extends MouseInput
|
||||
{
|
||||
public static abstract class MouseButtonPressed extends MouseInput {
|
||||
private final int button;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseButtonPressed(Screen screen, double mouseX, double mouseY, int button)
|
||||
{
|
||||
public MouseButtonPressed(Screen screen, double mouseX, double mouseY, int button) {
|
||||
super(screen, mouseX, mouseY);
|
||||
this.button = button;
|
||||
}
|
||||
@@ -411,8 +372,7 @@ public abstract class ScreenEvent extends Event
|
||||
* @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()
|
||||
{
|
||||
public int getButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -427,11 +387,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends MouseButtonPressed
|
||||
{
|
||||
public static class Pre extends MouseButtonPressed {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int button)
|
||||
{
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int button) {
|
||||
super(screen, mouseX, mouseY, button);
|
||||
}
|
||||
}
|
||||
@@ -452,13 +410,11 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@HasResult
|
||||
public static class Post extends MouseButtonPressed
|
||||
{
|
||||
public static class Post extends MouseButtonPressed {
|
||||
private final boolean handled;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, double mouseX, double mouseY, int button, boolean handled)
|
||||
{
|
||||
public Post(Screen screen, double mouseX, double mouseY, int button, boolean handled) {
|
||||
super(screen, mouseX, mouseY, button);
|
||||
this.handled = handled;
|
||||
}
|
||||
@@ -466,8 +422,7 @@ public abstract class ScreenEvent extends Event
|
||||
/**
|
||||
* {@return {@code true} if the mouse click was already handled by its screen}
|
||||
*/
|
||||
public boolean wasHandled()
|
||||
{
|
||||
public boolean wasHandled() {
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
@@ -480,13 +435,11 @@ public abstract class ScreenEvent extends Event
|
||||
* @see MouseButtonReleased.Pre
|
||||
* @see MouseButtonReleased.Post
|
||||
*/
|
||||
public static abstract class MouseButtonReleased extends MouseInput
|
||||
{
|
||||
public static abstract class MouseButtonReleased extends MouseInput {
|
||||
private final int button;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseButtonReleased(Screen screen, double mouseX, double mouseY, int button)
|
||||
{
|
||||
public MouseButtonReleased(Screen screen, double mouseX, double mouseY, int button) {
|
||||
super(screen, mouseX, mouseY);
|
||||
this.button = button;
|
||||
}
|
||||
@@ -497,8 +450,7 @@ public abstract class ScreenEvent extends Event
|
||||
* @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()
|
||||
{
|
||||
public int getButton() {
|
||||
return button;
|
||||
}
|
||||
|
||||
@@ -513,11 +465,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends MouseButtonReleased
|
||||
{
|
||||
public static class Pre extends MouseButtonReleased {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int button)
|
||||
{
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int button) {
|
||||
super(screen, mouseX, mouseY, button);
|
||||
}
|
||||
}
|
||||
@@ -538,13 +488,11 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@HasResult
|
||||
public static class Post extends MouseButtonReleased
|
||||
{
|
||||
public static class Post extends MouseButtonReleased {
|
||||
private final boolean handled;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, double mouseX, double mouseY, int button, boolean handled)
|
||||
{
|
||||
public Post(Screen screen, double mouseX, double mouseY, int button, boolean handled) {
|
||||
super(screen, mouseX, mouseY, button);
|
||||
this.handled = handled;
|
||||
}
|
||||
@@ -552,8 +500,7 @@ public abstract class ScreenEvent extends Event
|
||||
/**
|
||||
* @return {@code true} if the mouse release was already handled by its screen
|
||||
*/
|
||||
public boolean wasHandled()
|
||||
{
|
||||
public boolean wasHandled() {
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
@@ -566,15 +513,13 @@ public abstract class ScreenEvent extends Event
|
||||
* @see MouseDragged.Pre
|
||||
* @see MouseDragged.Post
|
||||
*/
|
||||
public static abstract class MouseDragged extends MouseInput
|
||||
{
|
||||
public static abstract class MouseDragged extends MouseInput {
|
||||
private final int mouseButton;
|
||||
private final double dragX;
|
||||
private final double dragY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseDragged(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY)
|
||||
{
|
||||
public MouseDragged(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY) {
|
||||
super(screen, mouseX, mouseY);
|
||||
this.mouseButton = mouseButton;
|
||||
this.dragX = dragX;
|
||||
@@ -587,24 +532,21 @@ public abstract class ScreenEvent extends Event
|
||||
* @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 getMouseButton()
|
||||
{
|
||||
public int getMouseButton() {
|
||||
return mouseButton;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return amount of mouse drag along the X axis}
|
||||
*/
|
||||
public double getDragX()
|
||||
{
|
||||
public double getDragX() {
|
||||
return dragX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return amount of mouse drag along the Y axis}
|
||||
*/
|
||||
public double getDragY()
|
||||
{
|
||||
public double getDragY() {
|
||||
return dragY;
|
||||
}
|
||||
|
||||
@@ -619,11 +561,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends MouseDragged
|
||||
{
|
||||
public static class Pre extends MouseDragged {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY)
|
||||
{
|
||||
public Pre(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY) {
|
||||
super(screen, mouseX, mouseY, mouseButton, dragX, dragY);
|
||||
}
|
||||
}
|
||||
@@ -638,11 +578,9 @@ public abstract class ScreenEvent extends Event
|
||||
* <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 MouseDragged
|
||||
{
|
||||
public static class Post extends MouseDragged {
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY)
|
||||
{
|
||||
public Post(Screen screen, double mouseX, double mouseY, int mouseButton, double dragX, double dragY) {
|
||||
super(screen, mouseX, mouseY, mouseButton, dragX, dragY);
|
||||
}
|
||||
}
|
||||
@@ -655,23 +593,29 @@ public abstract class ScreenEvent extends Event
|
||||
* @see MouseScrolled.Pre
|
||||
* @see MouseScrolled.Post
|
||||
*/
|
||||
public static abstract class MouseScrolled extends MouseInput
|
||||
{
|
||||
private final double scrollDelta;
|
||||
public static abstract class MouseScrolled extends MouseInput {
|
||||
private final double deltaX;
|
||||
private final double deltaY;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public MouseScrolled(Screen screen, double mouseX, double mouseY, double scrollDelta)
|
||||
{
|
||||
public MouseScrolled(Screen screen, double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||
super(screen, mouseX, mouseY);
|
||||
this.scrollDelta = scrollDelta;
|
||||
this.deltaX = deltaX;
|
||||
this.deltaY = deltaY;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll}
|
||||
* {@return the amount of change / delta of the mouse scroll in the vertical direction}
|
||||
*/
|
||||
public double getScrollDelta()
|
||||
{
|
||||
return scrollDelta;
|
||||
public double getDeltaX() {
|
||||
return deltaX;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the amount of change / delta of the mouse scroll in the horizontal direction}
|
||||
*/
|
||||
public double getDeltaY() {
|
||||
return deltaY;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -685,12 +629,10 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends MouseScrolled
|
||||
{
|
||||
public static class Pre extends MouseScrolled {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, double mouseX, double mouseY, double scrollDelta)
|
||||
{
|
||||
super(screen, mouseX, mouseY, scrollDelta);
|
||||
public Pre(Screen screen, double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||
super(screen, mouseX, mouseY, deltaX, deltaY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -704,12 +646,10 @@ public abstract class ScreenEvent extends Event
|
||||
* <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 MouseScrolled
|
||||
{
|
||||
public static class Post extends MouseScrolled {
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, double mouseX, double mouseY, double scrollDelta)
|
||||
{
|
||||
super(screen, mouseX, mouseY, scrollDelta);
|
||||
public Post(Screen screen, double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||
super(screen, mouseX, mouseY, deltaX, deltaY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -723,15 +663,13 @@ public abstract class ScreenEvent extends Event
|
||||
* @see InputConstants
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_key" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
private static abstract class KeyInput extends ScreenEvent
|
||||
{
|
||||
private static abstract class KeyInput extends ScreenEvent {
|
||||
private final int keyCode;
|
||||
private final int scanCode;
|
||||
private final int modifiers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
protected KeyInput(Screen screen, int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
protected KeyInput(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen);
|
||||
this.keyCode = keyCode;
|
||||
this.scanCode = scanCode;
|
||||
@@ -745,8 +683,7 @@ public abstract class ScreenEvent extends Event
|
||||
* @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 getKeyCode()
|
||||
{
|
||||
public int getKeyCode() {
|
||||
return keyCode;
|
||||
}
|
||||
|
||||
@@ -759,8 +696,7 @@ public abstract class ScreenEvent extends Event
|
||||
*
|
||||
* @see InputConstants#getKey(int, int)
|
||||
*/
|
||||
public int getScanCode()
|
||||
{
|
||||
public int getScanCode() {
|
||||
return scanCode;
|
||||
}
|
||||
|
||||
@@ -775,8 +711,7 @@ public abstract class ScreenEvent extends Event
|
||||
* @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()
|
||||
{
|
||||
public int getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
}
|
||||
@@ -788,11 +723,9 @@ public abstract class ScreenEvent extends Event
|
||||
* @see KeyPressed.Pre
|
||||
* @see KeyPressed.Post
|
||||
*/
|
||||
public static abstract class KeyPressed extends KeyInput
|
||||
{
|
||||
public static abstract class KeyPressed extends KeyInput {
|
||||
@ApiStatus.Internal
|
||||
public KeyPressed(Screen screen, int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
public KeyPressed(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@@ -807,11 +740,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends KeyPressed
|
||||
{
|
||||
public static class Pre extends KeyPressed {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
public Pre(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
}
|
||||
@@ -827,11 +758,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Post extends KeyPressed
|
||||
{
|
||||
public static class Post extends KeyPressed {
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
public Post(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
}
|
||||
@@ -844,11 +773,9 @@ public abstract class ScreenEvent extends Event
|
||||
* @see KeyReleased.Pre
|
||||
* @see KeyReleased.Post
|
||||
*/
|
||||
public static abstract class KeyReleased extends KeyInput
|
||||
{
|
||||
public static abstract class KeyReleased extends KeyInput {
|
||||
@ApiStatus.Internal
|
||||
public KeyReleased(Screen screen, int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
public KeyReleased(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
|
||||
@@ -863,11 +790,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends KeyReleased
|
||||
{
|
||||
public static class Pre extends KeyReleased {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
public Pre(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
}
|
||||
@@ -883,11 +808,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Post extends KeyReleased
|
||||
{
|
||||
public static class Post extends KeyReleased {
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
public Post(Screen screen, int keyCode, int scanCode, int modifiers) {
|
||||
super(screen, keyCode, scanCode, modifiers);
|
||||
}
|
||||
}
|
||||
@@ -901,14 +824,12 @@ public abstract class ScreenEvent extends Event
|
||||
* @see CharacterTyped.Post
|
||||
* @see <a href="https://www.glfw.org/docs/latest/input_guide.html#input_char" target="_top">the online GLFW documentation</a>
|
||||
*/
|
||||
public static class CharacterTyped extends ScreenEvent
|
||||
{
|
||||
public static class CharacterTyped extends ScreenEvent {
|
||||
private final char codePoint;
|
||||
private final int modifiers;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public CharacterTyped(Screen screen, char codePoint, int modifiers)
|
||||
{
|
||||
public CharacterTyped(Screen screen, char codePoint, int modifiers) {
|
||||
super(screen);
|
||||
this.codePoint = codePoint;
|
||||
this.modifiers = modifiers;
|
||||
@@ -917,8 +838,7 @@ public abstract class ScreenEvent extends Event
|
||||
/**
|
||||
* {@return the character code point}
|
||||
*/
|
||||
public char getCodePoint()
|
||||
{
|
||||
public char getCodePoint() {
|
||||
return codePoint;
|
||||
}
|
||||
|
||||
@@ -933,8 +853,7 @@ public abstract class ScreenEvent extends Event
|
||||
* @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()
|
||||
{
|
||||
public int getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
@@ -949,11 +868,9 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Pre extends CharacterTyped
|
||||
{
|
||||
public static class Pre extends CharacterTyped {
|
||||
@ApiStatus.Internal
|
||||
public Pre(Screen screen, char codePoint, int modifiers)
|
||||
{
|
||||
public Pre(Screen screen, char codePoint, int modifiers) {
|
||||
super(screen, codePoint, modifiers);
|
||||
}
|
||||
}
|
||||
@@ -968,11 +885,9 @@ public abstract class ScreenEvent extends Event
|
||||
* <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 CharacterTyped
|
||||
{
|
||||
public static class Post extends CharacterTyped {
|
||||
@ApiStatus.Internal
|
||||
public Post(Screen screen, char codePoint, int modifiers)
|
||||
{
|
||||
public Post(Screen screen, char codePoint, int modifiers) {
|
||||
super(screen, codePoint, modifiers);
|
||||
}
|
||||
}
|
||||
@@ -991,15 +906,13 @@ public abstract class ScreenEvent extends Event
|
||||
* only on the {@linkplain LogicalSide#CLIENT logical client}.</p>
|
||||
*/
|
||||
@Cancelable
|
||||
public static class Opening extends ScreenEvent
|
||||
{
|
||||
public static class Opening extends ScreenEvent {
|
||||
@Nullable
|
||||
private final Screen currentScreen;
|
||||
private Screen newScreen;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Opening(@Nullable Screen currentScreen, Screen screen)
|
||||
{
|
||||
public Opening(@Nullable Screen currentScreen, Screen screen) {
|
||||
super(screen);
|
||||
this.currentScreen = currentScreen;
|
||||
this.newScreen = screen;
|
||||
@@ -1011,8 +924,7 @@ public abstract class ScreenEvent extends Event
|
||||
* May be null if no screen was open.
|
||||
*/
|
||||
@Nullable
|
||||
public Screen getCurrentScreen()
|
||||
{
|
||||
public Screen getCurrentScreen() {
|
||||
return currentScreen;
|
||||
}
|
||||
|
||||
@@ -1020,16 +932,14 @@ public abstract class ScreenEvent extends Event
|
||||
* @return The screen that will be opened if the event is not cancelled. May be null.
|
||||
*/
|
||||
@Nullable
|
||||
public Screen getNewScreen()
|
||||
{
|
||||
public Screen getNewScreen() {
|
||||
return newScreen;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new screen to be opened if the event is not cancelled. May be null.
|
||||
*/
|
||||
public void setNewScreen(Screen newScreen)
|
||||
{
|
||||
public void setNewScreen(Screen newScreen) {
|
||||
this.newScreen = newScreen;
|
||||
}
|
||||
}
|
||||
@@ -1043,11 +953,9 @@ public abstract class ScreenEvent extends Event
|
||||
* <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 Closing extends ScreenEvent
|
||||
{
|
||||
public static class Closing extends ScreenEvent {
|
||||
@ApiStatus.Internal
|
||||
public Closing(Screen screen)
|
||||
{
|
||||
public Closing(Screen screen) {
|
||||
super(screen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,63 +136,4 @@ public interface IForgeGuiGraphics
|
||||
|
||||
self().blit(texture, x, y, boundsWidth, boundsHeight, 0.0f,0.0f, rectWidth, rectHeight, rectWidth, rectHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Version of {@link GuiGraphics#blitNineSliced(ResourceLocation, int, int, int, int, int, int, int, int, int)} that supports specifying the texture's size.
|
||||
*/
|
||||
default void blitNineSlicedSized(ResourceLocation texture, int x, int y, int width, int height, int sliceSize, int uWidth, int vHeight, int uOffset, int vOffset,
|
||||
int textureWidth, int textureHeight)
|
||||
{
|
||||
blitNineSlicedSized(texture, x, y, width, height, sliceSize, sliceSize, uWidth, vHeight, uOffset, vOffset, textureWidth, textureHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Version of {@link GuiGraphics#blitNineSliced(ResourceLocation, int, int, int, int, int, int, int, int, int, int)} that supports specifying the texture's size.
|
||||
*/
|
||||
default void blitNineSlicedSized(ResourceLocation texture, int x, int y, int width, int height, int sliceWidth, int sliceHeight, int uWidth, int vHeight,
|
||||
int uOffset, int vOffset, int textureWidth, int textureHeight)
|
||||
{
|
||||
blitNineSlicedSized(texture, x, y, width, height, sliceWidth, sliceHeight, sliceWidth, sliceHeight, uWidth, vHeight, uOffset, vOffset, textureWidth, textureHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* Version of {@link GuiGraphics#blitNineSliced(ResourceLocation, int, int, int, int, int, int, int, int, int, int, int, int)} that supports specifying the texture's size.
|
||||
*/
|
||||
default void blitNineSlicedSized(ResourceLocation texture, int x, int y, int width, int height, int cornerWidth, int cornerHeight, int edgeWidth, int edgeHeight,
|
||||
int uWidth, int vHeight, int uOffset, int vOffset, int textureWidth, int textureHeight)
|
||||
{
|
||||
cornerWidth = Math.min(cornerWidth, width / 2);
|
||||
edgeWidth = Math.min(edgeWidth, width / 2);
|
||||
cornerHeight = Math.min(cornerHeight, height / 2);
|
||||
edgeHeight = Math.min(edgeHeight, height / 2);
|
||||
GuiGraphics self = self();
|
||||
if (width == uWidth && height == vHeight)
|
||||
{
|
||||
self.blit(texture, x, y, uOffset, vOffset, width, height, textureWidth, textureHeight);
|
||||
}
|
||||
else if (height == vHeight)
|
||||
{
|
||||
self.blit(texture, x, y, uOffset, vOffset, cornerWidth, height, textureWidth, textureHeight);
|
||||
self.blitRepeating(texture, x + cornerWidth, y, width - edgeWidth - cornerWidth, height, uOffset + cornerWidth, vOffset, uWidth - edgeWidth - cornerWidth, vHeight, textureWidth, textureHeight);
|
||||
self.blit(texture, x + width - edgeWidth, y, uOffset + uWidth - edgeWidth, vOffset, edgeWidth, height, textureWidth, textureHeight);
|
||||
}
|
||||
else if (width == uWidth)
|
||||
{
|
||||
self.blit(texture, x, y, uOffset, vOffset, width, cornerHeight, textureWidth, textureHeight);
|
||||
self.blitRepeating(texture, x, y + cornerHeight, width, height - edgeHeight - cornerHeight, uOffset, vOffset + cornerHeight, uWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight);
|
||||
self.blit(texture, x, y + height - edgeHeight, uOffset, vOffset + vHeight - edgeHeight, width, edgeHeight, textureWidth, textureHeight);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.blit(texture, x, y, uOffset, vOffset, cornerWidth, cornerHeight, textureWidth, textureHeight);
|
||||
self.blitRepeating(texture, x + cornerWidth, y, width - edgeWidth - cornerWidth, cornerHeight, uOffset + cornerWidth, vOffset, uWidth - edgeWidth - cornerWidth, cornerHeight, textureWidth, textureHeight);
|
||||
self.blit(texture, x + width - edgeWidth, y, uOffset + uWidth - edgeWidth, vOffset, edgeWidth, cornerHeight, textureWidth, textureHeight);
|
||||
self.blit(texture, x, y + height - edgeHeight, uOffset, vOffset + vHeight - edgeHeight, cornerWidth, edgeHeight, textureWidth, textureHeight);
|
||||
self.blitRepeating(texture, x + cornerWidth, y + height - edgeHeight, width - edgeWidth - cornerWidth, edgeHeight, uOffset + cornerWidth, vOffset + vHeight - edgeHeight, uWidth - edgeWidth - cornerWidth, edgeHeight, textureWidth, textureHeight);
|
||||
self.blit(texture, x + width - edgeWidth, y + height - edgeHeight, uOffset + uWidth - edgeWidth, vOffset + vHeight - edgeHeight, edgeWidth, edgeHeight, textureWidth, textureHeight);
|
||||
self.blitRepeating(texture, x, y + cornerHeight, cornerWidth, height - edgeHeight - cornerHeight, uOffset, vOffset + cornerHeight, cornerWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight);
|
||||
self.blitRepeating(texture, x + cornerWidth, y + cornerHeight, width - edgeWidth - cornerWidth, height - edgeHeight - cornerHeight, uOffset + cornerWidth, vOffset + cornerHeight, uWidth - edgeWidth - cornerWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight);
|
||||
self.blitRepeating(texture, x + width - edgeWidth, y + cornerHeight, cornerWidth, height - edgeHeight - cornerHeight, uOffset + uWidth - edgeWidth, vOffset + cornerHeight, edgeWidth, vHeight - edgeHeight - cornerHeight, textureWidth, textureHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -74,7 +74,7 @@ public interface IClientBlockExtensions
|
||||
*/
|
||||
default boolean addDestroyEffects(BlockState state, Level Level, BlockPos pos, ParticleEngine manager)
|
||||
{
|
||||
return !state.shouldSpawnParticlesOnBreak();
|
||||
return !state.shouldSpawnTerrainParticles();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,8 +117,8 @@ public interface IClientBlockExtensions
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the breaking particles created from the {@link BlockState} passed should be tinted with biome colors.
|
||||
*
|
||||
* Returns true if the breaking particles created from the {@link BlockState} passed should be tinted with biome colors.
|
||||
*
|
||||
* @param state The state of this block
|
||||
* @param level The level the particles are spawning in
|
||||
* @param pos The position of the block
|
||||
|
||||
@@ -80,7 +80,7 @@ public class LoadingErrorScreen extends ErrorScreen {
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
this.renderBackground(guiGraphics);
|
||||
this.renderBackground(guiGraphics, mouseX, mouseY, partialTick);
|
||||
this.entryList.render(guiGraphics, mouseX, mouseY, partialTick);
|
||||
drawMultiLineCenteredString(guiGraphics, font, this.modLoadErrors.isEmpty() ? warningHeader : errorHeader, this.width / 2, 10);
|
||||
this.renderables.forEach(button -> button.render(guiGraphics, mouseX, mouseY, partialTick));
|
||||
|
||||
@@ -311,7 +311,6 @@ public class ModListScreen extends Screen
|
||||
@Override
|
||||
public void tick()
|
||||
{
|
||||
search.tick();
|
||||
modList.setSelected(selected);
|
||||
|
||||
if (!search.getValue().equals(lastFilterText))
|
||||
|
||||
@@ -104,7 +104,7 @@ public class ModMismatchDisconnectedScreen extends Screen
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks)
|
||||
{
|
||||
this.renderBackground(guiGraphics);
|
||||
this.renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
int textYOffset = modMismatchData.containsMismatches() ? 18 : 0;
|
||||
guiGraphics.drawCenteredString(this.font, this.title, this.width / 2, (this.height - this.listHeight - this.textHeight) / 2 - textYOffset - 9 * 2, 0xAAAAAA);
|
||||
this.message.renderCentered(guiGraphics, this.width / 2, (this.height - this.listHeight - this.textHeight) / 2 - textYOffset);
|
||||
|
||||
@@ -17,6 +17,7 @@ import net.minecraft.client.multiplayer.ClientPacketListener;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.util.StringUtil;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
@@ -30,6 +31,7 @@ import net.minecraft.world.food.FoodData;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.scores.DisplaySlot;
|
||||
import net.minecraft.world.scores.Objective;
|
||||
import net.minecraftforge.client.event.CustomizeGuiOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderGuiEvent;
|
||||
@@ -46,8 +48,7 @@ import java.util.List;
|
||||
/**
|
||||
* Forge wrapper around {@link Gui} to be able to render {@link IGuiOverlay HUD overlays}.
|
||||
*/
|
||||
public class ForgeGui extends Gui
|
||||
{
|
||||
public class ForgeGui extends Gui {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final int WHITE = 0xFFFFFF;
|
||||
@@ -64,45 +65,33 @@ public class ForgeGui extends Gui
|
||||
|
||||
private final ForgeDebugScreenOverlay debugOverlay;
|
||||
|
||||
public ForgeGui(Minecraft mc)
|
||||
{
|
||||
public ForgeGui(Minecraft mc) {
|
||||
super(mc, mc.getItemRenderer());
|
||||
debugOverlay = new ForgeDebugScreenOverlay(mc);
|
||||
}
|
||||
|
||||
public Minecraft getMinecraft()
|
||||
{
|
||||
public Minecraft getMinecraft() {
|
||||
return minecraft;
|
||||
}
|
||||
|
||||
public void setupOverlayRenderState(boolean blend, boolean depthTest)
|
||||
{
|
||||
if (blend)
|
||||
{
|
||||
public void setupOverlayRenderState(boolean blend, boolean depthTest) {
|
||||
if (blend) {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else
|
||||
RenderSystem.disableBlend();
|
||||
}
|
||||
|
||||
if (depthTest)
|
||||
{
|
||||
RenderSystem.enableDepthTest();
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderSystem.disableDepthTest();
|
||||
}
|
||||
|
||||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, float partialTick)
|
||||
{
|
||||
public void render(GuiGraphics guiGraphics, float partialTick) {
|
||||
this.screenWidth = this.minecraft.getWindow().getGuiScaledWidth();
|
||||
this.screenHeight = this.minecraft.getWindow().getGuiScaledHeight();
|
||||
|
||||
@@ -110,23 +99,19 @@ public class ForgeGui extends Gui
|
||||
leftHeight = 39;
|
||||
|
||||
if (MinecraftForge.EVENT_BUS.post(new RenderGuiEvent.Pre(minecraft.getWindow(), guiGraphics, partialTick)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
font = minecraft.font;
|
||||
|
||||
this.random.setSeed(tickCount * 312871L);
|
||||
|
||||
GuiOverlayManager.getOverlays().forEach(entry -> {
|
||||
try
|
||||
{
|
||||
try {
|
||||
IGuiOverlay overlay = entry.overlay();
|
||||
if (pre(entry, guiGraphics)) return;
|
||||
overlay.render(this, guiGraphics, partialTick, screenWidth, screenHeight);
|
||||
post(entry, guiGraphics);
|
||||
} catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error rendering overlay '{}'", entry.id(), e);
|
||||
}
|
||||
});
|
||||
@@ -136,69 +121,50 @@ public class ForgeGui extends Gui
|
||||
MinecraftForge.EVENT_BUS.post(new RenderGuiEvent.Post(minecraft.getWindow(), guiGraphics, partialTick));
|
||||
}
|
||||
|
||||
public boolean shouldDrawSurvivalElements()
|
||||
{
|
||||
public boolean shouldDrawSurvivalElements() {
|
||||
return minecraft.gameMode.canHurtPlayer() && minecraft.getCameraEntity() instanceof Player;
|
||||
}
|
||||
|
||||
protected void renderSubtitles(GuiGraphics guiGraphics)
|
||||
{
|
||||
protected void renderSubtitles(GuiGraphics guiGraphics) {
|
||||
this.subtitleOverlay.render(guiGraphics);
|
||||
}
|
||||
|
||||
protected void renderBossHealth(GuiGraphics guiGraphics)
|
||||
{
|
||||
protected void renderBossHealth(GuiGraphics guiGraphics) {
|
||||
RenderSystem.defaultBlendFunc();
|
||||
minecraft.getProfiler().push("bossHealth");
|
||||
this.bossOverlay.render(guiGraphics);
|
||||
minecraft.getProfiler().pop();
|
||||
}
|
||||
|
||||
void renderSpyglassOverlay(GuiGraphics guiGraphics)
|
||||
{
|
||||
void renderSpyglassOverlay(GuiGraphics guiGraphics) {
|
||||
float deltaFrame = this.minecraft.getDeltaFrameTime();
|
||||
this.scopeScale = Mth.lerp(0.5F * deltaFrame, this.scopeScale, 1.125F);
|
||||
if (this.minecraft.options.getCameraType().isFirstPerson())
|
||||
{
|
||||
if (this.minecraft.options.getCameraType().isFirstPerson()) {
|
||||
if (this.minecraft.player.isScoping())
|
||||
{
|
||||
this.renderSpyglassOverlay(guiGraphics, this.scopeScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scopeScale = 0.5F;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void renderHelmet(float partialTick, GuiGraphics guiGraphics)
|
||||
{
|
||||
void renderHelmet(float partialTick, GuiGraphics guiGraphics) {
|
||||
ItemStack itemstack = this.minecraft.player.getInventory().getArmor(3);
|
||||
|
||||
if (this.minecraft.options.getCameraType().isFirstPerson() && !itemstack.isEmpty())
|
||||
{
|
||||
if (this.minecraft.options.getCameraType().isFirstPerson() && !itemstack.isEmpty()) {
|
||||
Item item = itemstack.getItem();
|
||||
if (item == Blocks.CARVED_PUMPKIN.asItem())
|
||||
{
|
||||
renderTextureOverlay(guiGraphics, PUMPKIN_BLUR_LOCATION, 1.0F);
|
||||
}
|
||||
else
|
||||
{
|
||||
IClientItemExtensions.of(item).renderHelmetOverlay(itemstack, minecraft.player, this.screenWidth, this.screenHeight, partialTick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void renderFrostbite(GuiGraphics guiGraphics)
|
||||
{
|
||||
void renderFrostbite(GuiGraphics guiGraphics) {
|
||||
if (this.minecraft.player.getTicksFrozen() > 0)
|
||||
{
|
||||
this.renderTextureOverlay(guiGraphics, POWDER_SNOW_OUTLINE_LOCATION, this.minecraft.player.getPercentFrozen());
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderArmor(GuiGraphics guiGraphics, int width, int height)
|
||||
{
|
||||
protected void renderArmor(GuiGraphics guiGraphics, int width, int height) {
|
||||
minecraft.getProfiler().push("armor");
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
@@ -206,20 +172,13 @@ public class ForgeGui extends Gui
|
||||
int top = height - leftHeight;
|
||||
|
||||
int level = minecraft.player.getArmorValue();
|
||||
for (int i = 1; level > 0 && i < 20; i += 2)
|
||||
{
|
||||
for (int i = 1; level > 0 && i < 20; i += 2) {
|
||||
if (i < level)
|
||||
{
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, left, top, 34, 9, 9, 9);
|
||||
}
|
||||
guiGraphics.blitSprite(ARMOR_FULL_SPRITE, left, top, 9, 9);
|
||||
else if (i == level)
|
||||
{
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, left, top, 25, 9, 9, 9);
|
||||
}
|
||||
guiGraphics.blitSprite(ARMOR_HALF_SPRITE, left, top, 9, 9);
|
||||
else if (i > level)
|
||||
{
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, left, top, 16, 9, 9, 9);
|
||||
}
|
||||
guiGraphics.blitSprite(ARMOR_EMPTY_SPRITE, left, top, 9, 9);
|
||||
left += 8;
|
||||
}
|
||||
leftHeight += 10;
|
||||
@@ -229,16 +188,12 @@ public class ForgeGui extends Gui
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderPortalOverlay(GuiGraphics guiGraphics, float alpha)
|
||||
{
|
||||
protected void renderPortalOverlay(GuiGraphics guiGraphics, float alpha) {
|
||||
if (alpha > 0.0F)
|
||||
{
|
||||
super.renderPortalOverlay(guiGraphics, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderAir(int width, int height, GuiGraphics guiGraphics)
|
||||
{
|
||||
protected void renderAir(int width, int height, GuiGraphics guiGraphics) {
|
||||
minecraft.getProfiler().push("air");
|
||||
Player player = (Player) this.minecraft.getCameraEntity();
|
||||
RenderSystem.enableBlend();
|
||||
@@ -246,14 +201,15 @@ public class ForgeGui extends Gui
|
||||
int top = height - rightHeight;
|
||||
|
||||
int air = player.getAirSupply();
|
||||
if (player.isEyeInFluidType(ForgeMod.WATER_TYPE.get()) || air < 300)
|
||||
{
|
||||
if (player.isEyeInFluidType(ForgeMod.WATER_TYPE.get()) || air < 300) {
|
||||
int full = Mth.ceil((double) (air - 2) * 10.0D / 300.0D);
|
||||
int partial = Mth.ceil((double) air * 10.0D / 300.0D) - full;
|
||||
|
||||
for (int i = 0; i < full + partial; ++i)
|
||||
{
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, left - i * 8 - 9, top, (i < full ? 16 : 25), 18, 9, 9);
|
||||
for (int i = 0; i < full + partial; ++i) {
|
||||
if (i < full)
|
||||
guiGraphics.blitSprite(AIR_SPRITE, left - i * 8 - 9, top, 9, 9);
|
||||
else
|
||||
guiGraphics.blitSprite(AIR_BURSTING_SPRITE, left - i * 8 - 9, top, 9, 9);
|
||||
}
|
||||
rightHeight += 10;
|
||||
}
|
||||
@@ -262,8 +218,7 @@ public class ForgeGui extends Gui
|
||||
minecraft.getProfiler().pop();
|
||||
}
|
||||
|
||||
public void renderHealth(int width, int height, GuiGraphics guiGraphics)
|
||||
{
|
||||
public void renderHealth(int width, int height, GuiGraphics guiGraphics) {
|
||||
minecraft.getProfiler().push("health");
|
||||
RenderSystem.enableBlend();
|
||||
|
||||
@@ -271,19 +226,15 @@ public class ForgeGui extends Gui
|
||||
int health = Mth.ceil(player.getHealth());
|
||||
boolean highlight = healthBlinkTime > (long) tickCount && (healthBlinkTime - (long) tickCount) / 3L % 2L == 1L;
|
||||
|
||||
if (health < this.lastHealth && player.invulnerableTime > 0)
|
||||
{
|
||||
if (health < this.lastHealth && player.invulnerableTime > 0) {
|
||||
this.lastHealthTime = Util.getMillis();
|
||||
this.healthBlinkTime = (long) (this.tickCount + 20);
|
||||
}
|
||||
else if (health > this.lastHealth && player.invulnerableTime > 0)
|
||||
{
|
||||
} else if (health > this.lastHealth && player.invulnerableTime > 0) {
|
||||
this.lastHealthTime = Util.getMillis();
|
||||
this.healthBlinkTime = (long) (this.tickCount + 10);
|
||||
}
|
||||
|
||||
if (Util.getMillis() - this.lastHealthTime > 1000L)
|
||||
{
|
||||
if (Util.getMillis() - this.lastHealthTime > 1000L) {
|
||||
this.lastHealth = health;
|
||||
this.displayHealth = health;
|
||||
this.lastHealthTime = Util.getMillis();
|
||||
@@ -308,9 +259,7 @@ public class ForgeGui extends Gui
|
||||
|
||||
int regen = -1;
|
||||
if (player.hasEffect(MobEffects.REGENERATION))
|
||||
{
|
||||
regen = this.tickCount % Mth.ceil(healthMax + 5.0F);
|
||||
}
|
||||
|
||||
this.renderHearts(guiGraphics, player, left, top, rowHeight, regen, healthMax, health, healthLast, absorb, highlight);
|
||||
|
||||
@@ -318,8 +267,7 @@ public class ForgeGui extends Gui
|
||||
minecraft.getProfiler().pop();
|
||||
}
|
||||
|
||||
public void renderFood(int width, int height, GuiGraphics guiGraphics)
|
||||
{
|
||||
public void renderFood(int width, int height, GuiGraphics guiGraphics) {
|
||||
minecraft.getProfiler().push("food");
|
||||
|
||||
Player player = (Player) this.minecraft.getCameraEntity();
|
||||
@@ -327,54 +275,47 @@ public class ForgeGui extends Gui
|
||||
int left = width / 2 + 91;
|
||||
int top = height - rightHeight;
|
||||
rightHeight += 10;
|
||||
boolean unused = false;// Unused flag in vanilla, seems to be part of a 'fade out' mechanic
|
||||
|
||||
FoodData stats = minecraft.player.getFoodData();
|
||||
int level = stats.getFoodLevel();
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
ResourceLocation empty = FOOD_EMPTY_SPRITE;
|
||||
ResourceLocation half = FOOD_HALF_SPRITE;
|
||||
ResourceLocation full = FOOD_FULL_SPRITE;
|
||||
|
||||
if (player.hasEffect(MobEffects.HUNGER)) {
|
||||
empty = FOOD_EMPTY_HUNGER_SPRITE;
|
||||
half = FOOD_HALF_HUNGER_SPRITE;
|
||||
full = FOOD_FULL_HUNGER_SPRITE;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
int idx = i * 2 + 1;
|
||||
int x = left - i * 8 - 9;
|
||||
int y = top;
|
||||
int icon = 16;
|
||||
byte background = 0;
|
||||
|
||||
if (minecraft.player.hasEffect(MobEffects.HUNGER))
|
||||
{
|
||||
icon += 36;
|
||||
background = 13;
|
||||
}
|
||||
if (unused) background = 1; //Probably should be a += 1 but vanilla never uses this
|
||||
|
||||
if (player.getFoodData().getSaturationLevel() <= 0.0F && tickCount % (level * 3 + 1) == 0)
|
||||
{
|
||||
y = top + (random.nextInt(3) - 1);
|
||||
}
|
||||
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, x, y, 16 + background * 9, 27, 9, 9);
|
||||
guiGraphics.blitSprite(empty, x, y, 9, 9);
|
||||
|
||||
if (idx < level)
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, x, y, icon + 36, 27, 9, 9);
|
||||
guiGraphics.blitSprite(half, x, y, 9, 9);
|
||||
else if (idx == level)
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, x, y, icon + 45, 27, 9, 9);
|
||||
guiGraphics.blitSprite(full, x, y, 9, 9);
|
||||
}
|
||||
RenderSystem.disableBlend();
|
||||
minecraft.getProfiler().pop();
|
||||
}
|
||||
|
||||
protected void renderSleepFade(int width, int height, GuiGraphics guiGraphics)
|
||||
{
|
||||
if (minecraft.player.getSleepTimer() > 0)
|
||||
{
|
||||
protected void renderSleepFade(int width, int height, GuiGraphics guiGraphics) {
|
||||
if (minecraft.player.getSleepTimer() > 0) {
|
||||
minecraft.getProfiler().push("sleep");
|
||||
int sleepTime = minecraft.player.getSleepTimer();
|
||||
float opacity = (float) sleepTime / 100.0F;
|
||||
|
||||
if (opacity > 1.0F)
|
||||
{
|
||||
opacity = 1.0F - (float) (sleepTime - 100) / 10.0F;
|
||||
}
|
||||
|
||||
int color = (int) (220.0F * opacity) << 24 | 1052704;
|
||||
guiGraphics.fill(RenderType.guiOverlay(), 0, 0, width, height, color);
|
||||
@@ -382,22 +323,19 @@ public class ForgeGui extends Gui
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderExperience(int x, GuiGraphics guiGraphics)
|
||||
{
|
||||
protected void renderExperience(int x, GuiGraphics guiGraphics) {
|
||||
guiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
if (minecraft.gameMode.hasExperience())
|
||||
{
|
||||
super.renderExperienceBar(guiGraphics, x);
|
||||
}
|
||||
|
||||
RenderSystem.enableBlend();
|
||||
guiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderJumpMeter(PlayerRideableJumping playerRideableJumping, GuiGraphics guiGraphics, int x)
|
||||
{
|
||||
public void renderJumpMeter(PlayerRideableJumping playerRideableJumping, GuiGraphics guiGraphics, int x) {
|
||||
guiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
RenderSystem.disableBlend();
|
||||
|
||||
@@ -408,29 +346,22 @@ public class ForgeGui extends Gui
|
||||
guiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
}
|
||||
|
||||
protected void renderHUDText(int width, int height, GuiGraphics guiGraphics)
|
||||
{
|
||||
protected void renderHUDText(int width, int height, GuiGraphics guiGraphics) {
|
||||
minecraft.getProfiler().push("forgeHudText");
|
||||
RenderSystem.defaultBlendFunc();
|
||||
|
||||
var listL = new ArrayList<String>();
|
||||
var listR = new ArrayList<String>();
|
||||
|
||||
if (minecraft.isDemo())
|
||||
{
|
||||
if (minecraft.isDemo()) {
|
||||
long time = minecraft.level.getGameTime();
|
||||
if (time >= 120500L)
|
||||
{
|
||||
listR.add(I18n.get("demo.demoExpired"));
|
||||
}
|
||||
else
|
||||
{
|
||||
listR.add(I18n.get("demo.remainingTime", StringUtil.formatTickDuration((int) (120500L - time))));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.minecraft.options.renderDebug)
|
||||
{
|
||||
if (debugOverlay.showDebugScreen()) {
|
||||
debugOverlay.update();
|
||||
listL.addAll(debugOverlay.getLeft());
|
||||
listR.addAll(debugOverlay.getRight());
|
||||
@@ -440,10 +371,8 @@ public class ForgeGui extends Gui
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
|
||||
int top = 2;
|
||||
for (String msg : listL)
|
||||
{
|
||||
if (msg != null && !msg.isEmpty())
|
||||
{
|
||||
for (String msg : listL) {
|
||||
if (msg != null && !msg.isEmpty()) {
|
||||
guiGraphics.fill(1, top - 1, 2 + font.width(msg) + 1, top + font.lineHeight - 1, -1873784752);
|
||||
guiGraphics.drawString(font, msg, 2, top, 14737632, false);
|
||||
}
|
||||
@@ -451,10 +380,8 @@ public class ForgeGui extends Gui
|
||||
}
|
||||
|
||||
top = 2;
|
||||
for (String msg : listR)
|
||||
{
|
||||
if (msg != null && !msg.isEmpty())
|
||||
{
|
||||
for (String msg : listR) {
|
||||
if (msg != null && !msg.isEmpty()) {
|
||||
int w = font.width(msg);
|
||||
int left = width - 2 - w;
|
||||
guiGraphics.fill(left - 1, top - 1, left + w + 1, top + font.lineHeight - 1, -1873784752);
|
||||
@@ -466,32 +393,25 @@ public class ForgeGui extends Gui
|
||||
minecraft.getProfiler().pop();
|
||||
}
|
||||
|
||||
protected void renderFPSGraph(GuiGraphics guiGraphics)
|
||||
{
|
||||
if (this.minecraft.options.renderDebug && this.minecraft.options.renderFpsChart)
|
||||
{
|
||||
protected void renderFPSGraph(GuiGraphics guiGraphics) {
|
||||
if (debugOverlay.showDebugScreen())
|
||||
this.debugOverlay.render(guiGraphics);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearCache()
|
||||
{
|
||||
public void clearCache() {
|
||||
super.clearCache();
|
||||
this.debugOverlay.clearChunkCache();
|
||||
}
|
||||
|
||||
protected void renderRecordOverlay(int width, int height, float partialTick, GuiGraphics guiGraphics)
|
||||
{
|
||||
if (overlayMessageTime > 0)
|
||||
{
|
||||
protected void renderRecordOverlay(int width, int height, float partialTick, GuiGraphics guiGraphics) {
|
||||
if (overlayMessageTime > 0) {
|
||||
minecraft.getProfiler().push("overlayMessage");
|
||||
float hue = (float) overlayMessageTime - partialTick;
|
||||
int opacity = (int) (hue * 255.0F / 20.0F);
|
||||
if (opacity > 255) opacity = 255;
|
||||
|
||||
if (opacity > 8)
|
||||
{
|
||||
if (opacity > 8) {
|
||||
//Include a shift based on the bar height plus the difference between the height that renderSelectedItemName
|
||||
// renders at (59) and the height that the overlay/status bar renders at (68) by default
|
||||
int yShift = Math.max(leftHeight, rightHeight) + (68 - 59);
|
||||
@@ -512,16 +432,13 @@ public class ForgeGui extends Gui
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderTitle(int width, int height, float partialTick, GuiGraphics guiGraphics)
|
||||
{
|
||||
if (title != null && titleTime > 0)
|
||||
{
|
||||
protected void renderTitle(int width, int height, float partialTick, GuiGraphics guiGraphics) {
|
||||
if (title != null && titleTime > 0) {
|
||||
minecraft.getProfiler().push("titleAndSubtitle");
|
||||
float age = (float) this.titleTime - partialTick;
|
||||
int opacity = 255;
|
||||
|
||||
if (titleTime > titleFadeOutTime + titleStayTime)
|
||||
{
|
||||
if (titleTime > titleFadeOutTime + titleStayTime) {
|
||||
float f3 = (float) (titleFadeInTime + titleStayTime + titleFadeOutTime) - age;
|
||||
opacity = (int) (f3 * 255.0F / (float) titleFadeInTime);
|
||||
}
|
||||
@@ -529,8 +446,7 @@ public class ForgeGui extends Gui
|
||||
|
||||
opacity = Mth.clamp(opacity, 0, 255);
|
||||
|
||||
if (opacity > 8)
|
||||
{
|
||||
if (opacity > 8) {
|
||||
guiGraphics.pose().pushPose();
|
||||
guiGraphics.pose().translate(width / 2D, height / 2D, 0.0D);
|
||||
RenderSystem.enableBlend();
|
||||
@@ -540,8 +456,7 @@ public class ForgeGui extends Gui
|
||||
int l = opacity << 24 & -16777216;
|
||||
guiGraphics.drawString(this.font, this.title.getVisualOrderText(), -this.getFont().width(this.title) / 2, -10, 16777215 | l, true);
|
||||
guiGraphics.pose().popPose();
|
||||
if (this.subtitle != null)
|
||||
{
|
||||
if (this.subtitle != null) {
|
||||
guiGraphics.pose().pushPose();
|
||||
guiGraphics.pose().scale(2.0F, 2.0F, 2.0F);
|
||||
guiGraphics.drawString(this.font, this.subtitle.getVisualOrderText(), -this.getFont().width(this.subtitle) / 2, 5, 16777215 | l, true);
|
||||
@@ -555,8 +470,7 @@ public class ForgeGui extends Gui
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderChat(int width, int height, GuiGraphics guiGraphics)
|
||||
{
|
||||
protected void renderChat(int width, int height, GuiGraphics guiGraphics) {
|
||||
minecraft.getProfiler().push("chat");
|
||||
|
||||
Window window = minecraft.getWindow();
|
||||
@@ -574,30 +488,22 @@ public class ForgeGui extends Gui
|
||||
minecraft.getProfiler().pop();
|
||||
}
|
||||
|
||||
protected void renderPlayerList(int width, int height, GuiGraphics guiGraphics)
|
||||
{
|
||||
Objective scoreobjective = this.minecraft.level.getScoreboard().getDisplayObjective(0);
|
||||
protected void renderPlayerList(int width, int height, GuiGraphics guiGraphics) {
|
||||
Objective scoreobjective = this.minecraft.level.getScoreboard().getDisplayObjective(DisplaySlot.LIST);
|
||||
ClientPacketListener handler = minecraft.player.connection;
|
||||
|
||||
if (minecraft.options.keyPlayerList.isDown() && (!minecraft.isLocalServer() || handler.getOnlinePlayers().size() > 1 || scoreobjective != null))
|
||||
{
|
||||
if (minecraft.options.keyPlayerList.isDown() && (!minecraft.isLocalServer() || handler.getOnlinePlayers().size() > 1 || scoreobjective != null)) {
|
||||
this.tabList.setVisible(true);
|
||||
this.tabList.render(guiGraphics, width, this.minecraft.level.getScoreboard(), scoreobjective);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
} else
|
||||
this.tabList.setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected void renderHealthMount(int width, int height, GuiGraphics guiGraphics)
|
||||
{
|
||||
protected void renderHealthMount(int width, int height, GuiGraphics guiGraphics) {
|
||||
Player player = (Player) minecraft.getCameraEntity();
|
||||
Entity tmp = player.getVehicle();
|
||||
if (!(tmp instanceof LivingEntity)) return;
|
||||
|
||||
boolean unused = false;
|
||||
int left_align = width / 2 + 91;
|
||||
|
||||
minecraft.getProfiler().popPush("mountHealth");
|
||||
@@ -609,27 +515,21 @@ public class ForgeGui extends Gui
|
||||
|
||||
if (hearts > 30) hearts = 30;
|
||||
|
||||
final int MARGIN = 52;
|
||||
final int BACKGROUND = MARGIN + (unused ? 1 : 0);
|
||||
final int HALF = MARGIN + 45;
|
||||
final int FULL = MARGIN + 36;
|
||||
|
||||
for (int heart = 0; hearts > 0; heart += 20)
|
||||
{
|
||||
for (int heart = 0; hearts > 0; heart += 20) {
|
||||
int top = height - rightHeight;
|
||||
|
||||
int rowCount = Math.min(hearts, 10);
|
||||
hearts -= rowCount;
|
||||
|
||||
for (int i = 0; i < rowCount; ++i)
|
||||
{
|
||||
for (int i = 0; i < rowCount; ++i) {
|
||||
int x = left_align - i * 8 - 9;
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, x, top, BACKGROUND, 9, 9, 9);
|
||||
guiGraphics.blitSprite(HEART_VEHICLE_CONTAINER_SPRITE, x, top, 9, 9);
|
||||
|
||||
if (i * 2 + 1 + heart < health)
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, x, top, FULL, 9, 9, 9);
|
||||
guiGraphics.blitSprite(HEART_VEHICLE_FULL_SPRITE, x, top, 9, 9);
|
||||
else if (i * 2 + 1 + heart == health)
|
||||
guiGraphics.blit(GUI_ICONS_LOCATION, x, top, HALF, 9, 9, 9);
|
||||
guiGraphics.blitSprite(HEART_VEHICLE_HALF_SPRITE, x, top, 9, 9);
|
||||
}
|
||||
|
||||
rightHeight += 10;
|
||||
@@ -638,36 +538,30 @@ public class ForgeGui extends Gui
|
||||
}
|
||||
|
||||
//Helper macros
|
||||
private boolean pre(NamedGuiOverlay overlay, GuiGraphics guiGraphics)
|
||||
{
|
||||
private boolean pre(NamedGuiOverlay overlay, GuiGraphics guiGraphics) {
|
||||
return MinecraftForge.EVENT_BUS.post(new RenderGuiOverlayEvent.Pre(minecraft.getWindow(), guiGraphics, minecraft.getFrameTime(), overlay));
|
||||
}
|
||||
|
||||
private void post(NamedGuiOverlay overlay, GuiGraphics guiGraphics)
|
||||
{
|
||||
private void post(NamedGuiOverlay overlay, GuiGraphics guiGraphics) {
|
||||
MinecraftForge.EVENT_BUS.post(new RenderGuiOverlayEvent.Post(minecraft.getWindow(), guiGraphics, minecraft.getFrameTime(), overlay));
|
||||
}
|
||||
|
||||
private static class ForgeDebugScreenOverlay extends DebugScreenOverlay
|
||||
{
|
||||
private static class ForgeDebugScreenOverlay extends DebugScreenOverlay {
|
||||
private final Minecraft mc;
|
||||
|
||||
private ForgeDebugScreenOverlay(Minecraft mc)
|
||||
{
|
||||
private ForgeDebugScreenOverlay(Minecraft mc) {
|
||||
super(mc);
|
||||
this.mc = mc;
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
public void update() {
|
||||
Entity entity = this.mc.getCameraEntity();
|
||||
this.block = entity.pick(rayTraceDistance, 0.0F, false);
|
||||
this.liquid = entity.pick(rayTraceDistance, 0.0F, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGameInformation(GuiGraphics guiGraphics)
|
||||
{
|
||||
protected void drawGameInformation(GuiGraphics guiGraphics) {
|
||||
// Replicate the depth test state "leak" caused by the text that is rendered here in vanilla
|
||||
// being flushed when the graphs start drawing (PR #9539)
|
||||
RenderSystem.disableDepthTest();
|
||||
@@ -676,18 +570,16 @@ public class ForgeGui extends Gui
|
||||
@Override
|
||||
protected void drawSystemInformation(GuiGraphics guiGraphics) {}
|
||||
|
||||
private List<String> getLeft()
|
||||
{
|
||||
private List<String> getLeft() {
|
||||
List<String> ret = this.getGameInformation();
|
||||
ret.add("");
|
||||
boolean flag = this.mc.getSingleplayerServer() != null;
|
||||
ret.add("Debug: Pie [shift]: " + (this.mc.options.renderDebugCharts ? "visible" : "hidden") + (flag ? " FPS + TPS" : " FPS") + " [alt]: " + (this.mc.options.renderFpsChart ? "visible" : "hidden"));
|
||||
ret.add("Debug: Pie [shift]: " + (this.renderProfilerChart ? "visible" : "hidden") + (flag ? " FPS + TPS" : " FPS") + " [alt]: " + (this.renderFpsCharts ? "visible" : "hidden"));
|
||||
ret.add("For help: press F3 + Q");
|
||||
return ret;
|
||||
}
|
||||
|
||||
private List<String> getRight()
|
||||
{
|
||||
private List<String> getRight() {
|
||||
return this.getSystemInformation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.PlayerRideableJumping;
|
||||
import net.minecraft.world.level.GameType;
|
||||
import net.minecraft.world.scores.DisplaySlot;
|
||||
import net.minecraft.world.scores.Objective;
|
||||
import net.minecraft.world.scores.PlayerTeam;
|
||||
import net.minecraft.world.scores.Scoreboard;
|
||||
@@ -22,27 +23,29 @@ import org.lwjgl.opengl.GL11;
|
||||
/**
|
||||
* All the vanilla {@linkplain IGuiOverlay HUD overlays} in the order that they render.
|
||||
*/
|
||||
public enum VanillaGuiOverlay
|
||||
{
|
||||
public enum VanillaGuiOverlay {
|
||||
VIGNETTE("vignette", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (Minecraft.useFancyGraphics())
|
||||
{
|
||||
if (Minecraft.useFancyGraphics()) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderVignette(guiGraphics, gui.getMinecraft().getCameraEntity());
|
||||
}
|
||||
}),
|
||||
|
||||
SPYGLASS("spyglass", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderSpyglassOverlay(guiGraphics);
|
||||
}),
|
||||
|
||||
HELMET("helmet", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderHelmet(partialTick, guiGraphics);
|
||||
}),
|
||||
|
||||
FROSTBITE("frostbite", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderFrostbite(guiGraphics);
|
||||
}),
|
||||
|
||||
PORTAL("portal", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
float f1 = Mth.lerp(partialTick, gui.getMinecraft().player.oSpinningEffectIntensity, gui.getMinecraft().player.spinningEffectIntensity);
|
||||
if (f1 > 0.0F && !gui.getMinecraft().player.hasEffect(MobEffects.CONFUSION)) {
|
||||
@@ -50,23 +53,19 @@ public enum VanillaGuiOverlay
|
||||
gui.renderPortalOverlay(guiGraphics, f1);
|
||||
}
|
||||
}),
|
||||
|
||||
HOTBAR("hotbar", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
if (!gui.getMinecraft().options.hideGui) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
if (gui.getMinecraft().gameMode.getPlayerMode() == GameType.SPECTATOR)
|
||||
{
|
||||
gui.getSpectatorGui().renderHotbar(guiGraphics);
|
||||
}
|
||||
else
|
||||
{
|
||||
gui.renderHotbar(partialTick, guiGraphics);
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
CROSSHAIR("crosshair", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
if (!gui.getMinecraft().options.hideGui) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
|
||||
guiGraphics.pose().pushPose();
|
||||
@@ -75,9 +74,9 @@ public enum VanillaGuiOverlay
|
||||
guiGraphics.pose().popPose();
|
||||
}
|
||||
}),
|
||||
|
||||
BOSS_EVENT_PROGRESS("boss_event_progress", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
if (!gui.getMinecraft().options.hideGui) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
|
||||
guiGraphics.pose().pushPose();
|
||||
@@ -86,127 +85,125 @@ public enum VanillaGuiOverlay
|
||||
guiGraphics.pose().popPose();
|
||||
}
|
||||
}),
|
||||
|
||||
PLAYER_HEALTH("player_health", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements())
|
||||
{
|
||||
if (!gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements()) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderHealth(screenWidth, screenHeight, guiGraphics);
|
||||
}
|
||||
}),
|
||||
|
||||
ARMOR_LEVEL("armor_level", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements())
|
||||
{
|
||||
if (!gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements()) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderArmor(guiGraphics, screenWidth, screenHeight);
|
||||
}
|
||||
}),
|
||||
|
||||
FOOD_LEVEL("food_level", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
Entity vehicle = gui.getMinecraft().player.getVehicle();
|
||||
boolean isMounted = vehicle != null && vehicle.showVehicleHealth();
|
||||
if (!isMounted && !gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements())
|
||||
{
|
||||
if (!isMounted && !gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements()) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderFood(screenWidth, screenHeight, guiGraphics);
|
||||
}
|
||||
}),
|
||||
|
||||
AIR_LEVEL("air_level", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements())
|
||||
{
|
||||
if (!gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements()) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderAir(screenWidth, screenHeight, guiGraphics);
|
||||
}
|
||||
}),
|
||||
|
||||
MOUNT_HEALTH("mount_health", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements())
|
||||
{
|
||||
if (!gui.getMinecraft().options.hideGui && gui.shouldDrawSurvivalElements()) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderHealthMount(screenWidth, screenHeight, guiGraphics);
|
||||
}
|
||||
}),
|
||||
|
||||
JUMP_BAR("jump_bar", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
PlayerRideableJumping playerRideableJumping = gui.getMinecraft().player.jumpableVehicle();
|
||||
if (playerRideableJumping != null && !gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
if (playerRideableJumping != null && !gui.getMinecraft().options.hideGui) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderJumpMeter(playerRideableJumping, guiGraphics, screenWidth / 2 - 91);
|
||||
}
|
||||
}),
|
||||
|
||||
EXPERIENCE_BAR("experience_bar", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (gui.getMinecraft().player.jumpableVehicle() == null && !gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
if (gui.getMinecraft().player.jumpableVehicle() == null && !gui.getMinecraft().options.hideGui) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
gui.renderExperience(screenWidth / 2 - 91, guiGraphics);
|
||||
}
|
||||
}),
|
||||
|
||||
ITEM_NAME("item_name", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
if (!gui.getMinecraft().options.hideGui) {
|
||||
gui.setupOverlayRenderState(true, false);
|
||||
if (gui.getMinecraft().gameMode.getPlayerMode() != GameType.SPECTATOR)
|
||||
{
|
||||
gui.renderSelectedItemName(guiGraphics, Math.max(gui.leftHeight, gui.rightHeight));
|
||||
}
|
||||
else if (gui.getMinecraft().player.isSpectator())
|
||||
{
|
||||
gui.getSpectatorGui().renderTooltip(guiGraphics);
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
SLEEP_FADE("sleep_fade", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.renderSleepFade(screenWidth, screenHeight, guiGraphics);
|
||||
}),
|
||||
|
||||
POTION_ICONS("potion_icons", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.renderEffects(guiGraphics);
|
||||
}),
|
||||
|
||||
DEBUG_TEXT("debug_text", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.renderHUDText(screenWidth, screenHeight, guiGraphics);
|
||||
}),
|
||||
|
||||
FPS_GRAPH("fps_graph", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
gui.renderFPSGraph(guiGraphics);
|
||||
}),
|
||||
|
||||
RECORD_OVERLAY("record_overlay", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
gui.renderRecordOverlay(screenWidth, screenHeight, partialTick, guiGraphics);
|
||||
}
|
||||
}),
|
||||
|
||||
TITLE_TEXT("title_text", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
gui.renderTitle(screenWidth, screenHeight, partialTick, guiGraphics);
|
||||
}
|
||||
}),
|
||||
|
||||
SUBTITLES("subtitles", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
if (!gui.getMinecraft().options.hideGui)
|
||||
{
|
||||
gui.renderSubtitles(guiGraphics);
|
||||
}
|
||||
}),
|
||||
SCOREBOARD("scoreboard", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
|
||||
SCOREBOARD("scoreboard", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
Scoreboard scoreboard = gui.getMinecraft().level.getScoreboard();
|
||||
Objective objective = null;
|
||||
PlayerTeam scoreplayerteam = scoreboard.getPlayersTeam(gui.getMinecraft().player.getScoreboardName());
|
||||
if (scoreplayerteam != null)
|
||||
{
|
||||
int slot = scoreplayerteam.getColor().getId();
|
||||
if (slot >= 0) objective = scoreboard.getDisplayObjective(3 + slot);
|
||||
if (scoreplayerteam != null) {
|
||||
var slot = DisplaySlot.teamColorToSlot(scoreplayerteam.getColor());
|
||||
if (slot != null)
|
||||
objective = scoreboard.getDisplayObjective(slot);
|
||||
}
|
||||
Objective scoreobjective1 = objective != null ? objective : scoreboard.getDisplayObjective(1);
|
||||
if (scoreobjective1 != null)
|
||||
{
|
||||
gui.displayScoreboardSidebar(guiGraphics, scoreobjective1);
|
||||
}
|
||||
}),
|
||||
CHAT_PANEL("chat_panel", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
|
||||
if (objective == null)
|
||||
objective = scoreboard.getDisplayObjective(DisplaySlot.SIDEBAR);
|
||||
|
||||
if (objective != null)
|
||||
gui.displayScoreboardSidebar(guiGraphics, objective);
|
||||
}),
|
||||
|
||||
CHAT_PANEL("chat_panel", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
|
||||
gui.renderChat(screenWidth, screenHeight, guiGraphics);
|
||||
}),
|
||||
PLAYER_LIST("player_list", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
|
||||
PLAYER_LIST("player_list", (gui, guiGraphics, partialTick, screenWidth, screenHeight) -> {
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
|
||||
@@ -217,20 +214,17 @@ public enum VanillaGuiOverlay
|
||||
final IGuiOverlay overlay;
|
||||
NamedGuiOverlay type;
|
||||
|
||||
VanillaGuiOverlay(String id, IGuiOverlay overlay)
|
||||
{
|
||||
VanillaGuiOverlay(String id, IGuiOverlay overlay) {
|
||||
this.id = new ResourceLocation("minecraft", id);
|
||||
this.overlay = overlay;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ResourceLocation id()
|
||||
{
|
||||
public ResourceLocation id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public NamedGuiOverlay type()
|
||||
{
|
||||
public NamedGuiOverlay type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class ExtendedButton extends Button
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
int k = !this.active ? 0 : (this.isHoveredOrFocused() ? 2 : 1);
|
||||
guiGraphics.blitWithBorder(WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2);
|
||||
guiGraphics.blitSprite(SPRITES.get(this.active, this.isHoveredOrFocused()), this.getX(), this.getY(), this.getWidth(), this.getHeight());
|
||||
|
||||
final FormattedText buttonText = mc.font.ellipsize(this.getMessage(), this.width - 6); // Remove 6 pixels so that the text is always contained within the button's borders
|
||||
guiGraphics.drawCenteredString(mc.font, Language.getInstance().getVisualOrder(buttonText), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, getFGColor());
|
||||
|
||||
@@ -17,8 +17,7 @@ import java.text.DecimalFormat;
|
||||
/**
|
||||
* Slider widget implementation which allows inputting values in a certain range with optional step size.
|
||||
*/
|
||||
public class ForgeSlider extends AbstractSliderButton
|
||||
{
|
||||
public class ForgeSlider extends AbstractSliderButton {
|
||||
protected Component prefix;
|
||||
protected Component suffix;
|
||||
|
||||
@@ -46,8 +45,7 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
* @param precision Only used when {@code stepSize} is 0. Limited to a maximum of 4 (inclusive).
|
||||
* @param drawString Should text be displayed on the widget
|
||||
*/
|
||||
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)
|
||||
{
|
||||
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, Component.empty(), 0D);
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
@@ -57,8 +55,7 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
this.value = this.snapToNearest((currentValue - minValue) / (maxValue - minValue));
|
||||
this.drawString = drawString;
|
||||
|
||||
if (stepSize == 0D)
|
||||
{
|
||||
if (stepSize == 0D) {
|
||||
precision = Math.min(precision, 4);
|
||||
|
||||
StringBuilder builder = new StringBuilder("0");
|
||||
@@ -70,13 +67,9 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
builder.append('0');
|
||||
|
||||
this.format = new DecimalFormat(builder.toString());
|
||||
}
|
||||
else if (Mth.equal(this.stepSize, Math.floor(this.stepSize)))
|
||||
{
|
||||
} else if (Mth.equal(this.stepSize, Math.floor(this.stepSize))) {
|
||||
this.format = new DecimalFormat("0");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.format = new DecimalFormat(Double.toString(this.stepSize).replaceAll("\\d", "0"));
|
||||
}
|
||||
|
||||
@@ -86,68 +79,58 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
/**
|
||||
* Overload with {@code stepSize} set to 1, useful for sliders with whole number values.
|
||||
*/
|
||||
public ForgeSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, boolean drawString)
|
||||
{
|
||||
public ForgeSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, boolean drawString) {
|
||||
this(x, y, width, height, prefix, suffix, minValue, maxValue, currentValue, 1D, 0, drawString);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current slider value as a double
|
||||
*/
|
||||
public double getValue()
|
||||
{
|
||||
public double getValue() {
|
||||
return this.value * (maxValue - minValue) + minValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current slider value as an long
|
||||
*/
|
||||
public long getValueLong()
|
||||
{
|
||||
public long getValueLong() {
|
||||
return Math.round(this.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Current slider value as an int
|
||||
*/
|
||||
public int getValueInt()
|
||||
{
|
||||
public int getValueInt() {
|
||||
return (int) this.getValueLong();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value The new slider value
|
||||
*/
|
||||
public void setValue(double value)
|
||||
{
|
||||
public void setValue(double value) {
|
||||
this.value = this.snapToNearest((value - this.minValue) / (this.maxValue - this.minValue));
|
||||
this.updateMessage();
|
||||
}
|
||||
|
||||
public String getValueString()
|
||||
{
|
||||
public String getValueString() {
|
||||
return this.format.format(this.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(double mouseX, double mouseY)
|
||||
{
|
||||
public void onClick(double mouseX, double mouseY) {
|
||||
this.setValueFromMouse(mouseX);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDrag(double mouseX, double mouseY, double dragX, double dragY)
|
||||
{
|
||||
protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) {
|
||||
super.onDrag(mouseX, mouseY, dragX, dragY);
|
||||
this.setValueFromMouse(mouseX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers)
|
||||
{
|
||||
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
|
||||
boolean flag = keyCode == GLFW.GLFW_KEY_LEFT;
|
||||
if (flag || keyCode == GLFW.GLFW_KEY_RIGHT)
|
||||
{
|
||||
if (flag || keyCode == GLFW.GLFW_KEY_RIGHT) {
|
||||
if (this.minValue > this.maxValue)
|
||||
flag = !flag;
|
||||
float f = flag ? -1F : 1F;
|
||||
@@ -160,16 +143,14 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setValueFromMouse(double mouseX)
|
||||
{
|
||||
private void setValueFromMouse(double mouseX) {
|
||||
this.setSliderValue((mouseX - (this.getX() + 4)) / (this.width - 8));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value Percentage of slider range
|
||||
*/
|
||||
private void setSliderValue(double value)
|
||||
{
|
||||
private void setSliderValue(double value) {
|
||||
double oldValue = this.value;
|
||||
this.value = this.snapToNearest(value);
|
||||
if (!Mth.equal(oldValue, this.value))
|
||||
@@ -182,8 +163,7 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
* Snaps the value, so that the displayed value is the nearest multiple of {@code stepSize}.
|
||||
* If {@code stepSize} is 0, no snapping occurs.
|
||||
*/
|
||||
private double snapToNearest(double value)
|
||||
{
|
||||
private double snapToNearest(double value) {
|
||||
if(stepSize <= 0D)
|
||||
return Mth.clamp(value, 0D, 1D);
|
||||
|
||||
@@ -192,40 +172,29 @@ public class ForgeSlider extends AbstractSliderButton
|
||||
value = (stepSize * Math.round(value / stepSize));
|
||||
|
||||
if (this.minValue > this.maxValue)
|
||||
{
|
||||
value = Mth.clamp(value, this.maxValue, this.minValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
value = Mth.clamp(value, this.minValue, this.maxValue);
|
||||
}
|
||||
|
||||
return Mth.map(value, this.minValue, this.maxValue, 0D, 1D);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateMessage()
|
||||
{
|
||||
protected void updateMessage() {
|
||||
if (this.drawString)
|
||||
{
|
||||
this.setMessage(Component.literal("").append(prefix).append(this.getValueString()).append(suffix));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.setMessage(Component.empty());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyValue() {}
|
||||
|
||||
@Override
|
||||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
final Minecraft mc = Minecraft.getInstance();
|
||||
guiGraphics.blitWithBorder(SLIDER_LOCATION, this.getX(), this.getY(), 0, getTextureY(), this.width, this.height, 200, 20, 2, 3, 2, 2);
|
||||
|
||||
guiGraphics.blitWithBorder(SLIDER_LOCATION, this.getX() + (int)(this.value * (double)(this.width - 8)), this.getY(), 0, getHandleTextureY(), 8, this.height, 200, 20 , 2, 3, 2, 2);
|
||||
guiGraphics.blitSprite(this.getSprite(), this.getX(), this.getY(), this.getWidth(), this.getHeight());
|
||||
guiGraphics.blitSprite(this.getHandleSprite(), this.getX() + (int)(this.value * (double)(this.width - 8)), this.getY(), 8, this.getHeight());
|
||||
|
||||
renderScrollingString(guiGraphics, mc.font, 2, getFGColor() | Mth.ceil(this.alpha * 255.0F) << 24);
|
||||
}
|
||||
|
||||
@@ -54,9 +54,9 @@ public class ModListWidget extends ObjectSelectionList<ModListWidget.ModEntry>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBackground(GuiGraphics guiGraphics)
|
||||
{
|
||||
this.parent.renderBackground(guiGraphics);
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
|
||||
this.parent.renderBackground(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
super.render(guiGraphics, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
public class ModEntry extends ObjectSelectionList.Entry<ModEntry> {
|
||||
|
||||
@@ -25,8 +25,7 @@ import java.util.List;
|
||||
/**
|
||||
* Abstract scroll panel class.
|
||||
*/
|
||||
public abstract class ScrollPanel extends AbstractContainerEventHandler implements Renderable, NarratableEntry
|
||||
{
|
||||
public abstract class ScrollPanel extends AbstractContainerEventHandler implements Renderable, NarratableEntry {
|
||||
private final Minecraft client;
|
||||
protected final int width;
|
||||
protected final int height;
|
||||
@@ -54,8 +53,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
* @param top the offset from the top (y coord)
|
||||
* @param left the offset from the left (x coord)
|
||||
*/
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left)
|
||||
{
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left) {
|
||||
this(client, width, height, top, left, 4);
|
||||
}
|
||||
|
||||
@@ -67,8 +65,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
* @param left the offset from the left (x coord)
|
||||
* @param border the size of the border
|
||||
*/
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border)
|
||||
{
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border) {
|
||||
this(client, width, height, top, left, border, 6);
|
||||
}
|
||||
|
||||
@@ -81,8 +78,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
* @param border the size of the border
|
||||
* @param barWidth the width of the scroll bar
|
||||
*/
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border, int barWidth)
|
||||
{
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border, int barWidth) {
|
||||
this(client, width, height, top, left, border, barWidth, 0xC0101010, 0xD0101010);
|
||||
}
|
||||
|
||||
@@ -96,8 +92,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
* @param barWidth the width of the scroll bar
|
||||
* @param bgColor the color for the background
|
||||
*/
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border, int barWidth, int bgColor)
|
||||
{
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border, int barWidth, int bgColor) {
|
||||
this(client, width, height, top, left, border, barWidth, bgColor, bgColor);
|
||||
}
|
||||
|
||||
@@ -112,8 +107,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
* @param bgColorFrom the start color for the background gradient
|
||||
* @param bgColorTo the end color for the background gradient
|
||||
*/
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border, int barWidth, int bgColorFrom, int bgColorTo)
|
||||
{
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border, int barWidth, int bgColorFrom, int bgColorTo) {
|
||||
this(client, width, height, top, left, border, barWidth, bgColorFrom, bgColorTo, 0xFF000000, 0xFF808080, 0xFFC0C0C0);
|
||||
}
|
||||
|
||||
@@ -133,8 +127,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
* @param barColor the color for the scroll bar handle
|
||||
* @param barBorderColor the border color for the scroll bar handle
|
||||
*/
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border, int barWidth, int bgColorFrom, int bgColorTo, int barBgColor, int barColor, int barBorderColor)
|
||||
{
|
||||
public ScrollPanel(Minecraft client, int width, int height, int top, int left, int border, int barWidth, int bgColorFrom, int bgColorTo, int barBgColor, int barColor, int barBorderColor) {
|
||||
this.client = client;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
@@ -157,16 +150,12 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
/**
|
||||
* Draws the background of the scroll panel. This runs AFTER Scissors are enabled.
|
||||
*/
|
||||
protected void drawBackground(GuiGraphics guiGraphics, Tesselator tess, float partialTick)
|
||||
{
|
||||
protected void drawBackground(GuiGraphics guiGraphics, Tesselator tess, float partialTick) {
|
||||
BufferBuilder worldr = tess.getBuilder();
|
||||
|
||||
if (this.client.level != null)
|
||||
{
|
||||
if (this.client.level != null) {
|
||||
this.drawGradientRect(guiGraphics, this.left, this.top, this.right, this.bottom, bgColorFrom, bgColorTo);
|
||||
}
|
||||
else // Draw dark dirt background
|
||||
{
|
||||
} else { // Draw dark dirt background
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexColorShader);
|
||||
RenderSystem.setShaderTexture(0, Screen.BACKGROUND_LOCATION);
|
||||
final float texScale = 32.0F;
|
||||
@@ -185,38 +174,31 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
*/
|
||||
protected abstract void drawPanel(GuiGraphics guiGraphics, int entryRight, int relativeY, Tesselator tess, int mouseX, int mouseY);
|
||||
|
||||
protected boolean clickPanel(double mouseX, double mouseY, int button) { return false; }
|
||||
protected boolean clickPanel(double mouseX, double mouseY, int button) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getMaxScroll()
|
||||
{
|
||||
private int getMaxScroll() {
|
||||
return this.getContentHeight() - (this.height - this.border);
|
||||
}
|
||||
|
||||
private void applyScrollLimits()
|
||||
{
|
||||
private void applyScrollLimits() {
|
||||
int max = getMaxScroll();
|
||||
|
||||
if (max < 0)
|
||||
{
|
||||
max /= 2;
|
||||
}
|
||||
|
||||
if (this.scrollDistance < 0.0F)
|
||||
{
|
||||
this.scrollDistance = 0.0F;
|
||||
}
|
||||
|
||||
if (this.scrollDistance > max)
|
||||
{
|
||||
this.scrollDistance = max;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double scroll)
|
||||
{
|
||||
if (scroll != 0)
|
||||
{
|
||||
public boolean mouseScrolled(double mouseX, double mouseY, double deltaX, double deltaY) {
|
||||
double scroll = deltaX == 0 ? deltaY : deltaX;
|
||||
if (scroll != 0) {
|
||||
this.scrollDistance += -scroll * getScrollAmount();
|
||||
applyScrollLimits();
|
||||
return true;
|
||||
@@ -224,49 +206,42 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
return false;
|
||||
}
|
||||
|
||||
protected int getScrollAmount()
|
||||
{
|
||||
protected int getScrollAmount() {
|
||||
return 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMouseOver(double mouseX, double mouseY)
|
||||
{
|
||||
public boolean isMouseOver(double mouseX, double mouseY) {
|
||||
return mouseX >= this.left && mouseX <= this.left + this.width &&
|
||||
mouseY >= this.top && mouseY <= this.bottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button)
|
||||
{
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
if (super.mouseClicked(mouseX, mouseY, button))
|
||||
return true;
|
||||
|
||||
this.scrolling = button == 0 && mouseX >= barLeft && mouseX < barLeft + barWidth;
|
||||
if (this.scrolling)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
int mouseListY = ((int)mouseY) - this.top - this.getContentHeight() + (int)this.scrollDistance - border;
|
||||
if (mouseX >= left && mouseX <= right && mouseListY < 0)
|
||||
{
|
||||
return this.clickPanel(mouseX - left, mouseY - this.top + (int)this.scrollDistance - border, button);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button)
|
||||
{
|
||||
public boolean mouseReleased(double mouseX, double mouseY, int button) {
|
||||
if (super.mouseReleased(mouseX, mouseY, button))
|
||||
return true;
|
||||
|
||||
boolean ret = this.scrolling;
|
||||
this.scrolling = false;
|
||||
return ret;
|
||||
}
|
||||
|
||||
private int getBarHeight()
|
||||
{
|
||||
private int getBarHeight() {
|
||||
int barHeight = (height * height) / this.getContentHeight();
|
||||
|
||||
if (barHeight < 32) barHeight = 32;
|
||||
@@ -278,10 +253,8 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY)
|
||||
{
|
||||
if (this.scrolling)
|
||||
{
|
||||
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
|
||||
if (this.scrolling) {
|
||||
int maxScroll = height - getBarHeight();
|
||||
double moved = deltaY / maxScroll;
|
||||
this.scrollDistance += getMaxScroll() * moved;
|
||||
@@ -292,8 +265,7 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
|
||||
{
|
||||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
|
||||
Tesselator tess = Tesselator.getInstance();
|
||||
BufferBuilder worldr = tess.getBuilder();
|
||||
|
||||
@@ -309,15 +281,12 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
RenderSystem.disableDepthTest();
|
||||
|
||||
int extraHeight = (this.getContentHeight() + border) - height;
|
||||
if (extraHeight > 0)
|
||||
{
|
||||
if (extraHeight > 0) {
|
||||
int barHeight = getBarHeight();
|
||||
|
||||
int barTop = (int)this.scrollDistance * (height - barHeight) / extraHeight + this.top;
|
||||
if (barTop < this.top)
|
||||
{
|
||||
barTop = this.top;
|
||||
}
|
||||
|
||||
int barBgAlpha = this.barBgColor >> 24 & 0xff;
|
||||
int barBgRed = this.barBgColor >> 16 & 0xff;
|
||||
@@ -361,14 +330,12 @@ public abstract class ScrollPanel extends AbstractContainerEventHandler implemen
|
||||
RenderSystem.disableScissor();
|
||||
}
|
||||
|
||||
protected void drawGradientRect(GuiGraphics guiGraphics, int left, int top, int right, int bottom, int color1, int color2)
|
||||
{
|
||||
protected void drawGradientRect(GuiGraphics guiGraphics, int left, int top, int right, int bottom, int color1, int color2) {
|
||||
guiGraphics.fillGradient(left, top, right, bottom, color1, color2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends GuiEventListener> children()
|
||||
{
|
||||
public List<? extends GuiEventListener> children() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -33,8 +33,7 @@ public class UnicodeGlyphButton extends ExtendedButton
|
||||
{
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
this.isHovered = mouseX >= this.getX() && mouseY >= this.getY() && mouseX < this.getX() + this.width && mouseY < this.getY() + this.height;
|
||||
int k = !this.active ? 0 : (this.isHoveredOrFocused() ? 2 : 1);
|
||||
guiGraphics.blitWithBorder(WIDGETS_LOCATION, this.getX(), this.getY(), 0, 46 + k * 20, this.width, this.height, 200, 20, 2, 3, 2, 2);
|
||||
guiGraphics.blitSprite(SPRITES.get(this.active, this.isHoveredOrFocused()), this.getX(), this.getY(), this.getWidth(), this.getHeight());
|
||||
|
||||
Component buttonText = this.createNarrationMessage();
|
||||
int glyphWidth = (int) (mc.font.width(glyph) * glyphScale);
|
||||
|
||||
@@ -11,11 +11,13 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
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.repository.Pack.Info;
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener;
|
||||
import net.minecraft.server.packs.repository.PackSource;
|
||||
import net.minecraft.server.packs.resources.ReloadableResourceManager;
|
||||
@@ -37,6 +39,7 @@ import org.apache.logging.log4j.Logger;
|
||||
import net.minecraft.SharedConstants;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.server.packs.PackResources;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
@@ -163,9 +166,23 @@ public class ClientModLoader
|
||||
var hiddenPacks = new ArrayList<PathPackResources>();
|
||||
for (Entry<IModFile, ? extends PathPackResources> e : modResourcePacks.entrySet())
|
||||
{
|
||||
|
||||
var supplier = new Pack.ResourcesSupplier() {
|
||||
@Override
|
||||
public PackResources openPrimary(String path) {
|
||||
return e.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources openFull(String path, Info info) {
|
||||
return e.getValue(); // TODO: composite
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
IModInfo mod = e.getKey().getModInfos().get(0);
|
||||
final String name = "mod:" + mod.getModId();
|
||||
final Pack modPack = Pack.readMetaAndCreate(name, Component.literal(e.getValue().packId()), false, id -> e.getValue(), PackType.CLIENT_RESOURCES, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
final Pack modPack = Pack.readMetaAndCreate(name, Component.literal(e.getValue().packId()), false, supplier, PackType.CLIENT_RESOURCES, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
if (modPack == null) {
|
||||
// Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
|
||||
ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
|
||||
@@ -178,11 +195,30 @@ public class ClientModLoader
|
||||
hiddenPacks.add(e.getValue());
|
||||
}
|
||||
}
|
||||
var delegating = new DelegatingPackResources("mod_resources", false,
|
||||
new PackMetadataSection(
|
||||
Component.translatable("fml.resources.modresources", hiddenPacks.size()),
|
||||
SharedConstants.getCurrentVersion().getPackVersion(PackType.CLIENT_RESOURCES),
|
||||
Optional.empty()
|
||||
),
|
||||
hiddenPacks
|
||||
);
|
||||
|
||||
var supplier = new Pack.ResourcesSupplier() {
|
||||
@Override
|
||||
public PackResources openPrimary(String path) {
|
||||
return delegating;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources openFull(String path, Info info) {
|
||||
return delegating; // TODO: composite
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// Create a resource pack merging all mod resources that should be hidden
|
||||
final Pack modResourcesPack = Pack.readMetaAndCreate("mod_resources", Component.literal("Mod Resources"), true,
|
||||
id -> new DelegatingPackResources(id, false, new PackMetadataSection(Component.translatable("fml.resources.modresources", hiddenPacks.size()),
|
||||
SharedConstants.getCurrentVersion().getPackVersion(PackType.CLIENT_RESOURCES)), hiddenPacks),
|
||||
final Pack modResourcesPack = Pack.readMetaAndCreate("mod_resources", Component.literal("Mod Resources"), true, supplier,
|
||||
PackType.CLIENT_RESOURCES, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
packAcceptor.accept(modResourcesPack);
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ package net.minecraftforge.client.textures;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.metadata.animation.AnimationMetadataSection;
|
||||
import net.minecraft.client.resources.metadata.animation.FrameSize;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceMetadata;
|
||||
import net.minecraftforge.client.event.RegisterTextureAtlasSpriteLoadersEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -29,10 +29,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
*
|
||||
* @see RegisterTextureAtlasSpriteLoadersEvent
|
||||
*/
|
||||
public interface ITextureAtlasSpriteLoader
|
||||
{
|
||||
SpriteContents loadContents(ResourceLocation name, Resource resource, FrameSize frameSize, NativeImage image,
|
||||
AnimationMetadataSection animationMeta, ForgeTextureMetadata forgeMeta);
|
||||
public interface ITextureAtlasSpriteLoader {
|
||||
SpriteContents loadContents(ResourceLocation name, Resource resource, FrameSize frameSize, NativeImage image, ResourceMetadata animationMeta, ForgeTextureMetadata forgeMeta);
|
||||
|
||||
/**
|
||||
* Creates a {@link TextureAtlasSprite} from the given {@link SpriteContents}.
|
||||
|
||||
@@ -7,36 +7,31 @@ package net.minecraftforge.client.textures;
|
||||
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import net.minecraft.client.renderer.texture.SpriteContents;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.metadata.animation.AnimationMetadataSection;
|
||||
import net.minecraft.client.resources.metadata.animation.FrameSize;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceMetadata;
|
||||
|
||||
/**
|
||||
* A helper sprite with UVs spanning the entire texture.
|
||||
* <p>
|
||||
* Useful for baking quads that won't be used with an atlas.
|
||||
*/
|
||||
public class UnitTextureAtlasSprite extends TextureAtlasSprite
|
||||
{
|
||||
public class UnitTextureAtlasSprite extends TextureAtlasSprite {
|
||||
public static final ResourceLocation LOCATION = new ResourceLocation("forge", "unit");
|
||||
public static final UnitTextureAtlasSprite INSTANCE = new UnitTextureAtlasSprite();
|
||||
|
||||
private UnitTextureAtlasSprite()
|
||||
{
|
||||
super(LOCATION, new SpriteContents(LOCATION, new FrameSize(1, 1), new NativeImage(1, 1, false), AnimationMetadataSection.EMPTY, null), 1, 1, 0, 0);
|
||||
private UnitTextureAtlasSprite() {
|
||||
super(LOCATION, new SpriteContents(LOCATION, new FrameSize(1, 1), new NativeImage(1, 1, false), ResourceMetadata.EMPTY, null), 1, 1, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getU(double u)
|
||||
{
|
||||
return (float) u / 16;
|
||||
public float getU(float u) {
|
||||
return u / 16;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getV(double v)
|
||||
{
|
||||
return (float) v / 16;
|
||||
public float getV(float v) {
|
||||
return v / 16;
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,7 @@ import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.FilteredText;
|
||||
import net.minecraft.world.inventory.AnvilMenu;
|
||||
import net.minecraft.world.Container;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
@@ -127,9 +128,6 @@ import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSpecialEffects;
|
||||
import net.minecraft.world.level.biome.BiomeGenerationSettings;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.loot.LootModifierManager;
|
||||
import net.minecraftforge.common.loot.LootTableIdCondition;
|
||||
import net.minecraftforge.common.util.BlockSnapshot;
|
||||
import net.minecraftforge.common.util.BrainBuilder;
|
||||
import net.minecraftforge.common.util.Lazy;
|
||||
@@ -400,29 +398,13 @@ public class ForgeHooks
|
||||
return !MinecraftForge.EVENT_BUS.post(new VanillaGameEvent(level, vanillaEvent, pos, context));
|
||||
}
|
||||
|
||||
private static String getRawText(Component message)
|
||||
{
|
||||
return message.getContents() instanceof LiteralContents literalContents ? literalContents.text() : "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Component onServerChatSubmittedEvent(ServerPlayer player, String plain, Component decorated)
|
||||
{
|
||||
ServerChatEvent event = new ServerChatEvent(player, plain, decorated);
|
||||
public static Component onServerChatSubmittedEvent(ServerPlayer player, Component message) {
|
||||
var plain = message.getContents() instanceof LiteralContents literalContents ? literalContents.text() : "";
|
||||
ServerChatEvent event = new ServerChatEvent(player, plain, message);
|
||||
return MinecraftForge.EVENT_BUS.post(event) ? null : event.getMessage();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ChatDecorator getServerChatSubmittedDecorator()
|
||||
{
|
||||
return (sender, message) -> CompletableFuture.supplyAsync(() -> {
|
||||
if (sender == null)
|
||||
return message; // Vanilla should never get here with the patches we use, but let's be safe with dumb mods
|
||||
|
||||
return onServerChatSubmittedEvent(sender, getRawText(message), message);
|
||||
});
|
||||
}
|
||||
|
||||
static final Pattern URL_PATTERN = Pattern.compile(
|
||||
// schema ipv4 OR namespace port path ends
|
||||
// |-----------------| |-------------------------| |-------------------------| |---------| |--| |---------------|
|
||||
@@ -738,13 +720,6 @@ public class ForgeHooks
|
||||
return stack.isEmpty() || !stack.getItem().onLeftClickEntity(stack, player, target);
|
||||
}
|
||||
|
||||
public static boolean onTravelToDimension(Entity entity, ResourceKey<Level> dimension)
|
||||
{
|
||||
EntityTravelToDimensionEvent event = new EntityTravelToDimensionEvent(entity, dimension);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
return !event.isCanceled();
|
||||
}
|
||||
|
||||
public static InteractionResult onInteractEntityAt(Player player, Entity entity, HitResult ray, InteractionHand hand)
|
||||
{
|
||||
Vec3 vec3d = ray.getLocation().subtract(entity.position());
|
||||
@@ -812,21 +787,18 @@ public class ForgeHooks
|
||||
MinecraftForge.EVENT_BUS.post(new PlayerInteractEvent.LeftClickEmpty(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null if game type should not be changed, desired new GameType otherwise
|
||||
*/
|
||||
@Nullable
|
||||
public static GameType onChangeGameType(Player player, GameType currentGameType, GameType newGameType)
|
||||
{
|
||||
if (currentGameType != newGameType)
|
||||
{
|
||||
PlayerEvent.PlayerChangeGameModeEvent evt = new PlayerEvent.PlayerChangeGameModeEvent(player, currentGameType, newGameType);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return evt.isCanceled() ? null : evt.getNewGameMode();
|
||||
}
|
||||
return newGameType;
|
||||
public static GameType onChangeGameType(Player player, GameType currentGameType, GameType newGameType) {
|
||||
if (currentGameType == newGameType)
|
||||
return currentGameType;
|
||||
|
||||
var evt = new PlayerEvent.PlayerChangeGameModeEvent(player, currentGameType, newGameType);
|
||||
if (MinecraftForge.EVENT_BUS.post(evt))
|
||||
return currentGameType;
|
||||
|
||||
return evt.getNewGameMode();
|
||||
}
|
||||
|
||||
/* TODO: GLM
|
||||
private static final ThreadLocal<Deque<LootTableContext>> lootContext = new ThreadLocal<>();
|
||||
private static LootTableContext getLootTableContext()
|
||||
{
|
||||
@@ -918,6 +890,7 @@ public class ForgeHooks
|
||||
|
||||
return ctx.poolCount == 1 ? "main" : "pool" + (ctx.poolCount - 1);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns a vanilla fluid type for the given fluid.
|
||||
@@ -1147,6 +1120,7 @@ public class ForgeHooks
|
||||
FurnaceBlockEntity.getFuel().entrySet().forEach(e -> VANILLA_BURNS.put(ForgeRegistries.ITEMS.getDelegateOrThrow(e.getKey()), e.getValue()));
|
||||
}
|
||||
|
||||
// TODO: GLM
|
||||
/**
|
||||
* All loot table drops should be passed to this function so that mod added effects
|
||||
* (e.g. smelting enchantments) can be processed.
|
||||
@@ -1159,7 +1133,7 @@ public class ForgeHooks
|
||||
*
|
||||
* @implNote This method will use the {@linkplain LootTableIdCondition#UNKNOWN_LOOT_TABLE
|
||||
* unknown loot table marker} when redirecting.
|
||||
*/
|
||||
* /
|
||||
@Deprecated
|
||||
public static List<ItemStack> modifyLoot(List<ItemStack> list, LootContext context) {
|
||||
return modifyLoot(LootTableIdCondition.UNKNOWN_LOOT_TABLE, ObjectArrayList.wrap((ItemStack[]) list.toArray()), context);
|
||||
@@ -1178,7 +1152,7 @@ public class ForgeHooks
|
||||
*
|
||||
* @apiNote The given context will be modified by this method to also store the ID of the
|
||||
* loot table being queried.
|
||||
*/
|
||||
* /
|
||||
public static ObjectArrayList<ItemStack> modifyLoot(ResourceLocation lootTableId, ObjectArrayList<ItemStack> generatedLoot, LootContext context) {
|
||||
context.setQueriedLootTableId(lootTableId); // In case the ID was set via copy constructor, this will be ignored: intended
|
||||
LootModifierManager man = ForgeInternalHandler.getLootModifierManager();
|
||||
@@ -1187,6 +1161,7 @@ public class ForgeHooks
|
||||
}
|
||||
return generatedLoot;
|
||||
}
|
||||
*/
|
||||
|
||||
public static List<String> getModPacks()
|
||||
{
|
||||
@@ -1417,33 +1392,6 @@ public class ForgeHooks
|
||||
throw new IllegalArgumentException("Unknown lifecycle.");
|
||||
}
|
||||
|
||||
public static void saveMobEffect(CompoundTag nbt, String key, MobEffect effect)
|
||||
{
|
||||
var registryName = ForgeRegistries.MOB_EFFECTS.getKey(effect);
|
||||
if (registryName != null)
|
||||
{
|
||||
nbt.putString(key, registryName.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MobEffect loadMobEffect(CompoundTag nbt, String key, @Nullable MobEffect fallback)
|
||||
{
|
||||
var registryName = nbt.getString(key);
|
||||
if (Strings.isNullOrEmpty(registryName))
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
try
|
||||
{
|
||||
return ForgeRegistries.MOB_EFFECTS.getValue(new ResourceLocation(registryName));
|
||||
}
|
||||
catch (ResourceLocationException e)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean shouldSuppressEnderManAnger(EnderMan enderMan, Player player, ItemStack mask)
|
||||
{
|
||||
return mask.isEnderMask(player, enderMan) || MinecraftForge.EVENT_BUS.post(new EnderManAngerEvent(enderMan, player));
|
||||
@@ -1474,40 +1422,6 @@ public class ForgeHooks
|
||||
return biomeLocation != null && !biomeLocation.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE);
|
||||
}
|
||||
|
||||
public static Map<PackType, Integer> readTypedPackFormats(JsonObject json)
|
||||
{
|
||||
ImmutableMap.Builder<PackType, Integer> map = ImmutableMap.builder();
|
||||
|
||||
for (PackType packType : PackType.values())
|
||||
{
|
||||
String key = makePackFormatKey(packType);
|
||||
if (json.has(key))
|
||||
{
|
||||
map.put(packType, GsonHelper.getAsInt(json, key));
|
||||
}
|
||||
}
|
||||
|
||||
return map.buildOrThrow();
|
||||
}
|
||||
|
||||
public static void writeTypedPackFormats(JsonObject json, PackMetadataSection section)
|
||||
{
|
||||
int packFormat = section.getPackFormat();
|
||||
for (PackType packType : PackType.values())
|
||||
{
|
||||
int format = section.getPackFormat(packType);
|
||||
if (format != packFormat)
|
||||
{
|
||||
json.addProperty(makePackFormatKey(packType), format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String makePackFormatKey(PackType packType)
|
||||
{
|
||||
return "forge:" + packType.name().toLowerCase(Locale.ROOT) + "_pack_format";
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This method is used to prefix the path, where elements of the associated registry are stored, with their namespace, if it is not minecraft
|
||||
@@ -1569,7 +1483,7 @@ public class ForgeHooks
|
||||
*/
|
||||
public static void onLivingBreathe(LivingEntity entity, int consumeAirAmount, int refillAirAmount)
|
||||
{
|
||||
// Check things that vanilla considers to be air - these will cause the air supply to be increased.
|
||||
// Check things that vanilla considers to be air - these will cause the air supply to be increased.
|
||||
boolean isAir = entity.getEyeInFluidType().isAir() || entity.level().getBlockState(BlockPos.containing(entity.getX(), entity.getEyeY(), entity.getZ())).is(Blocks.BUBBLE_COLUMN);
|
||||
// The following effects cause the entity to not drown, but do not cause the air supply to be increased.
|
||||
boolean canBreathe = !entity.canDrownInFluidType(entity.getEyeInFluidType()) || MobEffectUtil.hasWaterBreathing(entity) || (entity instanceof Player && ((Player) entity).getAbilities().invulnerable);
|
||||
|
||||
@@ -12,7 +12,6 @@ import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.server.TickTask;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.common.loot.LootModifierManager;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.event.AddReloadListenerEvent;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
@@ -114,6 +113,7 @@ public class ForgeInternalHandler
|
||||
ConfigCommand.register(event.getDispatcher());
|
||||
}
|
||||
|
||||
/*
|
||||
private static LootModifierManager INSTANCE;
|
||||
|
||||
@SubscribeEvent
|
||||
@@ -129,6 +129,7 @@ public class ForgeInternalHandler
|
||||
throw new IllegalStateException("Can not retrieve LootModifierManager until resources have loaded once.");
|
||||
return INSTANCE;
|
||||
}
|
||||
*/
|
||||
|
||||
@SubscribeEvent
|
||||
public void resourceReloadListeners(AddReloadListenerEvent event)
|
||||
|
||||
@@ -43,9 +43,6 @@ import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.pathfinder.BlockPathTypes;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
|
||||
import net.minecraftforge.common.crafting.PartialNBTIngredient;
|
||||
import net.minecraftforge.common.crafting.DifferenceIngredient;
|
||||
import net.minecraftforge.common.crafting.IntersectionIngredient;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.common.data.ForgeBiomeTagsProvider;
|
||||
import net.minecraftforge.common.data.ForgeFluidTagsProvider;
|
||||
@@ -53,8 +50,6 @@ import net.minecraftforge.common.data.ForgeSpriteSourceProvider;
|
||||
import net.minecraftforge.common.data.VanillaSoundDefinitionsProvider;
|
||||
import net.minecraftforge.common.extensions.IForgeEntity;
|
||||
import net.minecraftforge.common.extensions.IForgePlayer;
|
||||
import net.minecraftforge.common.loot.CanToolPerformAction;
|
||||
import net.minecraftforge.common.loot.LootTableIdCondition;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.common.world.ForgeBiomeModifiers.AddFeaturesBiomeModifier;
|
||||
import net.minecraftforge.common.world.ForgeBiomeModifiers.AddSpawnsBiomeModifier;
|
||||
@@ -80,7 +75,6 @@ import net.minecraftforge.network.NetworkConstants;
|
||||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.data.event.GatherDataEvent;
|
||||
import net.minecraftforge.network.filters.VanillaPacketSplitter;
|
||||
import net.minecraftforge.server.command.EnumArgument;
|
||||
import net.minecraftforge.server.command.ModIdArgument;
|
||||
import net.minecraftforge.server.permission.events.PermissionGatherEvent;
|
||||
@@ -94,11 +88,7 @@ import org.apache.logging.log4j.Logger;
|
||||
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.common.crafting.CompoundIngredient;
|
||||
import net.minecraftforge.common.crafting.ConditionalRecipe;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.StrictNBTIngredient;
|
||||
import net.minecraftforge.common.crafting.VanillaIngredientSerializer;
|
||||
import net.minecraftforge.common.crafting.conditions.AndCondition;
|
||||
import net.minecraftforge.common.crafting.conditions.FalseCondition;
|
||||
import net.minecraftforge.common.crafting.conditions.ItemExistsCondition;
|
||||
@@ -110,7 +100,6 @@ import net.minecraftforge.common.crafting.conditions.TrueCondition;
|
||||
import net.minecraftforge.common.data.ForgeBlockTagsProvider;
|
||||
import net.minecraftforge.common.data.ForgeEntityTypeTagsProvider;
|
||||
import net.minecraftforge.common.data.ForgeItemTagsProvider;
|
||||
import net.minecraftforge.common.data.ForgeLootTableProvider;
|
||||
import net.minecraftforge.common.data.ForgeRecipeProvider;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
@@ -476,7 +465,7 @@ public class ForgeMod
|
||||
public void preInit(FMLCommonSetupEvent evt)
|
||||
{
|
||||
VersionChecker.startVersionCheck();
|
||||
VanillaPacketSplitter.register();
|
||||
//VanillaPacketSplitter.register();
|
||||
}
|
||||
|
||||
public void loadComplete(FMLLoadCompleteEvent event)
|
||||
@@ -501,11 +490,11 @@ public class ForgeMod
|
||||
|
||||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper();
|
||||
gen.addProvider(true, new PackMetadataGenerator(packOutput)
|
||||
.add(PackMetadataSection.TYPE, new PackMetadataSection(
|
||||
Component.translatable("pack.forge.description"),
|
||||
DetectedVersion.BUILT_IN.getPackVersion(PackType.CLIENT_RESOURCES),
|
||||
Arrays.stream(PackType.values()).collect(Collectors.toMap(Function.identity(), DetectedVersion.BUILT_IN::getPackVersion))
|
||||
))
|
||||
.add(PackMetadataSection.TYPE, new PackMetadataSection(
|
||||
Component.translatable("pack.forge.description"),
|
||||
DetectedVersion.BUILT_IN.getPackVersion(PackType.CLIENT_RESOURCES),
|
||||
Optional.empty() //Arrays.stream(PackType.values()).collect(Collectors.toMap(Function.identity(), DetectedVersion.BUILT_IN::getPackVersion))
|
||||
))
|
||||
);
|
||||
ForgeBlockTagsProvider blockTags = new ForgeBlockTagsProvider(packOutput, lookupProvider, existingFileHelper);
|
||||
gen.addProvider(event.includeServer(), blockTags);
|
||||
@@ -513,7 +502,7 @@ public class ForgeMod
|
||||
gen.addProvider(event.includeServer(), new ForgeEntityTypeTagsProvider(packOutput, lookupProvider, existingFileHelper));
|
||||
gen.addProvider(event.includeServer(), new ForgeFluidTagsProvider(packOutput, lookupProvider, existingFileHelper));
|
||||
gen.addProvider(event.includeServer(), new ForgeRecipeProvider(packOutput));
|
||||
gen.addProvider(event.includeServer(), new ForgeLootTableProvider(packOutput));
|
||||
//gen.addProvider(event.includeServer(), new ForgeLootTableProvider(packOutput));
|
||||
gen.addProvider(event.includeServer(), new ForgeBiomeTagsProvider(packOutput, lookupProvider, existingFileHelper));
|
||||
|
||||
gen.addProvider(event.includeClient(), new ForgeSpriteSourceProvider(packOutput, existingFileHelper));
|
||||
@@ -621,14 +610,16 @@ public class ForgeMod
|
||||
CraftingHelper.register(TrueCondition.Serializer.INSTANCE);
|
||||
CraftingHelper.register(TagEmptyCondition.Serializer.INSTANCE);
|
||||
|
||||
/*
|
||||
CraftingHelper.register(new ResourceLocation("forge", "compound"), CompoundIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "nbt"), StrictNBTIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "partial_nbt"), PartialNBTIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "difference"), DifferenceIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("forge", "intersection"), IntersectionIngredient.Serializer.INSTANCE);
|
||||
CraftingHelper.register(new ResourceLocation("minecraft", "item"), VanillaIngredientSerializer.INSTANCE);
|
||||
*/
|
||||
|
||||
event.register(ForgeRegistries.Keys.RECIPE_SERIALIZERS, new ResourceLocation("forge", "conditional"), ConditionalRecipe.Serializer::new);
|
||||
//event.register(ForgeRegistries.Keys.RECIPE_SERIALIZERS, new ResourceLocation("forge", "conditional"), ConditionalRecipe.Serializer::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -637,8 +628,8 @@ public class ForgeMod
|
||||
if (!event.getRegistryKey().equals(Registries.LOOT_CONDITION_TYPE))
|
||||
return;
|
||||
|
||||
event.register(Registries.LOOT_CONDITION_TYPE, new ResourceLocation("forge:loot_table_id"), () -> LootTableIdCondition.LOOT_TABLE_ID);
|
||||
event.register(Registries.LOOT_CONDITION_TYPE, new ResourceLocation("forge:can_tool_perform_action"), () -> CanToolPerformAction.LOOT_CONDITION_TYPE);
|
||||
//event.register(Registries.LOOT_CONDITION_TYPE, new ResourceLocation("forge:loot_table_id"), () -> LootTableIdCondition.LOOT_TABLE_ID);
|
||||
//event.register(Registries.LOOT_CONDITION_TYPE, new ResourceLocation("forge:can_tool_perform_action"), () -> CanToolPerformAction.LOOT_CONDITION_TYPE);
|
||||
}
|
||||
|
||||
public static final PermissionNode<Boolean> USE_SELECTORS_PERMISSION = new PermissionNode<>("forge", "use_entity_selectors",
|
||||
|
||||
@@ -351,7 +351,7 @@ public class TierSortingRegistry
|
||||
|
||||
private static void syncToPlayer(ServerPlayer serverPlayer)
|
||||
{
|
||||
if (SYNC_CHANNEL.isRemotePresent(serverPlayer.connection.connection) && !serverPlayer.connection.connection.isMemoryConnection())
|
||||
if (SYNC_CHANNEL.isRemotePresent(serverPlayer.connection.getConnection()) && !serverPlayer.connection.getConnection().isMemoryConnection())
|
||||
{
|
||||
SYNC_CHANNEL.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new SyncPacket(sortedTiers.stream().map(TierSortingRegistry::getName).toList()));
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import com.google.gson.JsonElement;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.tags.TagKey;
|
||||
@@ -19,18 +19,15 @@ import java.util.stream.Stream;
|
||||
/**
|
||||
* Extension of {@link Ingredient} which makes most methods custom ingredients need to implement abstract, and removes the static constructors
|
||||
* Mods are encouraged to extend this class for their custom ingredients
|
||||
*/
|
||||
public abstract class AbstractIngredient extends Ingredient
|
||||
{
|
||||
/** Empty constructor, for the sake of dynamic ingredients */
|
||||
protected AbstractIngredient()
|
||||
{
|
||||
* /
|
||||
public abstract class AbstractIngredient extends Ingredient {
|
||||
/** Empty constructor, for the sake of dynamic ingredients * /
|
||||
protected AbstractIngredient() {
|
||||
super(Stream.of());
|
||||
}
|
||||
|
||||
/** Value constructor, for ingredients that have some vanilla representation */
|
||||
protected AbstractIngredient(Stream<? extends Value> values)
|
||||
{
|
||||
/** Value constructor, for ingredients that have some vanilla representation * /
|
||||
protected AbstractIngredient(Stream<? extends Value> values) {
|
||||
super(values);
|
||||
}
|
||||
|
||||
@@ -41,64 +38,57 @@ public abstract class AbstractIngredient extends Ingredient
|
||||
public abstract IIngredientSerializer<? extends Ingredient> getSerializer();
|
||||
|
||||
@Override
|
||||
public abstract JsonElement toJson();
|
||||
public abstract JsonElement toJson(boolean allowEmpty);
|
||||
|
||||
|
||||
/* Hide vanilla ingredient static constructors to reduce errors with constructing custom ingredients */
|
||||
/* Hide vanilla ingredient static constructors to reduce errors with constructing custom ingredients * /
|
||||
|
||||
/** @deprecated use {@link Ingredient#fromValues(Stream)} */
|
||||
/** @deprecated use {@link Ingredient#fromValues(Stream)} * /
|
||||
@Deprecated
|
||||
public static Ingredient fromValues(Stream<? extends Ingredient.Value> values)
|
||||
{
|
||||
public static Ingredient fromValues(Stream<? extends Ingredient.Value> values) {
|
||||
throw new UnsupportedOperationException("Use Ingredient.fromValues()");
|
||||
}
|
||||
|
||||
/** @deprecated use {@link Ingredient#of()} */
|
||||
/** @deprecated use {@link Ingredient#of()} * /
|
||||
@Deprecated
|
||||
public static Ingredient of()
|
||||
{
|
||||
public static Ingredient of() {
|
||||
throw new UnsupportedOperationException("Use Ingredient.of()");
|
||||
}
|
||||
|
||||
/** @deprecated use {@link Ingredient#of(ItemLike...)} (Stream)} */
|
||||
/** @deprecated use {@link Ingredient#of(ItemLike...)} (Stream)} * /
|
||||
@Deprecated
|
||||
public static Ingredient of(ItemLike... items)
|
||||
{
|
||||
public static Ingredient of(ItemLike... items) {
|
||||
throw new UnsupportedOperationException("Use Ingredient.of()");
|
||||
}
|
||||
|
||||
/** @deprecated use {@link Ingredient#of(ItemStack...)} (Stream)} */
|
||||
/** @deprecated use {@link Ingredient#of(ItemStack...)} (Stream)} * /
|
||||
@Deprecated
|
||||
public static Ingredient of(ItemStack... stacks)
|
||||
{
|
||||
public static Ingredient of(ItemStack... stacks) {
|
||||
throw new UnsupportedOperationException("Use Ingredient.of()");
|
||||
}
|
||||
|
||||
/** @deprecated use {@link Ingredient#of(Stream)} (Stream)} */
|
||||
/** @deprecated use {@link Ingredient#of(Stream)} (Stream)} * /
|
||||
@Deprecated
|
||||
public static Ingredient of(Stream<ItemStack> stacks)
|
||||
{
|
||||
public static Ingredient of(Stream<ItemStack> stacks) {
|
||||
throw new UnsupportedOperationException("Use Ingredient.of()");
|
||||
}
|
||||
|
||||
/** @deprecated use {@link Ingredient#of(TagKey)} (Stream)} */
|
||||
/** @deprecated use {@link Ingredient#of(TagKey)} (Stream)} * /
|
||||
@Deprecated
|
||||
public static Ingredient of(TagKey<Item> tag)
|
||||
{
|
||||
public static Ingredient of(TagKey<Item> tag) {
|
||||
throw new UnsupportedOperationException("Use Ingredient.of()");
|
||||
}
|
||||
|
||||
/** @deprecated use {@link Ingredient#fromNetwork(FriendlyByteBuf)} */
|
||||
/** @deprecated use {@link Ingredient#fromNetwork(FriendlyByteBuf)} * /
|
||||
@Deprecated
|
||||
public static Ingredient fromNetwork(FriendlyByteBuf buffer)
|
||||
{
|
||||
public static Ingredient fromNetwork(FriendlyByteBuf buffer) {
|
||||
throw new UnsupportedOperationException("Use Ingredient.fromNetwork()");
|
||||
}
|
||||
|
||||
/** @deprecated use {@link Ingredient#fromJson(JsonElement)} (Stream)} */
|
||||
/** @deprecated use {@link Ingredient#fromJson(JsonElement)} (Stream)} * /
|
||||
@Deprecated
|
||||
public static Ingredient fromJson(@Nullable JsonElement json)
|
||||
{
|
||||
public static Ingredient fromJson(@Nullable JsonElement json) {
|
||||
throw new UnsupportedOperationException("Use Ingredient.fromJson()");
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -27,7 +27,7 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/** Ingredient that matches if any of the child ingredients match */
|
||||
/** Ingredient that matches if any of the child ingredients match * /
|
||||
public class CompoundIngredient extends AbstractIngredient
|
||||
{
|
||||
private List<Ingredient> children;
|
||||
@@ -41,7 +41,7 @@ public class CompoundIngredient extends AbstractIngredient
|
||||
this.isSimple = children.stream().allMatch(Ingredient::isSimple);
|
||||
}
|
||||
|
||||
/** Creates a compound ingredient from the given list of ingredients */
|
||||
/** Creates a compound ingredient from the given list of ingredients * /
|
||||
public static Ingredient of(Ingredient... children)
|
||||
{
|
||||
// if 0 or 1 ingredient, can save effort
|
||||
@@ -182,3 +182,4 @@ public class CompoundIngredient extends AbstractIngredient
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@@ -32,7 +32,7 @@ public class ConditionalAdvancement
|
||||
* Processes the conditional advancement during loading.
|
||||
* @param json The incoming json from the advancement file.
|
||||
* @return The advancement that passed the conditions, or null if none did.
|
||||
*/
|
||||
* /
|
||||
@Nullable
|
||||
public static JsonObject processConditional(JsonObject json, ICondition.IContext context) {
|
||||
JsonArray entries = GsonHelper.getAsJsonArray(json, "advancements", null);
|
||||
@@ -128,3 +128,4 @@ public class ConditionalAdvancement
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/* TODO: Conditional Recipes
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
@@ -14,6 +14,7 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
@@ -153,6 +154,7 @@ public class ConditionalRecipe
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class Finished implements FinishedRecipe
|
||||
{
|
||||
private final ResourceLocation id;
|
||||
@@ -189,19 +191,21 @@ public class ConditionalRecipe
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getId() {
|
||||
public ResourceLocation id() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getType()
|
||||
public RecipeSerializer<?> type()
|
||||
{
|
||||
return SERIALZIER;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JsonObject serializeAdvancement() {
|
||||
return adv == null ? null : adv.write();
|
||||
public AdvancementHolder advancement() {
|
||||
if (adv == null)
|
||||
return null;
|
||||
return new AdvancementHolder(advId, adv.)
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,3 +214,4 @@ public class ConditionalRecipe
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -6,13 +6,9 @@
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonArray;
|
||||
@@ -24,12 +20,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.common.crafting.conditions.IConditionSerializer;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.util.GsonHelper;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
@@ -38,28 +32,18 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.logging.log4j.Marker;
|
||||
import org.apache.logging.log4j.MarkerManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CraftingHelper
|
||||
{
|
||||
public class CraftingHelper {
|
||||
@SuppressWarnings("unused")
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
@SuppressWarnings("unused")
|
||||
private static final Marker CRAFTHELPER = MarkerManager.getMarker("CRAFTHELPER");
|
||||
private static Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
|
||||
private static final Map<ResourceLocation, IConditionSerializer<?>> conditions = new HashMap<>();
|
||||
/* TODO: Custom Ingredients
|
||||
private static final BiMap<ResourceLocation, IIngredientSerializer<?>> ingredients = HashBiMap.create();
|
||||
|
||||
public static IConditionSerializer<?> register(IConditionSerializer<?> serializer)
|
||||
{
|
||||
ResourceLocation key = serializer.getID();
|
||||
if (conditions.containsKey(key))
|
||||
throw new IllegalStateException("Duplicate recipe condition serializer: " + key);
|
||||
conditions.put(key, serializer);
|
||||
return serializer;
|
||||
}
|
||||
public static <T extends Ingredient> IIngredientSerializer<T> register(ResourceLocation key, IIngredientSerializer<T> serializer)
|
||||
{
|
||||
|
||||
public static <T extends Ingredient> IIngredientSerializer<T> register(ResourceLocation key, IIngredientSerializer<T> serializer) {
|
||||
if (ingredients.containsKey(key))
|
||||
throw new IllegalStateException("Duplicate recipe ingredient serializer: " + key);
|
||||
if (ingredients.containsValue(serializer))
|
||||
@@ -67,45 +51,40 @@ public class CraftingHelper
|
||||
ingredients.put(key, serializer);
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ResourceLocation getID(IIngredientSerializer<?> serializer)
|
||||
{
|
||||
public static ResourceLocation getID(IIngredientSerializer<?> serializer) {
|
||||
return ingredients.inverse().get(serializer);
|
||||
}
|
||||
public static <T extends Ingredient> void write(FriendlyByteBuf buffer, T ingredient)
|
||||
{
|
||||
|
||||
public static <T extends Ingredient> void write(FriendlyByteBuf buffer, T ingredient) {
|
||||
@SuppressWarnings("unchecked") //I wonder if there is a better way generic wise...
|
||||
IIngredientSerializer<T> serializer = (IIngredientSerializer<T>)ingredient.getSerializer();
|
||||
ResourceLocation key = ingredients.inverse().get(serializer);
|
||||
if (key == null)
|
||||
throw new IllegalArgumentException("Tried to serialize unregistered Ingredient: " + ingredient + " " + serializer);
|
||||
if (serializer != VanillaIngredientSerializer.INSTANCE)
|
||||
{
|
||||
if (serializer != VanillaIngredientSerializer.INSTANCE) {
|
||||
buffer.writeVarInt(-1); //Marker to know there is a custom ingredient
|
||||
buffer.writeResourceLocation(key);
|
||||
}
|
||||
serializer.write(buffer, ingredient);
|
||||
}
|
||||
|
||||
public static Ingredient getIngredient(ResourceLocation type, FriendlyByteBuf buffer)
|
||||
{
|
||||
public static Ingredient getIngredient(ResourceLocation type, FriendlyByteBuf buffer) {
|
||||
IIngredientSerializer<?> serializer = ingredients.get(type);
|
||||
if (serializer == null)
|
||||
throw new IllegalArgumentException("Can not deserialize unknown Ingredient type: " + type);
|
||||
return serializer.parse(buffer);
|
||||
}
|
||||
|
||||
public static Ingredient getIngredient(JsonElement json, boolean allowEmpty)
|
||||
{
|
||||
public static Ingredient getIngredient(JsonElement json, boolean allowEmpty) {
|
||||
if (json == null || json.isJsonNull())
|
||||
throw new JsonSyntaxException("Json cannot be null");
|
||||
|
||||
if (json.isJsonArray())
|
||||
{
|
||||
if (json.isJsonArray()) {
|
||||
List<Ingredient> ingredients = Lists.newArrayList();
|
||||
List<Ingredient> vanilla = Lists.newArrayList();
|
||||
json.getAsJsonArray().forEach((ele) ->
|
||||
{
|
||||
json.getAsJsonArray().forEach((ele) -> {
|
||||
Ingredient ing = CraftingHelper.getIngredient(ele, allowEmpty);
|
||||
|
||||
if (ing.getClass() == Ingredient.class) //Vanilla, Due to how we read it splits each itemstack, so we pull out to re-merge later
|
||||
@@ -117,12 +96,9 @@ public class CraftingHelper
|
||||
if (!vanilla.isEmpty())
|
||||
ingredients.add(Ingredient.merge(vanilla));
|
||||
|
||||
if (ingredients.size() == 0)
|
||||
{
|
||||
if (ingredients.size() == 0) {
|
||||
if (allowEmpty)
|
||||
{
|
||||
return Ingredient.EMPTY;
|
||||
}
|
||||
throw new JsonSyntaxException("Item array cannot be empty, at least one item must be defined");
|
||||
}
|
||||
|
||||
@@ -147,14 +123,13 @@ public class CraftingHelper
|
||||
|
||||
return serializer.parse(obj);
|
||||
}
|
||||
*/
|
||||
|
||||
public static ItemStack getItemStack(JsonObject json, boolean readNBT)
|
||||
{
|
||||
public static ItemStack getItemStack(JsonObject json, boolean readNBT) {
|
||||
return getItemStack(json, readNBT, false);
|
||||
}
|
||||
|
||||
public static Item getItem(String itemName, boolean disallowsAirInRecipe)
|
||||
{
|
||||
public static Item getItem(String itemName, boolean disallowsAirInRecipe) {
|
||||
ResourceLocation itemKey = new ResourceLocation(itemName);
|
||||
if (!ForgeRegistries.ITEMS.containsKey(itemKey))
|
||||
throw new JsonSyntaxException("Unknown item '" + itemName + "'");
|
||||
@@ -165,31 +140,24 @@ public class CraftingHelper
|
||||
return Objects.requireNonNull(item);
|
||||
}
|
||||
|
||||
public static CompoundTag getNBT(JsonElement element)
|
||||
{
|
||||
try
|
||||
{
|
||||
public static CompoundTag getNBT(JsonElement element) {
|
||||
try {
|
||||
if (element.isJsonObject())
|
||||
return TagParser.parseTag(GSON.toJson(element));
|
||||
else
|
||||
return TagParser.parseTag(GsonHelper.convertToString(element, "nbt"));
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
} catch (CommandSyntaxException e) {
|
||||
throw new JsonSyntaxException("Invalid NBT Entry: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getItemStack(JsonObject json, boolean readNBT, boolean disallowsAirInRecipe)
|
||||
{
|
||||
public static ItemStack getItemStack(JsonObject json, boolean readNBT, boolean disallowsAirInRecipe) {
|
||||
String itemName = GsonHelper.getAsString(json, "item");
|
||||
Item item = getItem(itemName, disallowsAirInRecipe);
|
||||
if (readNBT && json.has("nbt"))
|
||||
{
|
||||
if (readNBT && json.has("nbt")) {
|
||||
CompoundTag nbt = getNBT(json.get("nbt"));
|
||||
CompoundTag tmp = new CompoundTag();
|
||||
if (nbt.contains("ForgeCaps"))
|
||||
{
|
||||
if (nbt.contains("ForgeCaps")) {
|
||||
tmp.put("ForgeCaps", nbt.get("ForgeCaps"));
|
||||
nbt.remove("ForgeCaps");
|
||||
}
|
||||
@@ -204,13 +172,21 @@ public class CraftingHelper
|
||||
return new ItemStack(item, GsonHelper.getAsInt(json, "count", 1));
|
||||
}
|
||||
|
||||
public static boolean processConditions(JsonObject json, String memberName, ICondition.IContext context)
|
||||
{
|
||||
// CONDITIONS
|
||||
private static final Map<ResourceLocation, IConditionSerializer<?>> conditions = new HashMap<>();
|
||||
public static IConditionSerializer<?> register(IConditionSerializer<?> serializer) {
|
||||
ResourceLocation key = serializer.getID();
|
||||
if (conditions.containsKey(key))
|
||||
throw new IllegalStateException("Duplicate recipe condition serializer: " + key);
|
||||
conditions.put(key, serializer);
|
||||
return serializer;
|
||||
}
|
||||
|
||||
public static boolean processConditions(JsonObject json, String memberName, ICondition.IContext context) {
|
||||
return !json.has(memberName) || processConditions(GsonHelper.getAsJsonArray(json, memberName), context);
|
||||
}
|
||||
|
||||
public static boolean processConditions(JsonArray conditions, ICondition.IContext context)
|
||||
{
|
||||
public static boolean processConditions(JsonArray conditions, ICondition.IContext context) {
|
||||
for (int x = 0; x < conditions.size(); x++)
|
||||
{
|
||||
if (!conditions.get(x).isJsonObject())
|
||||
@@ -223,8 +199,7 @@ public class CraftingHelper
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ICondition getCondition(JsonObject json)
|
||||
{
|
||||
public static ICondition getCondition(JsonObject json) {
|
||||
ResourceLocation type = new ResourceLocation(GsonHelper.getAsString(json, "type"));
|
||||
IConditionSerializer<?> serializer = conditions.get(type);
|
||||
if (serializer == null)
|
||||
@@ -232,8 +207,7 @@ public class CraftingHelper
|
||||
return serializer.read(json);
|
||||
}
|
||||
|
||||
public static <T extends ICondition> JsonObject serialize(T condition)
|
||||
{
|
||||
public static <T extends ICondition> JsonObject serialize(T condition) {
|
||||
@SuppressWarnings("unchecked")
|
||||
IConditionSerializer<T> serializer = (IConditionSerializer<T>)conditions.get(condition.getID());
|
||||
if (serializer == null)
|
||||
@@ -241,13 +215,10 @@ public class CraftingHelper
|
||||
return serializer.getJson(condition);
|
||||
}
|
||||
|
||||
public static JsonArray serialize(ICondition... conditions)
|
||||
{
|
||||
public static JsonArray serialize(ICondition... conditions) {
|
||||
JsonArray arr = new JsonArray();
|
||||
for(ICondition iCond : conditions)
|
||||
{
|
||||
arr.add(serialize(iCond));
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
@@ -18,7 +18,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/** Ingredient that matches everything from the first ingredient that is not included in the second ingredient */
|
||||
/** Ingredient that matches everything from the first ingredient that is not included in the second ingredient * /
|
||||
public class DifferenceIngredient extends AbstractIngredient
|
||||
{
|
||||
private final Ingredient base;
|
||||
@@ -37,7 +37,7 @@ public class DifferenceIngredient extends AbstractIngredient
|
||||
* @param base Ingredient the item must match
|
||||
* @param subtracted Ingredient the item must not match
|
||||
* @return Ingredient that {@code base} anything in base that is not in {@code subtracted}
|
||||
*/
|
||||
* /
|
||||
public static DifferenceIngredient of(Ingredient base, Ingredient subtracted)
|
||||
{
|
||||
return new DifferenceIngredient(base, subtracted);
|
||||
@@ -98,12 +98,12 @@ public class DifferenceIngredient extends AbstractIngredient
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement toJson()
|
||||
public JsonElement toJson(boolean allowEmpty)
|
||||
{
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("type", CraftingHelper.getID(Serializer.INSTANCE).toString());
|
||||
json.add("base", base.toJson());
|
||||
json.add("subtracted", subtracted.toJson());
|
||||
json.add("base", base.toJson(allowEmpty));
|
||||
json.add("subtracted", subtracted.toJson(allowEmpty));
|
||||
return json;
|
||||
}
|
||||
|
||||
@@ -113,8 +113,7 @@ public class DifferenceIngredient extends AbstractIngredient
|
||||
return Serializer.INSTANCE;
|
||||
}
|
||||
|
||||
public static class Serializer implements IIngredientSerializer<DifferenceIngredient>
|
||||
{
|
||||
public static class Serializer implements IIngredientSerializer<DifferenceIngredient> {
|
||||
public static final IIngredientSerializer<DifferenceIngredient> INSTANCE = new Serializer();
|
||||
|
||||
@Override
|
||||
@@ -141,3 +140,4 @@ public class DifferenceIngredient extends AbstractIngredient
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -5,16 +5,18 @@
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
// TODO: Ingredient Serializers
|
||||
/*
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
|
||||
public interface IIngredientSerializer<T extends Ingredient>
|
||||
{
|
||||
public interface IIngredientSerializer<T extends Ingredient> {
|
||||
T parse(FriendlyByteBuf buffer);
|
||||
|
||||
T parse(JsonObject json);
|
||||
|
||||
void write(FriendlyByteBuf buffer, T ingredient);
|
||||
}
|
||||
*/
|
||||
@@ -15,8 +15,7 @@ import net.minecraft.world.inventory.CraftingContainer;
|
||||
* For GUIs with recipe books, this allows their containers to have
|
||||
* recipe completion and ghost recipes in their craft matrices.
|
||||
*/
|
||||
public interface IRecipeContainer
|
||||
{
|
||||
public interface IRecipeContainer {
|
||||
/**
|
||||
* The crafting result slot of your container, where you take out the crafted item.
|
||||
* The equivalent for {@link CraftingMenu} is {@code CraftingMenu#resultSlots}.
|
||||
|
||||
@@ -13,8 +13,7 @@ import net.minecraft.world.item.crafting.Recipe;
|
||||
* book and auto crafting picks the correct shape.
|
||||
* Note: These methods can't be named 'getHeight' or 'getWidth' due to obfusication issues.
|
||||
*/
|
||||
public interface IShapedRecipe<T extends Container> extends Recipe<T>
|
||||
{
|
||||
public interface IShapedRecipe<T extends Container> extends Recipe<T> {
|
||||
int getRecipeWidth();
|
||||
int getRecipeHeight();
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/** Ingredient that matches if all child ingredients match */
|
||||
/** Ingredient that matches if all child ingredients match * /
|
||||
public class IntersectionIngredient extends AbstractIngredient
|
||||
{
|
||||
private final List<Ingredient> children;
|
||||
@@ -44,7 +44,7 @@ public class IntersectionIngredient extends AbstractIngredient
|
||||
* Gets an intersection ingredient
|
||||
* @param ingredients List of ingredients to match
|
||||
* @return Ingredient that only matches if all the passed ingredients match
|
||||
*/
|
||||
* /
|
||||
public static Ingredient of(Ingredient... ingredients)
|
||||
{
|
||||
if (ingredients.length == 0)
|
||||
@@ -175,3 +175,4 @@ public class IntersectionIngredient extends AbstractIngredient
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -54,3 +54,4 @@ public class MultiItemValue implements Value
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -28,7 +28,7 @@ import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/** Ingredient that matches the given items, performing a partial NBT match. Use {@link StrictNBTIngredient} if you want exact match on NBT */
|
||||
/** Ingredient that matches the given items, performing a partial NBT match. Use {@link StrictNBTIngredient} if you want exact match on NBT * /
|
||||
public class PartialNBTIngredient extends AbstractIngredient
|
||||
{
|
||||
private final Set<Item> items;
|
||||
@@ -52,13 +52,13 @@ public class PartialNBTIngredient extends AbstractIngredient
|
||||
this.predicate = new NbtPredicate(nbt);
|
||||
}
|
||||
|
||||
/** Creates a new ingredient matching any item from the list, containing the given NBT */
|
||||
/** Creates a new ingredient matching any item from the list, containing the given NBT * /
|
||||
public static PartialNBTIngredient of(CompoundTag nbt, ItemLike... items)
|
||||
{
|
||||
return new PartialNBTIngredient(Arrays.stream(items).map(ItemLike::asItem).collect(Collectors.toSet()), nbt);
|
||||
}
|
||||
|
||||
/** Creates a new ingredient matching the given item, containing the given NBT */
|
||||
/** Creates a new ingredient matching the given item, containing the given NBT * /
|
||||
public static PartialNBTIngredient of(ItemLike item, CompoundTag nbt)
|
||||
{
|
||||
return new PartialNBTIngredient(Set.of(item.asItem()), nbt);
|
||||
@@ -154,3 +154,4 @@ public class PartialNBTIngredient extends AbstractIngredient
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
@@ -16,7 +16,7 @@ import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/** Ingredient that matches the given stack, performing an exact NBT match. Use {@link PartialNBTIngredient} if you need partial match. */
|
||||
/** Ingredient that matches the given stack, performing an exact NBT match. Use {@link PartialNBTIngredient} if you need partial match. * /
|
||||
public class StrictNBTIngredient extends AbstractIngredient
|
||||
{
|
||||
private final ItemStack stack;
|
||||
@@ -26,7 +26,7 @@ public class StrictNBTIngredient extends AbstractIngredient
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
/** Creates a new ingredient matching the given stack and tag */
|
||||
/** Creates a new ingredient matching the given stack and tag * /
|
||||
public static StrictNBTIngredient of(ItemStack stack)
|
||||
{
|
||||
return new StrictNBTIngredient(stack);
|
||||
@@ -85,3 +85,4 @@ public class StrictNBTIngredient extends AbstractIngredient
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
/*
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -36,3 +36,4 @@ public class VanillaIngredientSerializer implements IIngredientSerializer<Ingred
|
||||
buffer.writeItem(stack);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -3,11 +3,10 @@
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
// Auto generated package-info by MCP
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraftforge.common.crafting;
|
||||
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -20,6 +20,7 @@ import net.minecraft.client.resources.ClientPackSource;
|
||||
import net.minecraft.client.resources.IndexedAssetSource;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.server.packs.FilePackResources;
|
||||
import net.minecraft.server.packs.FilePackResources.FileResourcesSupplier;
|
||||
import net.minecraft.server.packs.PathPackResources;
|
||||
import net.minecraft.server.packs.repository.ServerPacksSource;
|
||||
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
||||
@@ -103,7 +104,7 @@ public class ExistingFileHelper {
|
||||
candidateServerResources.add(ServerPacksSource.createVanillaPackSource());
|
||||
for (Path existing : existingPacks) {
|
||||
File file = existing.toFile();
|
||||
PackResources pack = file.isDirectory() ? new PathPackResources(file.getName(), file.toPath(), false) : new FilePackResources(file.getName(), file, false);
|
||||
PackResources pack = file.isDirectory() ? new PathPackResources(file.getName(), file.toPath(), false) : new FileResourcesSupplier(file, false).openPrimary(file.getName()); // FilePackResources(file.getName(), file, false, "");
|
||||
candidateClientResources.add(pack);
|
||||
candidateServerResources.add(pack);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.advancements.AdvancementProvider;
|
||||
@@ -20,8 +20,8 @@ import java.util.function.Consumer;
|
||||
* An extension of the {@link AdvancementProvider} to provide a feature-complete
|
||||
* experience to generate modded advancements.
|
||||
*/
|
||||
public class ForgeAdvancementProvider extends AdvancementProvider
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
public class ForgeAdvancementProvider extends AdvancementProvider {
|
||||
/**
|
||||
* Constructs an advancement provider using the generators to write the
|
||||
* advancements to a file.
|
||||
@@ -31,8 +31,7 @@ public class ForgeAdvancementProvider extends AdvancementProvider
|
||||
* @param existingFileHelper a helper used to find whether a file exists
|
||||
* @param subProviders the generators used to create the advancements
|
||||
*/
|
||||
public ForgeAdvancementProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, ExistingFileHelper existingFileHelper, List<AdvancementGenerator> subProviders)
|
||||
{
|
||||
public ForgeAdvancementProvider(PackOutput output, CompletableFuture<HolderLookup.Provider> registries, ExistingFileHelper existingFileHelper, List<AdvancementGenerator> subProviders) {
|
||||
super(output, registries, subProviders.stream().map(generator -> generator.toSubProvider(existingFileHelper)).toList());
|
||||
}
|
||||
|
||||
@@ -42,8 +41,7 @@ public class ForgeAdvancementProvider extends AdvancementProvider
|
||||
*
|
||||
* @see AdvancementSubProvider
|
||||
*/
|
||||
public interface AdvancementGenerator
|
||||
{
|
||||
public interface AdvancementGenerator {
|
||||
/**
|
||||
* A method used to generate advancements for a mod. Advancements should be
|
||||
* built via {@link net.minecraftforge.common.extensions.IForgeAdvancementBuilder#save(Consumer, ResourceLocation, ExistingFileHelper)}.
|
||||
@@ -52,7 +50,7 @@ public class ForgeAdvancementProvider extends AdvancementProvider
|
||||
* @param saver a consumer used to write advancements to a file
|
||||
* @param existingFileHelper a helper used to find whether a file exists
|
||||
*/
|
||||
void generate(HolderLookup.Provider registries, Consumer<Advancement> saver, ExistingFileHelper existingFileHelper);
|
||||
void generate(HolderLookup.Provider registries, Consumer<AdvancementHolder> saver, ExistingFileHelper existingFileHelper);
|
||||
|
||||
/**
|
||||
* Creates an {@link AdvancementSubProvider} from this generator.
|
||||
@@ -60,8 +58,7 @@ public class ForgeAdvancementProvider extends AdvancementProvider
|
||||
* @param existingFileHelper a helper used to find whether a file exists
|
||||
* @return a sub provider wrapping this generator
|
||||
*/
|
||||
default AdvancementSubProvider toSubProvider(ExistingFileHelper existingFileHelper)
|
||||
{
|
||||
default AdvancementSubProvider toSubProvider(ExistingFileHelper existingFileHelper) {
|
||||
return (registries, saver) -> this.generate(registries, saver, existingFileHelper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
/*
|
||||
import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.loot.LootTableProvider;
|
||||
@@ -35,7 +35,7 @@ import net.minecraft.world.level.storage.loot.entries.LootPoolEntryContainer;
|
||||
|
||||
/**
|
||||
* Currently used only for replacing shears item to shears_dig tool action
|
||||
*/
|
||||
* /
|
||||
public final class ForgeLootTableProvider extends LootTableProvider {
|
||||
public ForgeLootTableProvider(PackOutput packOutput) {
|
||||
super(packOutput, Set.of(), VanillaLootTableProvider.create(packOutput).getTables());
|
||||
@@ -184,3 +184,4 @@ public final class ForgeLootTableProvider extends LootTableProvider {
|
||||
return items != null && items.contains(expected);
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -6,10 +6,12 @@
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.advancements.Advancement.Builder;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.recipes.FinishedRecipe;
|
||||
import net.minecraft.data.recipes.RecipeOutput;
|
||||
import net.minecraft.data.recipes.ShapedRecipeBuilder;
|
||||
import net.minecraft.data.recipes.ShapelessRecipeBuilder;
|
||||
import net.minecraft.data.recipes.packs.VanillaRecipeProvider;
|
||||
@@ -36,7 +38,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public final class ForgeRecipeProvider extends VanillaRecipeProvider {
|
||||
private final Map<Item, TagKey<Item>> replacements = new HashMap<>();
|
||||
@@ -59,7 +60,7 @@ public final class ForgeRecipeProvider extends VanillaRecipeProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildRecipes(Consumer<FinishedRecipe> consumer) {
|
||||
protected void buildRecipes(RecipeOutput consumer) {
|
||||
replace(Items.STICK, Tags.Items.RODS_WOODEN);
|
||||
replace(Items.GOLD_INGOT, Tags.Items.INGOTS_GOLD);
|
||||
replace(Items.IRON_INGOT, Tags.Items.INGOTS_IRON);
|
||||
@@ -92,10 +93,18 @@ public final class ForgeRecipeProvider extends VanillaRecipeProvider {
|
||||
exclude(Blocks.COBBLED_DEEPSLATE_SLAB);
|
||||
exclude(Blocks.COBBLED_DEEPSLATE_WALL);
|
||||
|
||||
super.buildRecipes(vanilla -> {
|
||||
FinishedRecipe modified = enhance(vanilla);
|
||||
if (modified != null)
|
||||
consumer.accept(modified);
|
||||
super.buildRecipes(new RecipeOutput() {
|
||||
@Override
|
||||
public void accept(FinishedRecipe vanilla) {
|
||||
var modified = enhance(vanilla);
|
||||
if (modified != null)
|
||||
consumer.accept(modified);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Builder advancement() {
|
||||
return consumer.advancement();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -113,7 +122,7 @@ public final class ForgeRecipeProvider extends VanillaRecipeProvider {
|
||||
List<Ingredient> ingredients = getField(ShapelessRecipeBuilder.Result.class, vanilla, 4);
|
||||
boolean modified = false;
|
||||
for (int x = 0; x < ingredients.size(); x++) {
|
||||
Ingredient ing = enhance(vanilla.getId(), ingredients.get(x));
|
||||
Ingredient ing = enhance(vanilla.id(), ingredients.get(x));
|
||||
if (ing != null) {
|
||||
ingredients.set(x, ing);
|
||||
modified = true;
|
||||
@@ -124,13 +133,13 @@ public final class ForgeRecipeProvider extends VanillaRecipeProvider {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected CompletableFuture<?> saveAdvancement(CachedOutput output, FinishedRecipe recipe, JsonObject json) {
|
||||
protected CompletableFuture<?> saveAdvancement(CachedOutput output, JsonObject advancementJson, AdvancementHolder holder, FinishedRecipe finishedRecipe) {
|
||||
// NOOP - We don't replace any of the advancement things yet...
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CompletableFuture<?> buildAdvancement(CachedOutput output, ResourceLocation name, Advancement.Builder builder) {
|
||||
protected CompletableFuture<?> buildAdvancement(CachedOutput p_253674_, AdvancementHolder p_297687_) {
|
||||
// NOOP - We don't replace any of the advancement things yet...
|
||||
return CompletableFuture.allOf();
|
||||
}
|
||||
@@ -140,7 +149,7 @@ public final class ForgeRecipeProvider extends VanillaRecipeProvider {
|
||||
Map<Character, Ingredient> ingredients = getField(ShapedRecipeBuilder.Result.class, vanilla, 5);
|
||||
boolean modified = false;
|
||||
for (Character x : ingredients.keySet()) {
|
||||
Ingredient ing = enhance(vanilla.getId(), ingredients.get(x));
|
||||
Ingredient ing = enhance(vanilla.id(), ingredients.get(x));
|
||||
if (ing != null) {
|
||||
ingredients.put(x, ing);
|
||||
modified = true;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.data;
|
||||
|
||||
/*
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -31,7 +31,7 @@ import java.util.stream.Collectors;
|
||||
* Provider for forge's GlobalLootModifier system. See {@link LootModifier}
|
||||
*
|
||||
* This provider only requires implementing {@link #start()} and calling {@link #add} from it.
|
||||
*/
|
||||
* /
|
||||
public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
{
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
@@ -48,7 +48,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
|
||||
/**
|
||||
* Sets the "replace" key in global_loot_modifiers to true.
|
||||
*/
|
||||
* /
|
||||
protected void replacing()
|
||||
{
|
||||
this.replace = true;
|
||||
@@ -56,7 +56,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
|
||||
/**
|
||||
* Call {@link #add} here, which will pass in the necessary information to write the jsons.
|
||||
*/
|
||||
* /
|
||||
protected abstract void start();
|
||||
|
||||
@Override
|
||||
@@ -91,7 +91,7 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
*
|
||||
* @param modifier The name of the modifier, which will be the file name.
|
||||
* @param instance The instance to serialize
|
||||
*/
|
||||
* /
|
||||
public <T extends IGlobalLootModifier> void add(String modifier, T instance)
|
||||
{
|
||||
JsonElement json = IGlobalLootModifier.DIRECT_CODEC.encodeStart(JsonOps.INSTANCE, instance).getOrThrow(false, s -> {});
|
||||
@@ -104,3 +104,4 @@ public abstract class GlobalLootModifierProvider implements DataProvider
|
||||
return "Global Loot Modifiers : " + modid;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -7,7 +7,6 @@ package net.minecraftforge.common.data;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
@@ -18,21 +17,14 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.BiConsumer;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper.ResourceType;
|
||||
import net.minecraftforge.registries.DataPackRegistriesHooks;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
@@ -96,6 +88,7 @@ public class JsonCodecProvider<T> implements DataProvider
|
||||
final Path path = outputFolder.resolve(id.getNamespace()).resolve(this.directory).resolve(id.getPath() + ".json");
|
||||
JsonElement encoded = this.codec.encodeStart(this.dynamicOps, value)
|
||||
.getOrThrow(false, msg -> LOGGER.error("Failed to encode {}: {}", path, msg));
|
||||
/* TODO: Conditional JSONS
|
||||
ICondition[] conditions = this.conditions.get(id);
|
||||
if (conditions != null && conditions.length > 0)
|
||||
{
|
||||
@@ -108,6 +101,7 @@ public class JsonCodecProvider<T> implements DataProvider
|
||||
LOGGER.error("Attempted to apply conditions to a type that is not a JsonObject! - Path: {}", path);
|
||||
}
|
||||
}
|
||||
*/
|
||||
futuresBuilder.add(DataProvider.saveStable(cache, encoded, path));
|
||||
}));
|
||||
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementRewards;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface IForgeAdvancementBuilder
|
||||
{
|
||||
|
||||
private Advancement.Builder self()
|
||||
{
|
||||
return (Advancement.Builder) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves this builder with the given id using the {@link ExistingFileHelper} to check if the parent is already known.
|
||||
*
|
||||
* @param saver a {@link Consumer} which saves any advancements provided
|
||||
* @param id the {@link ResourceLocation} id for the new advancement
|
||||
* @param fileHelper the {@link ExistingFileHelper} where all known advancements are registered
|
||||
* @return the built advancement
|
||||
* @throws IllegalStateException if the parent of the advancement is not known
|
||||
*/
|
||||
default Advancement save(Consumer<Advancement> saver, ResourceLocation id, ExistingFileHelper fileHelper)
|
||||
{
|
||||
boolean canBuild = self().canBuild((advancementId) ->
|
||||
{
|
||||
if (fileHelper.exists(advancementId, PackType.SERVER_DATA, ".json", "advancements"))
|
||||
{
|
||||
return new Advancement(advancementId, null, null, AdvancementRewards.EMPTY, Maps.newHashMap(), new String[0][0], false);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if (!canBuild)
|
||||
{
|
||||
throw new IllegalStateException("Tried to build Advancement without valid Parent!");
|
||||
}
|
||||
|
||||
Advancement advancement = self().build(id);
|
||||
saver.accept(advancement);
|
||||
return advancement;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.RecipeManager;
|
||||
@@ -15,44 +15,36 @@ import net.minecraft.world.scores.Scoreboard;
|
||||
/**
|
||||
* Additional methods for {@link CommandSourceStack} so that commands and arguments can access various things without directly referencing using server specific classes
|
||||
*/
|
||||
public interface IForgeCommandSourceStack
|
||||
{
|
||||
|
||||
private CommandSourceStack self()
|
||||
{
|
||||
public interface IForgeCommandSourceStack {
|
||||
private CommandSourceStack self() {
|
||||
return (CommandSourceStack) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scoreboard
|
||||
*/
|
||||
default Scoreboard getScoreboard()
|
||||
{
|
||||
default Scoreboard getScoreboard() {
|
||||
return self().getServer().getScoreboard();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the advancement from the id
|
||||
*/
|
||||
default Advancement getAdvancement(ResourceLocation id)
|
||||
{
|
||||
return self().getServer().getAdvancements().getAdvancement(id);
|
||||
default AdvancementHolder getAdvancement(ResourceLocation id) {
|
||||
return self().getServer().getAdvancements().get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the recipe manager
|
||||
*/
|
||||
default RecipeManager getRecipeManager()
|
||||
{
|
||||
default RecipeManager getRecipeManager() {
|
||||
return self().getServer().getRecipeManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the level but without being specifically the server side level
|
||||
*/
|
||||
default Level getUnsidedLevel()
|
||||
{
|
||||
default Level getUnsidedLevel() {
|
||||
return self().getLevel();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Forge Development LLC and contributors
|
||||
* SPDX-License-Identifier: LGPL-2.1-only
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraftforge.common.crafting.conditions.ICondition;
|
||||
|
||||
public interface IForgeRecipeSerializer<T extends Recipe<?>>
|
||||
{
|
||||
private RecipeSerializer<T> self()
|
||||
{
|
||||
return (RecipeSerializer<T>) this;
|
||||
}
|
||||
|
||||
default T fromJson(ResourceLocation recipeLoc, JsonObject recipeJson, ICondition.IContext context)
|
||||
{
|
||||
return self().fromJson(recipeLoc, recipeJson);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.loot;
|
||||
|
||||
/*
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -22,7 +22,7 @@ import java.util.Set;
|
||||
|
||||
/**
|
||||
* This LootItemCondition "forge:can_tool_perform_action" can be used to check if a tool can perform a given ToolAction.
|
||||
*/
|
||||
* /
|
||||
public class CanToolPerformAction implements LootItemCondition {
|
||||
|
||||
public static final LootItemConditionType LOOT_CONDITION_TYPE = new LootItemConditionType(new CanToolPerformAction.Serializer());
|
||||
@@ -64,3 +64,4 @@ public class CanToolPerformAction implements LootItemCondition {
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.loot;
|
||||
|
||||
/*
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.mojang.serialization.Codec;
|
||||
@@ -26,7 +26,7 @@ import java.util.function.Function;
|
||||
* {@link LootModifier} Supplies base functionality; most modders should only need to extend that.<br/>
|
||||
* Requires a {@link Codec} to be registered: {@link ForgeRegistries#GLOBAL_LOOT_MODIFIER_SERIALIZERS}, and returned in {@link #codec()}
|
||||
* Individual instances of modifiers must be registered via json, see forge:loot_modifiers/global_loot_modifiers
|
||||
*/
|
||||
* /
|
||||
public interface IGlobalLootModifier {
|
||||
Codec<IGlobalLootModifier> DIRECT_CODEC = ExtraCodecs.lazyInitializedCodec(() -> ForgeRegistries.GLOBAL_LOOT_MODIFIER_SERIALIZERS.get().getCodec())
|
||||
.dispatch(IGlobalLootModifier::codec, Function.identity());
|
||||
@@ -74,12 +74,13 @@ public interface IGlobalLootModifier {
|
||||
* @param generatedLoot the list of ItemStacks that will be dropped, generated by loot tables
|
||||
* @param context the LootContext, identical to what is passed to loot tables
|
||||
* @return modified loot drops
|
||||
*/
|
||||
* /
|
||||
@NotNull
|
||||
ObjectArrayList<ItemStack> apply(ObjectArrayList<ItemStack> generatedLoot, LootContext context);
|
||||
|
||||
/**
|
||||
* Returns the registered codec for this modifier
|
||||
*/
|
||||
* /
|
||||
Codec<? extends IGlobalLootModifier> codec();
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.loot;
|
||||
|
||||
/*
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import com.mojang.datafixers.Products;
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
/**
|
||||
* A base implementation of a Global Loot Modifier for modders to extend.
|
||||
* Takes care of ILootCondition matching and comes with the base codec to extend.
|
||||
*/
|
||||
* /
|
||||
public abstract class LootModifier implements IGlobalLootModifier
|
||||
{
|
||||
protected final LootItemCondition[] conditions;
|
||||
@@ -35,7 +35,7 @@ public abstract class LootModifier implements IGlobalLootModifier
|
||||
* </p>
|
||||
* Otherwise can follow this with #and() to add more fields.
|
||||
* Examples: Forge Test Subclasses or {@link BendingTrunkPlacer#CODEC}
|
||||
*/
|
||||
* /
|
||||
protected static <T extends LootModifier> Products.P1<RecordCodecBuilder.Mu<T>, LootItemCondition[]> codecStart(RecordCodecBuilder.Instance<T> instance)
|
||||
{
|
||||
return instance.group(LOOT_CONDITIONS_CODEC.fieldOf("conditions").forGetter(lm -> lm.conditions));
|
||||
@@ -44,7 +44,7 @@ public abstract class LootModifier implements IGlobalLootModifier
|
||||
/**
|
||||
* Constructs a LootModifier.
|
||||
* @param conditionsIn the ILootConditions that need to be matched before the loot is modified.
|
||||
*/
|
||||
* /
|
||||
protected LootModifier(LootItemCondition[] conditionsIn)
|
||||
{
|
||||
this.conditions = conditionsIn;
|
||||
@@ -64,7 +64,8 @@ public abstract class LootModifier implements IGlobalLootModifier
|
||||
* @param generatedLoot the list of ItemStacks that will be dropped, generated by loot tables
|
||||
* @param context the LootContext, identical to what is passed to loot tables
|
||||
* @return modified loot drops
|
||||
*/
|
||||
* /
|
||||
@NotNull
|
||||
protected abstract ObjectArrayList<ItemStack> doApply(ObjectArrayList<ItemStack> generatedLoot, LootContext context);
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.loot;
|
||||
|
||||
/*
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -16,7 +16,6 @@ import java.util.*;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import net.minecraft.world.level.storage.loot.Deserializers;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@@ -87,9 +86,10 @@ public class LootModifierManager extends SimpleJsonResourceReloadListener {
|
||||
|
||||
/**
|
||||
* An immutable collection of the registered loot modifiers in layered order.
|
||||
*/
|
||||
* /
|
||||
public Collection<IGlobalLootModifier> getAllLootMods() {
|
||||
return registeredLootModifiers.values();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.loot;
|
||||
|
||||
/*
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
@@ -77,3 +77,4 @@ public class LootTableIdCondition implements LootItemCondition
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.common.ServerboundClientInformationPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundAcceptTeleportationPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundBlockEntityTagQuery;
|
||||
@@ -24,17 +25,14 @@ import net.minecraft.network.protocol.game.ServerboundChatCommandPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatSessionUpdatePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundClientCommandPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundClientInformationPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundCommandSuggestionPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundContainerButtonClickPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundContainerClickPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundContainerClosePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundEditBookPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundEntityTagQuery;
|
||||
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundJigsawGeneratePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundKeepAlivePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundLockDifficultyPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
|
||||
@@ -48,7 +46,6 @@ import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundRecipeBookChangeSettingsPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundRecipeBookSeenRecipePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundRenameItemPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundResourcePackPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSeenAdvancementsPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSelectTradePacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundSetBeaconPacket;
|
||||
@@ -64,8 +61,10 @@ import net.minecraft.network.protocol.game.ServerboundTeleportToEntityPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundUseItemPacket;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ClientInformation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
@@ -77,12 +76,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* A basic fake server player implementation that can be used to simulate player actions.
|
||||
*/
|
||||
public class FakePlayer extends ServerPlayer
|
||||
{
|
||||
public FakePlayer(ServerLevel level, GameProfile name)
|
||||
{
|
||||
super(level.getServer(), level, name);
|
||||
this.connection = new FakePlayerNetHandler(level.getServer(), this);
|
||||
@Deprecated // TODO: Re-write this whole system to be less hacky. Use until we get a good replacement.
|
||||
public class FakePlayer extends ServerPlayer {
|
||||
protected FakePlayer(ServerLevel level, GameProfile name, ClientInformation info) {
|
||||
super(level.getServer(), level, name, info);
|
||||
}
|
||||
|
||||
@Override public void displayClientMessage(Component chatComponent, boolean actionBar) { }
|
||||
@@ -91,15 +88,14 @@ public class FakePlayer extends ServerPlayer
|
||||
@Override public boolean canHarmPlayer(Player player) { return false; }
|
||||
@Override public void die(DamageSource source) { }
|
||||
@Override public void tick() { }
|
||||
@Override public void updateOptions(ServerboundClientInformationPacket packet) { }
|
||||
@Override @Nullable public MinecraftServer getServer() { return ServerLifecycleHooks.getCurrentServer(); }
|
||||
|
||||
@ParametersAreNonnullByDefault
|
||||
private static class FakePlayerNetHandler extends ServerGamePacketListenerImpl {
|
||||
static class NetHandler extends ServerGamePacketListenerImpl {
|
||||
private static final Connection DUMMY_CONNECTION = new Connection(PacketFlow.CLIENTBOUND);
|
||||
|
||||
public FakePlayerNetHandler(MinecraftServer server, ServerPlayer player) {
|
||||
super(server, DUMMY_CONNECTION, player);
|
||||
NetHandler(MinecraftServer server, ServerPlayer player, CommonListenerCookie cookie) {
|
||||
super(server, DUMMY_CONNECTION, player, cookie);
|
||||
}
|
||||
|
||||
@Override public void tick() { }
|
||||
@@ -130,7 +126,6 @@ public class FakePlayer extends ServerPlayer
|
||||
@Override public void handleUseItemOn(ServerboundUseItemOnPacket packet) { }
|
||||
@Override public void handleUseItem(ServerboundUseItemPacket packet) { }
|
||||
@Override public void handleTeleportToEntityPacket(ServerboundTeleportToEntityPacket packet) { }
|
||||
@Override public void handleResourcePackResponse(ServerboundResourcePackPacket packet) { }
|
||||
@Override public void handlePaddleBoat(ServerboundPaddleBoatPacket packet) { }
|
||||
@Override public void onDisconnect(Component message) { }
|
||||
@Override public void send(Packet<?> packet) { }
|
||||
@@ -147,10 +142,7 @@ public class FakePlayer extends ServerPlayer
|
||||
@Override public void handleContainerButtonClick(ServerboundContainerButtonClickPacket packet) { }
|
||||
@Override public void handleSetCreativeModeSlot(ServerboundSetCreativeModeSlotPacket packet) { }
|
||||
@Override public void handleSignUpdate(ServerboundSignUpdatePacket packet) { }
|
||||
@Override public void handleKeepAlive(ServerboundKeepAlivePacket packet) { }
|
||||
@Override public void handlePlayerAbilities(ServerboundPlayerAbilitiesPacket packet) { }
|
||||
@Override public void handleClientInformation(ServerboundClientInformationPacket packet) { }
|
||||
@Override public void handleCustomPayload(ServerboundCustomPayloadPacket packet) { }
|
||||
@Override public void handleChangeDifficulty(ServerboundChangeDifficultyPacket packet) { }
|
||||
@Override public void handleLockDifficulty(ServerboundLockDifficultyPacket packet) { }
|
||||
@Override public void teleport(double x, double y, double z, float yaw, float pitch, Set<RelativeMovement> relativeSet) { }
|
||||
|
||||
@@ -12,8 +12,10 @@ import com.google.common.collect.Maps;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
|
||||
//To be expanded for generic Mod fake players?
|
||||
|
||||
@Deprecated // TODO: Re-write this whole system to be less hacky. Use until we get a good replacement.
|
||||
public class FakePlayerFactory
|
||||
{
|
||||
private static final GameProfile MINECRAFT = new GameProfile(UUID.fromString("41C82C87-7AfB-4024-BA57-13D2C99CAE77"), "[Minecraft]");
|
||||
@@ -35,11 +37,18 @@ public class FakePlayerFactory
|
||||
public static FakePlayer get(ServerLevel level, GameProfile username)
|
||||
{
|
||||
FakePlayerKey key = new FakePlayerKey(level, username);
|
||||
return fakePlayers.computeIfAbsent(key, k -> new FakePlayer(k.level(), k.username()));
|
||||
return fakePlayers.computeIfAbsent(key, FakePlayerFactory::create);
|
||||
}
|
||||
|
||||
public static void unloadLevel(ServerLevel level)
|
||||
{
|
||||
fakePlayers.entrySet().removeIf(entry -> entry.getValue().level() == level);
|
||||
}
|
||||
|
||||
private static FakePlayer create(FakePlayerKey key) {
|
||||
var cookie = CommonListenerCookie.createInitial(key.username());
|
||||
var ret = new FakePlayer(key.level(), cookie.gameProfile(), cookie.clientInformation());
|
||||
new FakePlayer.NetHandler(key.level().getServer(), ret, cookie);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -6,58 +6,63 @@
|
||||
package net.minecraftforge.common.util;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.datafix.DataFixTypes;
|
||||
import net.minecraft.world.level.saveddata.SavedData;
|
||||
import net.minecraft.world.level.storage.DimensionDataStorage;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class LevelCapabilityData extends SavedData
|
||||
{
|
||||
public class LevelCapabilityData extends SavedData {
|
||||
public static final String ID = "capabilities";
|
||||
|
||||
private INBTSerializable<CompoundTag> serializable;
|
||||
private CompoundTag capNBT = null;
|
||||
|
||||
public LevelCapabilityData(@Nullable INBTSerializable<CompoundTag> serializable)
|
||||
{
|
||||
public LevelCapabilityData(@Nullable INBTSerializable<CompoundTag> serializable) {
|
||||
this.serializable = serializable;
|
||||
}
|
||||
|
||||
public static LevelCapabilityData load(CompoundTag tag, @Nullable INBTSerializable<CompoundTag> serializable) {
|
||||
LevelCapabilityData data = new LevelCapabilityData(serializable);
|
||||
data.read(tag);
|
||||
return data;
|
||||
}
|
||||
|
||||
public void read(CompoundTag nbt)
|
||||
{
|
||||
public void read(CompoundTag nbt) {
|
||||
this.capNBT = nbt;
|
||||
if (serializable != null)
|
||||
{
|
||||
if (serializable != null) {
|
||||
serializable.deserializeNBT(this.capNBT);
|
||||
this.capNBT = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag save(CompoundTag nbt)
|
||||
{
|
||||
public CompoundTag save(CompoundTag nbt) {
|
||||
if (serializable != null)
|
||||
nbt = serializable.serializeNBT();
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty()
|
||||
{
|
||||
public boolean isDirty() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setCapabilities(INBTSerializable<CompoundTag> capabilities)
|
||||
{
|
||||
public void setCapabilities(INBTSerializable<CompoundTag> capabilities) {
|
||||
this.serializable = capabilities;
|
||||
if (this.capNBT != null && serializable != null)
|
||||
{
|
||||
if (this.capNBT != null && serializable != null) {
|
||||
serializable.deserializeNBT(this.capNBT);
|
||||
this.capNBT = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static LevelCapabilityData compute(DimensionDataStorage data, @Nullable INBTSerializable<CompoundTag> caps) {
|
||||
var factory = new Factory<>(
|
||||
() -> new LevelCapabilityData(caps),
|
||||
(tag) -> {
|
||||
var ret = new LevelCapabilityData(caps);
|
||||
ret.read(tag);
|
||||
return ret;
|
||||
},
|
||||
DataFixTypes.SAVED_DATA_COMMAND_STORAGE //TODO: Hook this for our own types?
|
||||
);
|
||||
|
||||
var ret = data.computeIfAbsent(factory, ID);
|
||||
ret.setCapabilities(caps);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class ForgeChunkManager
|
||||
*/
|
||||
public static boolean hasForcedChunks(ServerLevel level)
|
||||
{
|
||||
ForcedChunksSavedData data = level.getDataStorage().get(ForcedChunksSavedData::load, "chunks");
|
||||
ForcedChunksSavedData data = level.getDataStorage().get(ForcedChunksSavedData.factory(), "chunks");
|
||||
if (data == null) return false;
|
||||
return !data.getChunks().isEmpty() || !data.getBlockForcedChunks().isEmpty() || !data.getEntityForcedChunks().isEmpty();
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class ForgeChunkManager
|
||||
LOGGER.warn("A mod attempted to force a chunk for an unloaded mod of id: {}", modId);
|
||||
return false;
|
||||
}
|
||||
ForcedChunksSavedData saveData = level.getDataStorage().computeIfAbsent(ForcedChunksSavedData::load, ForcedChunksSavedData::new, "chunks");
|
||||
ForcedChunksSavedData saveData = level.getDataStorage().computeIfAbsent(ForcedChunksSavedData.factory(), "chunks");
|
||||
ChunkPos pos = new ChunkPos(chunkX, chunkZ);
|
||||
long chunk = pos.toLong();
|
||||
TicketTracker<T> tickets = ticketGetter.apply(saveData);
|
||||
|
||||
@@ -16,13 +16,11 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* Fired on {@link PackRepository} creation to allow mods to add new pack finders.
|
||||
*/
|
||||
public class AddPackFindersEvent extends Event implements IModBusEvent
|
||||
{
|
||||
public class AddPackFindersEvent extends Event implements IModBusEvent {
|
||||
private final PackType packType;
|
||||
private final Consumer<RepositorySource> sources;
|
||||
|
||||
public AddPackFindersEvent(PackType packType, Consumer<RepositorySource> sources)
|
||||
{
|
||||
public AddPackFindersEvent(PackType packType, Consumer<RepositorySource> sources) {
|
||||
this.packType = packType;
|
||||
this.sources = sources;
|
||||
}
|
||||
@@ -31,16 +29,14 @@ public class AddPackFindersEvent extends Event implements IModBusEvent
|
||||
* Adds a new source to the list of pack finders.
|
||||
* @param source the pack finder
|
||||
*/
|
||||
public void addRepositorySource(RepositorySource source)
|
||||
{
|
||||
public void addRepositorySource(RepositorySource source) {
|
||||
sources.accept(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link PackType} of the pack repository being constructed.
|
||||
*/
|
||||
public PackType getPackType()
|
||||
{
|
||||
public PackType getPackType() {
|
||||
return packType;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -26,16 +26,14 @@ import org.jetbrains.annotations.ApiStatus;
|
||||
* only on the {@linkplain LogicalSide#SERVER logical server}.
|
||||
**/
|
||||
@Cancelable
|
||||
public class ServerChatEvent extends Event
|
||||
{
|
||||
public class ServerChatEvent extends Event {
|
||||
private final ServerPlayer player;
|
||||
private final String username;
|
||||
private final String rawText;
|
||||
private Component message;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public ServerChatEvent(ServerPlayer player, String rawText, Component message)
|
||||
{
|
||||
public ServerChatEvent(ServerPlayer player, String rawText, Component message) {
|
||||
this.player = player;
|
||||
this.username = player.getGameProfile().getName();
|
||||
this.rawText = rawText;
|
||||
@@ -45,40 +43,35 @@ public class ServerChatEvent extends Event
|
||||
/**
|
||||
* {@return the player who initiated the chat action}
|
||||
*/
|
||||
public ServerPlayer getPlayer()
|
||||
{
|
||||
public ServerPlayer getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the username of the player who initiated the chat action}
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the original raw text of the player chat message}
|
||||
*/
|
||||
public String getRawText()
|
||||
{
|
||||
public String getRawText() {
|
||||
return this.rawText;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message to be sent to the relevant clients.
|
||||
*/
|
||||
public void setMessage(Component message)
|
||||
{
|
||||
public void setMessage(Component message) {
|
||||
this.message = Objects.requireNonNull(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the message that will be sent to the relevant clients, if the event is not cancelled}
|
||||
*/
|
||||
public Component getMessage()
|
||||
{
|
||||
public Component getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,7 @@ package net.minecraftforge.event.entity;
|
||||
|
||||
import net.minecraft.core.SectionPos;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.Pose;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.extensions.IForgeEntity;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
/**
|
||||
@@ -23,17 +19,14 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public class EntityEvent extends Event
|
||||
{
|
||||
public class EntityEvent extends Event {
|
||||
private final Entity entity;
|
||||
|
||||
public EntityEvent(Entity entity)
|
||||
{
|
||||
public EntityEvent(Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public Entity getEntity()
|
||||
{
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -47,10 +40,8 @@ public class EntityEvent extends Event
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class EntityConstructing extends EntityEvent
|
||||
{
|
||||
public EntityConstructing(Entity entity)
|
||||
{
|
||||
public static class EntityConstructing extends EntityEvent {
|
||||
public EntityConstructing(Entity entity) {
|
||||
super(entity);
|
||||
}
|
||||
}
|
||||
@@ -67,14 +58,11 @@ public class EntityEvent extends Event
|
||||
* <br>
|
||||
* This event is fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class EnteringSection extends EntityEvent
|
||||
{
|
||||
|
||||
public static class EnteringSection extends EntityEvent {
|
||||
private final long packedOldPos;
|
||||
private final long packedNewPos;
|
||||
|
||||
public EnteringSection(Entity entity, long packedOldPos, long packedNewPos)
|
||||
{
|
||||
public EnteringSection(Entity entity, long packedOldPos, long packedNewPos) {
|
||||
super(entity);
|
||||
this.packedOldPos = packedOldPos;
|
||||
this.packedNewPos = packedNewPos;
|
||||
@@ -85,8 +73,7 @@ public class EntityEvent extends Event
|
||||
* such as {@link SectionPos#of(long)} or {@link SectionPos#x(long)} to avoid allocation.
|
||||
* @return the packed position of the old section
|
||||
*/
|
||||
public long getPackedOldPos()
|
||||
{
|
||||
public long getPackedOldPos() {
|
||||
return packedOldPos;
|
||||
}
|
||||
|
||||
@@ -95,24 +82,21 @@ public class EntityEvent extends Event
|
||||
* such as {@link SectionPos#of(long)} or {@link SectionPos#x(long)} to avoid allocation.
|
||||
* @return the packed position of the new section
|
||||
*/
|
||||
public long getPackedNewPos()
|
||||
{
|
||||
public long getPackedNewPos() {
|
||||
return packedNewPos;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the position of the old section
|
||||
*/
|
||||
public SectionPos getOldPos()
|
||||
{
|
||||
public SectionPos getOldPos() {
|
||||
return SectionPos.of(packedOldPos);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the position of the new section
|
||||
*/
|
||||
public SectionPos getNewPos()
|
||||
{
|
||||
public SectionPos getNewPos() {
|
||||
return SectionPos.of(packedNewPos);
|
||||
}
|
||||
|
||||
@@ -120,87 +104,8 @@ public class EntityEvent extends Event
|
||||
* Whether the chunk has changed as part of this event. If this method returns false, only the Y position of the
|
||||
* section has changed.
|
||||
*/
|
||||
public boolean didChunkChange()
|
||||
{
|
||||
public boolean didChunkChange() {
|
||||
return SectionPos.x(packedOldPos) != SectionPos.x(packedNewPos) || SectionPos.z(packedOldPos) != SectionPos.z(packedNewPos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* CAREFUL: This is also fired in the Entity constructor. Therefore, the entity (subclass) might not be fully initialized. Check {@link Entity#isAddedToWorld()} or {@code !Entity.firstUpdate}.<br>
|
||||
* If you change the player's size, you probably want to set the eye height accordingly as well<br>
|
||||
* <br>
|
||||
* This event is not {@link Cancelable}.<br>
|
||||
* <br>
|
||||
* This event does not have a result. {@link HasResult}
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1") // Remove Entity Eye/Size hooks, as they need to be redesigned
|
||||
public static class Size extends EntityEvent {
|
||||
private final Pose pose;
|
||||
private final EntityDimensions originalSize;
|
||||
private EntityDimensions newSize;
|
||||
private final float oldEyeHeight;
|
||||
private float newEyeHeight;
|
||||
|
||||
public Size(Entity entity, Pose pose, EntityDimensions size) {
|
||||
this(entity, pose, size, 1.0f); // Eye height doesn't matter this is just for binary compatibility.
|
||||
}
|
||||
|
||||
public Size(Entity entity, Pose pose, EntityDimensions size, float defaultEyeHeight) {
|
||||
this(entity, pose, size, size, defaultEyeHeight, defaultEyeHeight);
|
||||
}
|
||||
|
||||
public Size(Entity entity, Pose pose, EntityDimensions oldSize, EntityDimensions newSize, float oldEyeHeight, float newEyeHeight) {
|
||||
super(entity);
|
||||
this.pose = pose;
|
||||
this.originalSize = oldSize;
|
||||
this.newSize = newSize;
|
||||
this.oldEyeHeight = oldEyeHeight;
|
||||
this.newEyeHeight = newEyeHeight;
|
||||
}
|
||||
|
||||
public Pose getPose() { return pose; }
|
||||
public EntityDimensions getOldSize() { return this.getOriginalSize(); }
|
||||
public EntityDimensions getOriginalSize() { return originalSize; }
|
||||
public EntityDimensions getNewSize() { return newSize; }
|
||||
public void setNewSize(EntityDimensions size) { this.newSize = size; }
|
||||
|
||||
public void setNewSize(EntityDimensions size, boolean updateEyeHeight) {
|
||||
this.setNewSize(size);
|
||||
if (updateEyeHeight) {
|
||||
this.newEyeHeight = this.getEntity().getEyeHeightAccess(this.getPose(), this.newSize);
|
||||
}
|
||||
}
|
||||
public float getOldEyeHeight() { return oldEyeHeight; }
|
||||
public float getNewEyeHeight() { return newEyeHeight; }
|
||||
public void setNewEyeHeight(float eyeHeight) { this.newEyeHeight = eyeHeight; }
|
||||
}
|
||||
|
||||
/**
|
||||
*Remove Entity Eye/Size hooks, as they need to be redesigned, this is no longer fired in any forge/vanilla code.
|
||||
**/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1")
|
||||
public static class EyeHeight extends EntityEvent {
|
||||
private final Pose pose;
|
||||
private final EntityDimensions size;
|
||||
private final float originalEyeHeight;
|
||||
private float newEyeHeight;
|
||||
|
||||
public EyeHeight(Entity entity, Pose pose, EntityDimensions size, float eyeHeight) {
|
||||
super(entity);
|
||||
this.pose = pose;
|
||||
this.size = size;
|
||||
this.originalEyeHeight = eyeHeight;
|
||||
this.newEyeHeight = eyeHeight;
|
||||
}
|
||||
|
||||
public Pose getPose() { return pose; }
|
||||
public EntityDimensions getSize() { return size; }
|
||||
public float getOriginalEyeHeight() { return originalEyeHeight; }
|
||||
public float getNewEyeHeight() { return newEyeHeight; }
|
||||
public void setNewEyeHeight(float newEyeHeight) { this.newEyeHeight = newEyeHeight; }
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.world.entity.projectile.Projectile;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
@@ -20,58 +19,38 @@ import java.util.Objects;
|
||||
* This event is fired via {@link ForgeEventFactory#onProjectileImpact(Projectile, HitResult)}
|
||||
* This event is fired for all vanilla projectiles by Forge,
|
||||
* custom projectiles should fire this event and check the result in a similar fashion.
|
||||
* This event is cancelable. When canceled, the impact will not be processed and the projectile will continue flying.
|
||||
* Killing or other handling of the entity after event cancellation is up to the modder.
|
||||
* You can also directly set the {@link ImpactResult} to change the impact behaviour.
|
||||
* @see #setImpactResult(ImpactResult)
|
||||
*/
|
||||
@Cancelable
|
||||
public class ProjectileImpactEvent extends EntityEvent
|
||||
{
|
||||
public class ProjectileImpactEvent extends EntityEvent {
|
||||
private final HitResult ray;
|
||||
private final Projectile projectile;
|
||||
|
||||
private ImpactResult result = ImpactResult.DEFAULT;
|
||||
|
||||
public ProjectileImpactEvent(Projectile projectile, HitResult ray)
|
||||
{
|
||||
public ProjectileImpactEvent(Projectile projectile, HitResult ray) {
|
||||
super(projectile);
|
||||
this.ray = ray;
|
||||
this.projectile = projectile;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @deprecated Use {@link #setImpactResult(ImpactResult)} instead.
|
||||
*/
|
||||
@Deprecated(forRemoval = true, since = "1.20.1")
|
||||
public void setCanceled(boolean cancel)
|
||||
{
|
||||
super.setCanceled(cancel);
|
||||
}
|
||||
|
||||
public HitResult getRayTraceResult()
|
||||
{
|
||||
public HitResult getRayTraceResult() {
|
||||
return ray;
|
||||
}
|
||||
|
||||
public Projectile getProjectile()
|
||||
{
|
||||
public Projectile getProjectile() {
|
||||
return projectile;
|
||||
}
|
||||
|
||||
public void setImpactResult(@NotNull ImpactResult newResult)
|
||||
{
|
||||
public void setImpactResult(@NotNull ImpactResult newResult) {
|
||||
this.result = Objects.requireNonNull(newResult, "ImpactResult cannot be null");
|
||||
}
|
||||
|
||||
public ImpactResult getImpactResult()
|
||||
{
|
||||
public ImpactResult getImpactResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public enum ImpactResult
|
||||
{
|
||||
public enum ImpactResult {
|
||||
/**
|
||||
* The default behaviour, the projectile will be destroyed and the hit will be processed.
|
||||
*/
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package net.minecraftforge.event.entity.player;
|
||||
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementHolder;
|
||||
import net.minecraft.advancements.AdvancementProgress;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -15,18 +16,15 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
* @see AdvancementEarnEvent
|
||||
* @see AdvancementProgressEvent
|
||||
*/
|
||||
public class AdvancementEvent extends PlayerEvent
|
||||
{
|
||||
private final Advancement advancement;
|
||||
public class AdvancementEvent extends PlayerEvent {
|
||||
private final AdvancementHolder advancement;
|
||||
|
||||
public AdvancementEvent(Player player, Advancement advancement)
|
||||
{
|
||||
public AdvancementEvent(Player player, AdvancementHolder advancement) {
|
||||
super(player);
|
||||
this.advancement = advancement;
|
||||
}
|
||||
|
||||
public Advancement getAdvancement()
|
||||
{
|
||||
public AdvancementHolder getAdvancement() {
|
||||
return advancement;
|
||||
}
|
||||
|
||||
@@ -43,23 +41,10 @@ public class AdvancementEvent extends PlayerEvent
|
||||
*
|
||||
* @see AdvancementProgress#isDone()
|
||||
*/
|
||||
public static class AdvancementEarnEvent extends AdvancementEvent
|
||||
{
|
||||
|
||||
public AdvancementEarnEvent(Player player, Advancement earned)
|
||||
{
|
||||
public static class AdvancementEarnEvent extends AdvancementEvent {
|
||||
public AdvancementEarnEvent(Player player, AdvancementHolder earned) {
|
||||
super(player, earned);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@return the advancement that was earned}
|
||||
*/
|
||||
@Override
|
||||
public Advancement getAdvancement()
|
||||
{
|
||||
return super.getAdvancement();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,56 +59,40 @@ public class AdvancementEvent extends PlayerEvent
|
||||
* @see net.minecraft.server.PlayerAdvancements#award(Advancement, String)
|
||||
* @see net.minecraft.server.PlayerAdvancements#revoke(Advancement, String)
|
||||
*/
|
||||
public static class AdvancementProgressEvent extends AdvancementEvent
|
||||
{
|
||||
public static class AdvancementProgressEvent extends AdvancementEvent {
|
||||
private final AdvancementProgress advancementProgress;
|
||||
private final String criterionName;
|
||||
private final AdvancementEvent.AdvancementProgressEvent.ProgressType progressType;
|
||||
|
||||
public AdvancementProgressEvent(Player player, Advancement progressed, AdvancementProgress advancementProgress, String criterionName, AdvancementEvent.AdvancementProgressEvent.ProgressType progressType)
|
||||
{
|
||||
public AdvancementProgressEvent(Player player, AdvancementHolder progressed, AdvancementProgress advancementProgress, String criterionName, AdvancementEvent.AdvancementProgressEvent.ProgressType progressType) {
|
||||
super(player, progressed);
|
||||
this.advancementProgress = advancementProgress;
|
||||
this.criterionName = criterionName;
|
||||
this.progressType = progressType;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* {@return The advancement that was progressed}
|
||||
*/
|
||||
@Override
|
||||
public Advancement getAdvancement()
|
||||
{
|
||||
return super.getAdvancement();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return the progress of the advancement}
|
||||
*/
|
||||
public AdvancementProgress getAdvancementProgress()
|
||||
{
|
||||
public AdvancementProgress getAdvancementProgress() {
|
||||
return advancementProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return name of the criterion that was progressed}
|
||||
*/
|
||||
public String getCriterionName()
|
||||
{
|
||||
public String getCriterionName() {
|
||||
return criterionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@return The type of progress for the criterion in this event}
|
||||
*/
|
||||
public ProgressType getProgressType()
|
||||
{
|
||||
public ProgressType getProgressType() {
|
||||
return progressType;
|
||||
}
|
||||
|
||||
public enum ProgressType
|
||||
{
|
||||
public enum ProgressType {
|
||||
GRANT, REVOKE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,24 +26,20 @@ import net.minecraftforge.eventbus.api.Event;
|
||||
* <br>
|
||||
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public class ChunkDataEvent extends ChunkEvent
|
||||
{
|
||||
public class ChunkDataEvent extends ChunkEvent {
|
||||
private final CompoundTag data;
|
||||
|
||||
public ChunkDataEvent(ChunkAccess chunk, CompoundTag data)
|
||||
{
|
||||
public ChunkDataEvent(ChunkAccess chunk, CompoundTag data) {
|
||||
super(chunk);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public ChunkDataEvent(ChunkAccess chunk, LevelAccessor world, CompoundTag data)
|
||||
{
|
||||
public ChunkDataEvent(ChunkAccess chunk, LevelAccessor world, CompoundTag data) {
|
||||
super(chunk, world);
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public CompoundTag getData()
|
||||
{
|
||||
public CompoundTag getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -58,18 +54,15 @@ public class ChunkDataEvent extends ChunkEvent
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class Load extends ChunkDataEvent
|
||||
{
|
||||
public static class Load extends ChunkDataEvent {
|
||||
private ChunkStatus.ChunkType status;
|
||||
|
||||
public Load(ChunkAccess chunk, CompoundTag data, ChunkStatus.ChunkType status)
|
||||
{
|
||||
public Load(ChunkAccess chunk, CompoundTag data, ChunkStatus.ChunkType status) {
|
||||
super(chunk, data);
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public ChunkStatus.ChunkType getStatus()
|
||||
{
|
||||
public ChunkStatus.ChunkType getStatus() {
|
||||
return this.status;
|
||||
}
|
||||
}
|
||||
@@ -85,10 +78,8 @@ public class ChunkDataEvent extends ChunkEvent
|
||||
* <br>
|
||||
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
|
||||
**/
|
||||
public static class Save extends ChunkDataEvent
|
||||
{
|
||||
public Save(ChunkAccess chunk, LevelAccessor world, CompoundTag data)
|
||||
{
|
||||
public static class Save extends ChunkDataEvent {
|
||||
public Save(ChunkAccess chunk, LevelAccessor world, CompoundTag data) {
|
||||
super(chunk, world, data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -573,7 +573,7 @@ public class FluidUtil
|
||||
BlockState destBlockState = level.getBlockState(pos);
|
||||
boolean isDestNonSolid = !destBlockState.isSolid();
|
||||
boolean isDestReplaceable = destBlockState.canBeReplaced(context);
|
||||
boolean canDestContainFluid = destBlockState.getBlock() instanceof LiquidBlockContainer && ((LiquidBlockContainer) destBlockState.getBlock()).canPlaceLiquid(level, pos, destBlockState, fluid);
|
||||
boolean canDestContainFluid = destBlockState.getBlock() instanceof LiquidBlockContainer && ((LiquidBlockContainer) destBlockState.getBlock()).canPlaceLiquid(player, level, pos, destBlockState, fluid);
|
||||
if (!level.isEmptyBlock(pos) && !isDestNonSolid && !isDestReplaceable && !canDestContainFluid)
|
||||
{
|
||||
return false; // Non-air, solid, unreplacable block. We can't put fluid here.
|
||||
|
||||
@@ -20,61 +20,50 @@ import net.minecraftforge.fluids.capability.templates.VoidFluidHandler;
|
||||
* If the block in question inherits from the Forge implementations,
|
||||
* consider using {@link FluidBlockWrapper}.
|
||||
*/
|
||||
public class BlockWrapper extends VoidFluidHandler
|
||||
{
|
||||
public class BlockWrapper extends VoidFluidHandler {
|
||||
protected final BlockState state;
|
||||
protected final Level world;
|
||||
protected final BlockPos blockPos;
|
||||
|
||||
public BlockWrapper(BlockState state, Level world, BlockPos blockPos)
|
||||
{
|
||||
public BlockWrapper(BlockState state, Level world, BlockPos blockPos) {
|
||||
this.state = state;
|
||||
this.world = world;
|
||||
this.blockPos = blockPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action)
|
||||
{
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
// NOTE: "Filling" means placement in this context!
|
||||
if (resource.getAmount() < FluidType.BUCKET_VOLUME)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
if (action.execute())
|
||||
{
|
||||
|
||||
if (action.execute()) {
|
||||
FluidUtil.destroyBlockOnFluidPlacement(world, blockPos);
|
||||
world.setBlock(blockPos, state, Block.UPDATE_ALL_IMMEDIATE);
|
||||
}
|
||||
|
||||
return FluidType.BUCKET_VOLUME;
|
||||
}
|
||||
|
||||
public static class LiquidContainerBlockWrapper extends VoidFluidHandler
|
||||
{
|
||||
public static class LiquidContainerBlockWrapper extends VoidFluidHandler {
|
||||
protected final LiquidBlockContainer liquidContainer;
|
||||
protected final Level world;
|
||||
protected final BlockPos blockPos;
|
||||
|
||||
public LiquidContainerBlockWrapper(LiquidBlockContainer liquidContainer, Level world, BlockPos blockPos)
|
||||
{
|
||||
public LiquidContainerBlockWrapper(LiquidBlockContainer liquidContainer, Level world, BlockPos blockPos) {
|
||||
this.liquidContainer = liquidContainer;
|
||||
this.world = world;
|
||||
this.blockPos = blockPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, FluidAction action)
|
||||
{
|
||||
public int fill(FluidStack resource, FluidAction action) {
|
||||
// NOTE: "Filling" means placement in this context!
|
||||
if (resource.getAmount() >= FluidType.BUCKET_VOLUME)
|
||||
{
|
||||
if (resource.getAmount() >= FluidType.BUCKET_VOLUME) {
|
||||
BlockState state = world.getBlockState(blockPos);
|
||||
if (liquidContainer.canPlaceLiquid(world, blockPos, state, resource.getFluid()))
|
||||
{
|
||||
if (liquidContainer.canPlaceLiquid(null, world, blockPos, state, resource.getFluid())) {
|
||||
if (action.execute())
|
||||
{
|
||||
liquidContainer.placeLiquid(world, blockPos, state, resource.getFluid().getFluidType().getStateForPlacement(world, blockPos, resource));
|
||||
}
|
||||
return FluidType.BUCKET_VOLUME;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -85,7 +85,7 @@ public class BucketPickupHandlerWrapper implements IFluidHandler
|
||||
{
|
||||
if (action.execute())
|
||||
{
|
||||
ItemStack itemStack = bucketPickupHandler.pickupBlock(world, blockPos, world.getBlockState(blockPos));
|
||||
ItemStack itemStack = bucketPickupHandler.pickupBlock(null, world, blockPos, world.getBlockState(blockPos));
|
||||
if (itemStack != ItemStack.EMPTY && itemStack.getItem() instanceof BucketItem bucket)
|
||||
{
|
||||
FluidStack extracted = new FluidStack(bucket.getFluid(), FluidType.BUCKET_VOLUME);
|
||||
@@ -126,7 +126,7 @@ public class BucketPickupHandlerWrapper implements IFluidHandler
|
||||
{
|
||||
return new FluidStack(fluidState.getType(), FluidType.BUCKET_VOLUME);
|
||||
}
|
||||
ItemStack itemStack = bucketPickupHandler.pickupBlock(world, blockPos, world.getBlockState(blockPos));
|
||||
ItemStack itemStack = bucketPickupHandler.pickupBlock(null, world, blockPos, world.getBlockState(blockPos));
|
||||
if (itemStack != ItemStack.EMPTY && itemStack.getItem() instanceof BucketItem bucket)
|
||||
{
|
||||
return new FluidStack(bucket.getFluid(), FluidType.BUCKET_VOLUME);
|
||||
|
||||
@@ -7,30 +7,28 @@ package net.minecraftforge.network;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public enum ConnectionType
|
||||
{
|
||||
MODDED(s->Integer.valueOf(s.substring(NetworkConstants.FMLNETMARKER.length()))), VANILLA(s->0);
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public enum ConnectionType {
|
||||
MODDED(s -> Integer.valueOf(s.substring(NetworkConstants.FMLNETMARKER.length()))),
|
||||
VANILLA(s ->0);
|
||||
|
||||
private final Function<String, Integer> versionExtractor;
|
||||
|
||||
ConnectionType(Function<String, Integer> versionExtractor)
|
||||
{
|
||||
ConnectionType(Function<String, Integer> versionExtractor) {
|
||||
this.versionExtractor = versionExtractor;
|
||||
}
|
||||
|
||||
public static ConnectionType forVersionFlag(String vers)
|
||||
{
|
||||
public static ConnectionType forVersionFlag(String vers) {
|
||||
return vers.startsWith(NetworkConstants.FMLNETMARKER) ? MODDED : VANILLA;
|
||||
}
|
||||
|
||||
public int getFMLVersionNumber(final String fmlVersion)
|
||||
{
|
||||
public int getFMLVersionNumber(final String fmlVersion) {
|
||||
return versionExtractor.apply(fmlVersion);
|
||||
}
|
||||
|
||||
public boolean isVanilla()
|
||||
{
|
||||
public boolean isVanilla() {
|
||||
return this == VANILLA;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
|
||||
import net.minecraft.network.protocol.login.ClientboundCustomQueryPacket;
|
||||
import net.minecraft.network.protocol.login.ServerboundCustomQueryPacket;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
|
||||
@@ -341,7 +340,7 @@ public class HandshakeHandler
|
||||
public boolean tickServer()
|
||||
{
|
||||
if (!negotiationStarted) {
|
||||
GameProfile profile = ((ServerLoginPacketListenerImpl) manager.getPacketListener()).gameProfile;
|
||||
GameProfile profile = ((ServerLoginPacketListenerImpl) manager.getPacketListener()).getAuthenticatedProfile();
|
||||
PlayerNegotiationEvent event = new PlayerNegotiationEvent(manager, profile, pendingFutures);
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
negotiationStarted = true;
|
||||
|
||||
@@ -7,11 +7,14 @@ package net.minecraftforge.network;
|
||||
|
||||
import it.unimi.dsi.fastutil.objects.Reference2ReferenceArrayMap;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.common.custom.DiscardedPayload;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.protocol.login.ServerboundCustomQueryPacket;
|
||||
import net.minecraft.network.protocol.login.ClientboundCustomQueryPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.network.protocol.login.ServerboundCustomQueryAnswerPacket;
|
||||
import net.minecraft.network.protocol.login.custom.DiscardedQueryAnswerPayload;
|
||||
import net.minecraft.network.protocol.login.custom.DiscardedQueryPayload;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
@@ -22,12 +25,11 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public enum NetworkDirection
|
||||
{
|
||||
PLAY_TO_SERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT, ServerboundCustomPayloadPacket.class, 1, (d, i, n) -> new ServerboundCustomPayloadPacket(n, d)),
|
||||
PLAY_TO_CLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER, ClientboundCustomPayloadPacket.class, 0, (d, i, n) -> new ClientboundCustomPayloadPacket(n, d)),
|
||||
LOGIN_TO_SERVER(NetworkEvent.ClientCustomPayloadLoginEvent::new, LogicalSide.CLIENT, ServerboundCustomQueryPacket.class, 3, (d, i, n) -> new ServerboundCustomQueryPacket(i, d)),
|
||||
LOGIN_TO_CLIENT(NetworkEvent.ServerCustomPayloadLoginEvent::new, LogicalSide.SERVER, ClientboundCustomQueryPacket.class, 2, (d, i, n) -> new ClientboundCustomQueryPacket(i, n, d));
|
||||
public enum NetworkDirection {
|
||||
PLAY_TO_SERVER(NetworkEvent.ClientCustomPayloadEvent::new, LogicalSide.CLIENT, ServerboundCustomPayloadPacket.class, 1, NetworkDirection::playServerbound),
|
||||
PLAY_TO_CLIENT(NetworkEvent.ServerCustomPayloadEvent::new, LogicalSide.SERVER, ClientboundCustomPayloadPacket.class, 0, NetworkDirection::playClientbound),
|
||||
LOGIN_TO_SERVER(NetworkEvent.ClientCustomPayloadLoginEvent::new, LogicalSide.CLIENT, ServerboundCustomQueryAnswerPacket.class, 3, NetworkDirection::loginServerbound),
|
||||
LOGIN_TO_CLIENT(NetworkEvent.ServerCustomPayloadLoginEvent::new, LogicalSide.SERVER, ClientboundCustomQueryPacket.class, 2, NetworkDirection::loginClientbound);
|
||||
|
||||
private final BiFunction<ICustomPacket<?>, Supplier<NetworkEvent.Context>, NetworkEvent> eventSupplier;
|
||||
private final LogicalSide logicalSide;
|
||||
@@ -42,8 +44,7 @@ public enum NetworkDirection
|
||||
collect(Collectors.toMap(NetworkDirection::getPacketClass, Function.identity(), (m1,m2)->m1, Reference2ReferenceArrayMap::new));
|
||||
}
|
||||
|
||||
private NetworkDirection(BiFunction<ICustomPacket<?>, Supplier<NetworkEvent.Context>, NetworkEvent> eventSupplier, LogicalSide logicalSide, Class<? extends Packet> clazz, int i, Factory factory)
|
||||
{
|
||||
private NetworkDirection(BiFunction<ICustomPacket<?>, Supplier<NetworkEvent.Context>, NetworkEvent> eventSupplier, LogicalSide logicalSide, Class<? extends Packet> clazz, int i, Factory factory) {
|
||||
this.eventSupplier = eventSupplier;
|
||||
this.logicalSide = logicalSide;
|
||||
this.packetClass = clazz;
|
||||
@@ -54,32 +55,47 @@ public enum NetworkDirection
|
||||
private Class<? extends Packet> getPacketClass() {
|
||||
return packetClass;
|
||||
}
|
||||
public static <T extends ICustomPacket<?>> NetworkDirection directionFor(Class<T> customPacket)
|
||||
{
|
||||
|
||||
public static <T extends ICustomPacket<?>> NetworkDirection directionFor(Class<T> customPacket) {
|
||||
return packetLookup.get(customPacket);
|
||||
}
|
||||
|
||||
public NetworkDirection reply() {
|
||||
return NetworkDirection.values()[this.otherWay];
|
||||
}
|
||||
|
||||
public NetworkEvent getEvent(final ICustomPacket<?> buffer, final Supplier<NetworkEvent.Context> manager) {
|
||||
return this.eventSupplier.apply(buffer, manager);
|
||||
}
|
||||
|
||||
public LogicalSide getOriginationSide()
|
||||
{
|
||||
public LogicalSide getOriginationSide() {
|
||||
return logicalSide;
|
||||
}
|
||||
|
||||
public LogicalSide getReceptionSide() { return reply().logicalSide; };
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T extends Packet<?>> ICustomPacket<T> buildPacket(Pair<FriendlyByteBuf,Integer> packetData, ResourceLocation channelName)
|
||||
{
|
||||
public <T extends Packet<?>> ICustomPacket<T> buildPacket(Pair<FriendlyByteBuf,Integer> packetData, ResourceLocation channelName) {
|
||||
return this.factory.create(packetData.getLeft(), packetData.getRight(), channelName);
|
||||
}
|
||||
|
||||
private interface Factory<T extends Packet<?>> {
|
||||
ICustomPacket<T> create(FriendlyByteBuf data, Integer index, ResourceLocation channelName);
|
||||
}
|
||||
|
||||
private static ServerboundCustomPayloadPacket playServerbound(FriendlyByteBuf data, Integer index, ResourceLocation channelName) {
|
||||
return new ServerboundCustomPayloadPacket(new DiscardedPayload(channelName, data));
|
||||
}
|
||||
|
||||
private static ClientboundCustomPayloadPacket playClientbound(FriendlyByteBuf data, Integer index, ResourceLocation channelName) {
|
||||
return new ClientboundCustomPayloadPacket(new DiscardedPayload(channelName, data));
|
||||
}
|
||||
|
||||
private static ServerboundCustomQueryAnswerPacket loginServerbound(FriendlyByteBuf data, Integer index, ResourceLocation channelName) {
|
||||
return new ServerboundCustomQueryAnswerPacket(index, new DiscardedQueryAnswerPayload(data));
|
||||
}
|
||||
|
||||
private static ClientboundCustomQueryPacket loginClientbound(FriendlyByteBuf data, Integer index, ResourceLocation channelName) {
|
||||
return new ClientboundCustomQueryPacket(index, new DiscardedQueryPayload(channelName, data));
|
||||
}
|
||||
}
|
||||
@@ -41,35 +41,41 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerContainerEvent;
|
||||
import net.minecraftforge.fml.config.ConfigTracker;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class NetworkHooks
|
||||
{
|
||||
@ApiStatus.Internal
|
||||
public class NetworkHooks {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public static String getFMLVersion(final String ip)
|
||||
{
|
||||
return ip.contains("\0") ? Objects.equals(ip.split("\0")[1], NetworkConstants.NETVERSION) ? NetworkConstants.NETVERSION : ip.split("\0")[1] : NetworkConstants.NOVERSION;
|
||||
public static String getFMLVersion(final String ip) {
|
||||
int idx = ip.indexOf('\0');
|
||||
if (idx == -1)
|
||||
return NetworkConstants.NOVERSION;
|
||||
|
||||
for (var pt : ip.split("\0")) {
|
||||
if (pt.startsWith("FML"))
|
||||
return pt;
|
||||
}
|
||||
|
||||
return NetworkConstants.NOVERSION;
|
||||
}
|
||||
|
||||
public static ConnectionType getConnectionType(final Supplier<Connection> connection)
|
||||
{
|
||||
public static ConnectionType getConnectionType(final Supplier<Connection> connection) {
|
||||
return getConnectionType(connection.get().channel());
|
||||
}
|
||||
|
||||
public static ConnectionType getConnectionType(ChannelHandlerContext context)
|
||||
{
|
||||
public static ConnectionType getConnectionType(ChannelHandlerContext context) {
|
||||
return getConnectionType(context.channel());
|
||||
}
|
||||
|
||||
private static ConnectionType getConnectionType(Channel channel)
|
||||
{
|
||||
private static ConnectionType getConnectionType(Channel channel) {
|
||||
return ConnectionType.forVersionFlag(channel.attr(NetworkConstants.FML_NETVERSION).get());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Packet<ClientGamePacketListener> getEntitySpawningPacket(Entity entity)
|
||||
{
|
||||
public static Packet<ClientGamePacketListener> getEntitySpawningPacket(Entity entity) {
|
||||
// ClientboundCustomPayloadPacket is an instance of Packet<ClientGamePacketListener>
|
||||
return (Packet<ClientGamePacketListener>) NetworkConstants.playChannel.toVanillaPacket(new PlayMessages.SpawnEntity(entity), NetworkDirection.PLAY_TO_CLIENT);
|
||||
}
|
||||
@@ -94,14 +100,13 @@ public class NetworkHooks
|
||||
throw new IllegalStateException("Invalid packet received, aborting connection");
|
||||
}
|
||||
}
|
||||
public static void registerServerLoginChannel(Connection manager, ClientIntentionPacket packet)
|
||||
{
|
||||
manager.channel().attr(NetworkConstants.FML_NETVERSION).set(packet.getFMLVersion());
|
||||
|
||||
public static void registerServerLoginChannel(Connection manager, ClientIntentionPacket packet) {
|
||||
manager.channel().attr(NetworkConstants.FML_NETVERSION).set(NetworkHooks.getFMLVersion(packet.hostName()));
|
||||
HandshakeHandler.registerHandshake(manager, NetworkDirection.LOGIN_TO_CLIENT);
|
||||
}
|
||||
|
||||
public synchronized static void registerClientLoginChannel(Connection manager)
|
||||
{
|
||||
public synchronized static void registerClientLoginChannel(Connection manager) {
|
||||
manager.channel().attr(NetworkConstants.FML_NETVERSION).set(NetworkConstants.NOVERSION);
|
||||
HandshakeHandler.registerHandshake(manager, NetworkDirection.LOGIN_TO_SERVER);
|
||||
}
|
||||
@@ -115,17 +120,7 @@ public class NetworkHooks
|
||||
MCRegisterPacketHandler.INSTANCE.sendRegistry(manager, NetworkDirection.valueOf(direction));
|
||||
}
|
||||
|
||||
//TODO Dimensions..
|
||||
/* public synchronized static void sendDimensionDataPacket(NetworkManager manager, ServerPlayerEntity player) {
|
||||
// don't send vanilla dims
|
||||
if (player.dimension.isVanilla()) return;
|
||||
// don't sent to local - we already have a valid dim registry locally
|
||||
if (manager.isLocalChannel()) return;
|
||||
FMLNetworkConstants.playChannel.sendTo(new FMLPlayMessages.DimensionInfoMessage(player.dimension), manager, NetworkDirection.PLAY_TO_CLIENT);
|
||||
}*/
|
||||
|
||||
public static boolean isVanillaConnection(Connection manager)
|
||||
{
|
||||
public static boolean isVanillaConnection(Connection manager) {
|
||||
if (manager == null || manager.channel() == null) throw new NullPointerException("ARGH! Network Manager is null (" + manager != null ? "CHANNEL" : "MANAGER"+")" );
|
||||
return getConnectionType(() -> manager) == ConnectionType.VANILLA;
|
||||
}
|
||||
@@ -139,9 +134,8 @@ public class NetworkHooks
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean tickNegotiation(ServerLoginPacketListenerImpl netHandlerLoginServer, Connection networkManager, ServerPlayer player)
|
||||
{
|
||||
return HandshakeHandler.tickLogin(networkManager);
|
||||
public static boolean tickNegotiation(Connection manager) {
|
||||
return HandshakeHandler.tickLogin(manager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,8 +147,7 @@ public class NetworkHooks
|
||||
* @param player The player to open the GUI for
|
||||
* @param containerSupplier A supplier of container properties including the registry name of the container
|
||||
*/
|
||||
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier)
|
||||
{
|
||||
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier) {
|
||||
openScreen(player, containerSupplier, buf -> {});
|
||||
}
|
||||
|
||||
@@ -168,10 +161,10 @@ public class NetworkHooks
|
||||
* @param containerSupplier A supplier of container properties including the registry name of the container
|
||||
* @param pos A block pos, which will be encoded into the auxillary data for this request
|
||||
*/
|
||||
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier, BlockPos pos)
|
||||
{
|
||||
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier, BlockPos pos) {
|
||||
openScreen(player, containerSupplier, buf -> buf.writeBlockPos(pos));
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to open a GUI on the client, from the server
|
||||
*
|
||||
@@ -184,8 +177,7 @@ public class NetworkHooks
|
||||
* @param containerSupplier A supplier of container properties including the registry name of the container
|
||||
* @param extraDataWriter Consumer to write any additional data the GUI needs
|
||||
*/
|
||||
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier, Consumer<FriendlyByteBuf> extraDataWriter)
|
||||
{
|
||||
public static void openScreen(ServerPlayer player, MenuProvider containerSupplier, Consumer<FriendlyByteBuf> extraDataWriter) {
|
||||
if (player.level().isClientSide) return;
|
||||
player.doCloseContainer();
|
||||
player.nextContainerCounter();
|
||||
@@ -206,7 +198,7 @@ public class NetworkHooks
|
||||
return;
|
||||
MenuType<?> type = c.getType();
|
||||
PlayMessages.OpenContainer msg = new PlayMessages.OpenContainer(type, openContainerId, containerSupplier.getDisplayName(), output);
|
||||
NetworkConstants.playChannel.sendTo(msg, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT);
|
||||
NetworkConstants.playChannel.sendTo(msg, player.connection.getConnection(), NetworkDirection.PLAY_TO_CLIENT);
|
||||
|
||||
player.containerMenu = c;
|
||||
player.initMenu(player.containerMenu);
|
||||
@@ -217,8 +209,7 @@ public class NetworkHooks
|
||||
* Updates the current ConnectionData instance with new mod or channel data if the old instance did not have either of these yet,
|
||||
* or creates a new ConnectionData instance with the new data if the current ConnectionData instance doesn't exist yet.
|
||||
*/
|
||||
static void appendConnectionData(Connection mgr, Map<String, Pair<String, String>> modData, Map<ResourceLocation, String> channels)
|
||||
{
|
||||
static void appendConnectionData(Connection mgr, Map<String, Pair<String, String>> modData, Map<ResourceLocation, String> channels) {
|
||||
ConnectionData oldData = mgr.channel().attr(NetworkConstants.FML_CONNECTION_DATA).get();
|
||||
|
||||
oldData = oldData != null ? new ConnectionData(oldData.getModData().isEmpty() ? modData : oldData.getModData(), oldData.getChannels().isEmpty() ? channels : oldData.getChannels()) : new ConnectionData(modData, channels);
|
||||
@@ -226,20 +217,17 @@ public class NetworkHooks
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ConnectionData getConnectionData(Connection mgr)
|
||||
{
|
||||
public static ConnectionData getConnectionData(Connection mgr) {
|
||||
return mgr.channel().attr(NetworkConstants.FML_CONNECTION_DATA).get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ModMismatchData getModMismatchData(Connection mgr)
|
||||
{
|
||||
public static ModMismatchData getModMismatchData(Connection mgr) {
|
||||
return mgr.channel().attr(NetworkConstants.FML_MOD_MISMATCH_DATA).get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static MCRegisterPacketHandler.ChannelList getChannelList(Connection mgr)
|
||||
{
|
||||
public static MCRegisterPacketHandler.ChannelList getChannelList(Connection mgr) {
|
||||
return mgr.channel().attr(NetworkConstants.FML_MC_REGISTRY).get();
|
||||
}
|
||||
}
|
||||
@@ -200,7 +200,7 @@ public class PacketDistributor<T> {
|
||||
}
|
||||
|
||||
private Consumer<Packet<?>> playerConsumer(final Supplier<ServerPlayer> entityPlayerMPSupplier) {
|
||||
return p -> entityPlayerMPSupplier.get().connection.connection.send(p);
|
||||
return p -> entityPlayerMPSupplier.get().connection.getConnection().send(p);
|
||||
}
|
||||
private Consumer<Packet<?>> playerListDimConsumer(final Supplier<ResourceKey<Level>> dimensionTypeSupplier) {
|
||||
return p->getServer().getPlayerList().broadcastAll(p, dimensionTypeSupplier.get());
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
package net.minecraftforge.network.filters;
|
||||
|
||||
/*
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
@@ -24,7 +25,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Network filter for forge-forge connections.
|
||||
*/
|
||||
* /
|
||||
@ChannelHandler.Sharable
|
||||
public class ForgeConnectionNetworkFilter extends VanillaPacketFilter
|
||||
{
|
||||
@@ -65,3 +66,4 @@ public class ForgeConnectionNetworkFilter extends VanillaPacketFilter
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
@@ -22,8 +22,8 @@ public class NetworkFilters
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
private static final Map<String, Function<Connection, VanillaPacketFilter>> instances = ImmutableMap.of(
|
||||
"forge:vanilla_filter", manager -> new VanillaConnectionNetworkFilter(),
|
||||
"forge:forge_fixes", ForgeConnectionNetworkFilter::new
|
||||
"forge:vanilla_filter", manager -> new VanillaConnectionNetworkFilter()/*,
|
||||
"forge:forge_fixes", ForgeConnectionNetworkFilter::new*/
|
||||
);
|
||||
|
||||
public static void injectIfNecessary(Connection manager)
|
||||
|
||||
+4
-13
@@ -7,18 +7,13 @@ package net.minecraftforge.network.filters;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import net.minecraft.commands.CommandBuildContext;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfo;
|
||||
import net.minecraft.commands.synchronization.ArgumentTypeInfos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.data.registries.VanillaRegistries;
|
||||
import net.minecraft.gametest.framework.TestClassNameArgument;
|
||||
@@ -27,18 +22,11 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.game.ClientboundCommandsPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket;
|
||||
import net.minecraft.network.protocol.game.ClientboundUpdateTagsPacket;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.tags.TagNetworkSerialization;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.flag.FeatureFlags;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import net.minecraftforge.registries.RegistryManager;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@@ -61,7 +49,8 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
ImmutableMap.<Class<? extends Packet<?>>, BiConsumer<Packet<?>, List<? super Packet<?>>>>builder()
|
||||
.put(handler(ClientboundUpdateAttributesPacket.class, VanillaConnectionNetworkFilter::filterEntityProperties))
|
||||
.put(handler(ClientboundCommandsPacket.class, VanillaConnectionNetworkFilter::filterCommandList))
|
||||
.put(handler(ClientboundUpdateTagsPacket.class, VanillaConnectionNetworkFilter::filterCustomTagTypes))
|
||||
// TODO Filter tags
|
||||
//.put(handler(ClientboundUpdateTagsPacket.class, VanillaConnectionNetworkFilter::filterCustomTagTypes))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
@@ -113,12 +102,14 @@ public class VanillaConnectionNetworkFilter extends VanillaPacketFilter
|
||||
* Filters out custom tag types that the vanilla client won't recognize.
|
||||
* It prevents a rare error from logging and reduces the packet size
|
||||
*/
|
||||
/*
|
||||
private static ClientboundUpdateTagsPacket filterCustomTagTypes(ClientboundUpdateTagsPacket packet) {
|
||||
Map<ResourceKey<? extends Registry<?>>, TagNetworkSerialization.NetworkPayload> tags = packet.getTags()
|
||||
.entrySet().stream().filter(e -> isVanillaRegistry(e.getKey().location()))
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
return new ClientboundUpdateTagsPacket(tags);
|
||||
}
|
||||
*/
|
||||
|
||||
private static boolean isVanillaRegistry(ResourceLocation location)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
package net.minecraftforge.network.filters;
|
||||
|
||||
/*
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
@@ -14,7 +14,6 @@ import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.network.*;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.protocol.PacketFlow;
|
||||
import net.minecraft.network.protocol.game.ClientboundCustomPayloadPacket;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraftforge.network.*;
|
||||
import net.minecraftforge.network.event.EventNetworkChannel;
|
||||
@@ -25,9 +24,8 @@ import org.apache.logging.log4j.Logger;
|
||||
/**
|
||||
* A custom payload channel that allows sending vanilla server-to-client packets, even if they would normally
|
||||
* be too large for the vanilla protocol. This is achieved by splitting them into multiple custom payload packets.
|
||||
*/
|
||||
public class VanillaPacketSplitter
|
||||
{
|
||||
* /
|
||||
public class VanillaPacketSplitter {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
@@ -43,8 +41,7 @@ public class VanillaPacketSplitter
|
||||
private static final byte STATE_FIRST = 1;
|
||||
private static final byte STATE_LAST = 2;
|
||||
|
||||
public static void register()
|
||||
{
|
||||
public static void register() {
|
||||
Predicate<String> versionCheck = NetworkRegistry.acceptMissingOr(VERSION);
|
||||
EventNetworkChannel channel = NetworkRegistry.newEventChannel(CHANNEL, () -> VERSION, versionCheck, versionCheck);
|
||||
channel.addListener(VanillaPacketSplitter::onClientPacket);
|
||||
@@ -53,43 +50,29 @@ public class VanillaPacketSplitter
|
||||
/**
|
||||
* Append the given packet to the given list. If the packet needs to be split, multiple packets will be appened.
|
||||
* Otherwise only the packet itself.
|
||||
*/
|
||||
public static void appendPackets(ConnectionProtocol protocol, PacketFlow direction, Packet<?> packet, List<? super Packet<?>> out)
|
||||
{
|
||||
if (heuristicIsDefinitelySmallEnough(packet))
|
||||
{
|
||||
* /
|
||||
public static void appendPackets(ConnectionProtocol protocol, PacketFlow direction, Packet<?> packet, List<? super Packet<?>> out) {
|
||||
if (heuristicIsDefinitelySmallEnough(packet)) {
|
||||
out.add(packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
|
||||
packet.write(buf);
|
||||
if (buf.readableBytes() <= PROTOCOL_MAX)
|
||||
{
|
||||
if (buf.readableBytes() <= PROTOCOL_MAX) {
|
||||
buf.release();
|
||||
out.add(packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int parts = (int)Math.ceil(((double)buf.readableBytes()) / PART_SIZE);
|
||||
if (parts == 1)
|
||||
{
|
||||
if (parts == 1) {
|
||||
buf.release();
|
||||
out.add(packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int part = 0; part < parts; part++)
|
||||
{
|
||||
} else {
|
||||
for (int part = 0; part < parts; part++) {
|
||||
ByteBuf partPrefix;
|
||||
if (part == 0)
|
||||
{
|
||||
if (part == 0) {
|
||||
partPrefix = Unpooled.buffer(5);
|
||||
partPrefix.writeByte(STATE_FIRST);
|
||||
new FriendlyByteBuf(partPrefix).writeVarInt(protocol.getPacketId(direction, packet));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
partPrefix = Unpooled.buffer(1);
|
||||
partPrefix.writeByte(part == parts - 1 ? STATE_LAST : 0);
|
||||
}
|
||||
@@ -108,15 +91,13 @@ public class VanillaPacketSplitter
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean heuristicIsDefinitelySmallEnough(Packet<?> packet)
|
||||
{
|
||||
private static boolean heuristicIsDefinitelySmallEnough(Packet<?> packet) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final List<FriendlyByteBuf> receivedBuffers = new ArrayList<>();
|
||||
|
||||
private static void onClientPacket(NetworkEvent.ServerCustomPayloadEvent event)
|
||||
{
|
||||
private static void onClientPacket(NetworkEvent.ServerCustomPayloadEvent event) {
|
||||
NetworkEvent.Context ctx = event.getSource().get();
|
||||
PacketFlow direction = ctx.getDirection() == NetworkDirection.PLAY_TO_CLIENT ? PacketFlow.CLIENTBOUND : PacketFlow.SERVERBOUND;
|
||||
ConnectionProtocol protocol = ConnectionProtocol.PLAY;
|
||||
@@ -126,27 +107,21 @@ public class VanillaPacketSplitter
|
||||
FriendlyByteBuf buf = event.getPayload();
|
||||
|
||||
byte state = buf.readByte();
|
||||
if (state == STATE_FIRST)
|
||||
{
|
||||
if (!receivedBuffers.isEmpty())
|
||||
{
|
||||
if (state == STATE_FIRST) {
|
||||
if (!receivedBuffers.isEmpty()) {
|
||||
LOGGER.warn("forge:split received out of order - inbound buffer not empty when receiving first");
|
||||
receivedBuffers.clear();
|
||||
}
|
||||
}
|
||||
buf.retain(); // retain the buffer, it is released after this handler otherwise
|
||||
receivedBuffers.add(buf);
|
||||
if (state == STATE_LAST)
|
||||
{
|
||||
if (state == STATE_LAST) {
|
||||
FriendlyByteBuf full = new FriendlyByteBuf(Unpooled.wrappedBuffer(receivedBuffers.toArray(new FriendlyByteBuf[0])));
|
||||
int packetId = full.readVarInt();
|
||||
Packet<?> packet = protocol.createPacket(direction, packetId, full);
|
||||
if (packet == null)
|
||||
{
|
||||
if (packet == null) {
|
||||
LOGGER.error("Received invalid packet ID {} in forge:split", packetId);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
receivedBuffers.clear();
|
||||
full.release();
|
||||
ctx.enqueueWork(() -> genericsFtw(packet, event.getSource().get().getNetworkManager().getPacketListener()));
|
||||
@@ -155,32 +130,25 @@ public class VanillaPacketSplitter
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T extends PacketListener> void genericsFtw(Packet<T> pkt, Object listener)
|
||||
{
|
||||
private static <T extends PacketListener> void genericsFtw(Packet<T> pkt, Object listener) {
|
||||
pkt.handle((T) listener);
|
||||
}
|
||||
|
||||
public enum RemoteCompatibility
|
||||
{
|
||||
public enum RemoteCompatibility {
|
||||
ABSENT,
|
||||
PRESENT
|
||||
}
|
||||
|
||||
public static RemoteCompatibility getRemoteCompatibility(Connection manager)
|
||||
{
|
||||
public static RemoteCompatibility getRemoteCompatibility(Connection manager) {
|
||||
ConnectionData connectionData = NetworkHooks.getConnectionData(manager);
|
||||
if (connectionData != null && connectionData.getChannels().containsKey(CHANNEL))
|
||||
{
|
||||
return RemoteCompatibility.PRESENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RemoteCompatibility.ABSENT;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isRemoteCompatible(Connection manager)
|
||||
{
|
||||
public static boolean isRemoteCompatible(Connection manager) {
|
||||
return getRemoteCompatibility(manager) != RemoteCompatibility.ABSENT;
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -25,7 +25,7 @@ public class ForgeDeferredRegistriesSetup
|
||||
}
|
||||
|
||||
ForgeRegistries.DEFERRED_ENTITY_DATA_SERIALIZERS.register(modEventBus);
|
||||
ForgeRegistries.DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS.register(modEventBus);
|
||||
//ForgeRegistries.DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS.register(modEventBus);
|
||||
ForgeRegistries.DEFERRED_BIOME_MODIFIER_SERIALIZERS.register(modEventBus);
|
||||
ForgeRegistries.DEFERRED_FLUID_TYPES.register(modEventBus);
|
||||
ForgeRegistries.DEFERRED_STRUCTURE_MODIFIER_SERIALIZERS.register(modEventBus);
|
||||
|
||||
@@ -43,15 +43,10 @@ import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacerType;
|
||||
import net.minecraft.world.level.levelgen.feature.treedecorators.TreeDecoratorType;
|
||||
import net.minecraftforge.common.Tags;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.fluids.FluidType;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.holdersets.HolderSetType;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraftforge.common.world.StructureModifier;
|
||||
|
||||
@@ -109,12 +104,12 @@ public class ForgeRegistries
|
||||
* Use {@link Keys#ENTITY_DATA_SERIALIZERS} to create a {@link DeferredRegister}.
|
||||
*/
|
||||
public static final Supplier<IForgeRegistry<EntityDataSerializer<?>>> ENTITY_DATA_SERIALIZERS = DEFERRED_ENTITY_DATA_SERIALIZERS.makeRegistry(GameData::getDataSerializersRegistryBuilder);
|
||||
static final DeferredRegister<Codec<? extends IGlobalLootModifier>> DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS = DeferredRegister.create(Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS.location().getNamespace());
|
||||
//static final DeferredRegister<Codec<? extends IGlobalLootModifier>> DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS = DeferredRegister.create(Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS, Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS.location().getNamespace());
|
||||
/**
|
||||
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
|
||||
* Use {@link Keys#GLOBAL_LOOT_MODIFIER_SERIALIZERS} to create a {@link DeferredRegister}.
|
||||
*/
|
||||
public static final Supplier<IForgeRegistry<Codec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS.makeRegistry(GameData::getGLMSerializersRegistryBuilder);
|
||||
//public static final Supplier<IForgeRegistry<Codec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = DEFERRED_GLOBAL_LOOT_MODIFIER_SERIALIZERS.makeRegistry(GameData::getGLMSerializersRegistryBuilder);
|
||||
static final DeferredRegister<Codec<? extends BiomeModifier>> DEFERRED_BIOME_MODIFIER_SERIALIZERS = DeferredRegister.create(Keys.BIOME_MODIFIER_SERIALIZERS, Keys.BIOME_MODIFIER_SERIALIZERS.location().getNamespace());
|
||||
/**
|
||||
* Calling {@link Supplier#get()} before {@link NewRegistryEvent} is fired will result in a null registry returned.
|
||||
@@ -184,7 +179,7 @@ public class ForgeRegistries
|
||||
|
||||
// Forge
|
||||
public static final ResourceKey<Registry<EntityDataSerializer<?>>> ENTITY_DATA_SERIALIZERS = key("forge:entity_data_serializers");
|
||||
public static final ResourceKey<Registry<Codec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = key("forge:global_loot_modifier_serializers");
|
||||
//public static final ResourceKey<Registry<Codec<? extends IGlobalLootModifier>>> GLOBAL_LOOT_MODIFIER_SERIALIZERS = key("forge:global_loot_modifier_serializers");
|
||||
public static final ResourceKey<Registry<Codec<? extends BiomeModifier>>> BIOME_MODIFIER_SERIALIZERS = key("forge:biome_modifier_serializers");
|
||||
public static final ResourceKey<Registry<Codec<? extends StructureModifier>>> STRUCTURE_MODIFIER_SERIALIZERS = key("forge:structure_modifier_serializers");
|
||||
public static final ResourceKey<Registry<FluidType>> FLUID_TYPES = key("forge:fluid_type");
|
||||
|
||||
@@ -30,6 +30,7 @@ import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.network.syncher.EntityDataSerializer;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.SpawnPlacements;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
@@ -38,7 +39,10 @@ import net.minecraft.world.entity.ai.village.poi.PoiType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.levelgen.DebugLevelSource;
|
||||
@@ -46,7 +50,6 @@ import net.minecraft.world.level.material.Fluid;
|
||||
import net.minecraftforge.common.CreativeModeTabRegistry;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.loot.IGlobalLootModifier;
|
||||
import net.minecraftforge.common.util.LogMessageAdapter;
|
||||
import net.minecraftforge.common.world.BiomeModifier;
|
||||
import net.minecraftforge.common.world.StructureModifier;
|
||||
@@ -103,12 +106,12 @@ public class GameData
|
||||
makeRegistry(Keys.BLOCKS, "air").addCallback(BlockCallbacks.INSTANCE).legacyName("blocks").intrusiveHolderCallback(Block::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.FLUIDS, "empty").intrusiveHolderCallback(Fluid::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.ITEMS, "air").addCallback(ItemCallbacks.INSTANCE).legacyName("items").intrusiveHolderCallback(Item::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.MOB_EFFECTS).legacyName("potions").create();
|
||||
makeRegistry(Keys.MOB_EFFECTS).legacyName("potions").intrusiveHolderCallback(MobEffect::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.SOUND_EVENTS).legacyName("soundevents").create();
|
||||
makeRegistry(Keys.POTIONS, "empty").legacyName("potiontypes").create();
|
||||
makeRegistry(Keys.ENCHANTMENTS).legacyName("enchantments").create();
|
||||
makeRegistry(Keys.POTIONS, "empty").legacyName("potiontypes").intrusiveHolderCallback(Potion::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.ENCHANTMENTS).legacyName("enchantments").intrusiveHolderCallback(Enchantment::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.ENTITY_TYPES, "pig").legacyName("entities").intrusiveHolderCallback(EntityType::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.BLOCK_ENTITY_TYPES).disableSaving().legacyName("blockentities").create();
|
||||
makeRegistry(Keys.BLOCK_ENTITY_TYPES).disableSaving().legacyName("blockentities").intrusiveHolderCallback(BlockEntityType::builtInRegistryHolder).create();
|
||||
makeRegistry(Keys.PARTICLE_TYPES).disableSaving().create();
|
||||
makeRegistry(Keys.MENU_TYPES).disableSaving().create();
|
||||
makeRegistry(Keys.PAINTING_VARIANTS, "kebab").create();
|
||||
@@ -143,10 +146,12 @@ public class GameData
|
||||
return makeRegistry(Keys.ENTITY_DATA_SERIALIZERS, 256 /*vanilla space*/, MAX_VARINT).disableSaving().disableOverrides();
|
||||
}
|
||||
|
||||
/*
|
||||
static RegistryBuilder<Codec<? extends IGlobalLootModifier>> getGLMSerializersRegistryBuilder()
|
||||
{
|
||||
return makeRegistry(Keys.GLOBAL_LOOT_MODIFIER_SERIALIZERS).disableSaving().disableSync();
|
||||
}
|
||||
*/
|
||||
|
||||
static RegistryBuilder<Codec<? extends BiomeModifier>> getBiomeModifierSerializersRegistryBuilder()
|
||||
{
|
||||
|
||||
@@ -22,6 +22,7 @@ import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.gametest.framework.GameTestServer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.server.packs.PackResources;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.server.packs.repository.PackSource;
|
||||
import net.minecraft.server.packs.repository.RepositorySource;
|
||||
@@ -52,6 +53,7 @@ import net.minecraft.network.ConnectionProtocol;
|
||||
import net.minecraft.network.protocol.handshake.ClientIntentionPacket;
|
||||
import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket;
|
||||
import net.minecraft.server.packs.repository.Pack;
|
||||
import net.minecraft.server.packs.repository.Pack.Info;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -159,9 +161,10 @@ public class ServerLifecycleHooks
|
||||
return false;
|
||||
}
|
||||
|
||||
if (packet.getIntention() == ConnectionProtocol.LOGIN) {
|
||||
final ConnectionType connectionType = ConnectionType.forVersionFlag(packet.getFMLVersion());
|
||||
final int versionNumber = connectionType.getFMLVersionNumber(packet.getFMLVersion());
|
||||
if (packet.nextProtocol() == ConnectionProtocol.LOGIN) {
|
||||
var fmlVersion = NetworkHooks.getFMLVersion(packet.hostName());
|
||||
final ConnectionType connectionType = ConnectionType.forVersionFlag(fmlVersion);
|
||||
final int versionNumber = connectionType.getFMLVersionNumber(fmlVersion);
|
||||
|
||||
if (connectionType == ConnectionType.MODDED && versionNumber != NetworkConstants.FMLNETVERSION) {
|
||||
rejectConnection(manager, connectionType, "This modded server is not impl compatible with your modded client. Please verify your Forge version closely matches the server. Got net version " + versionNumber + " this server is net version " + NetworkConstants.FMLNETVERSION);
|
||||
@@ -174,7 +177,7 @@ public class ServerLifecycleHooks
|
||||
}
|
||||
}
|
||||
|
||||
if (packet.getIntention() == ConnectionProtocol.STATUS) return true;
|
||||
if (packet.nextProtocol() == ConnectionProtocol.STATUS) return true;
|
||||
|
||||
NetworkHooks.registerServerLoginChannel(manager, packet);
|
||||
return true;
|
||||
@@ -182,11 +185,8 @@ public class ServerLifecycleHooks
|
||||
}
|
||||
|
||||
private static void rejectConnection(final Connection manager, ConnectionType type, String message) {
|
||||
manager.setProtocol(ConnectionProtocol.LOGIN);
|
||||
String ip = "local";
|
||||
if (manager.getRemoteAddress() != null)
|
||||
ip = manager.getRemoteAddress().toString();
|
||||
LOGGER.info(SERVERHOOKS, "[{}] Disconnecting {} connection attempt: {}", ip, type, message);
|
||||
//manager.setProtocol(ConnectionProtocol.LOGIN); Pretty sure things auto swap in ProtocolSwapHandler
|
||||
LOGGER.info(SERVERHOOKS, "[{}] Disconnecting {} connection attempt: {}", manager.getLoggableAddress(true), type, message); // TODO: Respect logIP setting
|
||||
MutableComponent text = Component.literal(message);
|
||||
manager.send(new ClientboundLoginDisconnectPacket(text));
|
||||
manager.disconnect(text);
|
||||
@@ -208,7 +208,21 @@ public class ServerLifecycleHooks
|
||||
IModInfo mod = e.getKey().getModInfos().get(0);
|
||||
if (Objects.equals(mod.getModId(), "minecraft")) continue; // skip the minecraft "mod"
|
||||
final String name = "mod:" + mod.getModId();
|
||||
final Pack modPack = Pack.readMetaAndCreate(name, Component.literal(e.getValue().packId()), false, id -> e.getValue(), PackType.SERVER_DATA, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
|
||||
var supplier = new Pack.ResourcesSupplier() {
|
||||
@Override
|
||||
public PackResources openPrimary(String path) {
|
||||
return e.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PackResources openFull(String path, Info info) {
|
||||
return e.getValue(); // TODO: composite
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
final Pack modPack = Pack.readMetaAndCreate(name, Component.literal(e.getValue().packId()), false, supplier, PackType.SERVER_DATA, Pack.Position.BOTTOM, PackSource.DEFAULT);
|
||||
if (modPack == null) {
|
||||
// Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong
|
||||
ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
|
||||
|
||||
@@ -13,34 +13,25 @@ import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraftforge.network.ConnectionType;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class TextComponentHelper
|
||||
{
|
||||
public class TextComponentHelper {
|
||||
private TextComponentHelper() {}
|
||||
|
||||
/**
|
||||
* Detects when sending to a vanilla client and falls back to sending english,
|
||||
* since they don't have the lang data necessary to translate on the client.
|
||||
*/
|
||||
public static MutableComponent createComponentTranslation(CommandSource source, final String translation, final Object... args)
|
||||
{
|
||||
public static MutableComponent createComponentTranslation(CommandSource source, final String translation, final Object... args) {
|
||||
if (isVanillaClient(source))
|
||||
{
|
||||
return Component.literal(String.format(Locale.ENGLISH, Language.getInstance().getOrDefault(translation), args));
|
||||
}
|
||||
return Component.translatable(translation, args);
|
||||
}
|
||||
|
||||
private static boolean isVanillaClient(CommandSource sender)
|
||||
{
|
||||
if (sender instanceof ServerPlayer)
|
||||
{
|
||||
ServerPlayer playerMP = (ServerPlayer) sender;
|
||||
private static boolean isVanillaClient(CommandSource sender) {
|
||||
if (sender instanceof ServerPlayer playerMP) {
|
||||
ServerGamePacketListenerImpl channel = playerMP.connection;
|
||||
return NetworkHooks.getConnectionType(()->channel.connection) == ConnectionType.VANILLA;
|
||||
return NetworkHooks.getConnectionType(channel::getConnection) == ConnectionType.VANILLA;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user