Skip to content

Commit

Permalink
separate more internal classes out into the Common subproject
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Apr 5, 2022
1 parent 056631d commit fdd0593
Show file tree
Hide file tree
Showing 154 changed files with 612 additions and 424 deletions.
@@ -1,4 +1,4 @@
package mezz.jei.config;
package mezz.jei.common;

import mezz.jei.api.recipe.RecipeType;
import net.minecraft.resources.ResourceLocation;
Expand Down
16 changes: 15 additions & 1 deletion Common/src/main/java/mezz/jei/common/color/ColorNamer.java
@@ -1,7 +1,9 @@
package mezz.jei.common.color;

import com.google.common.base.Preconditions;
import org.jetbrains.annotations.Nullable;

import java.awt.*;
import java.util.Comparator;
import java.util.Map;
import java.util.stream.Stream;
Expand All @@ -10,9 +12,21 @@
import com.google.common.collect.ImmutableMap;

public class ColorNamer {
@Nullable
private static ColorNamer INSTANCE = null;

public static ColorNamer getInstance() {
Preconditions.checkState(INSTANCE != null, "Color Namer has not been created yet.");
return INSTANCE;
}

public static void create(ImmutableMap<Integer, String> colorNames) {
INSTANCE = new ColorNamer(colorNames);
}

private final ImmutableMap<Integer, String> colorNames;

public ColorNamer(ImmutableMap<Integer, String> colorNames) {
private ColorNamer(ImmutableMap<Integer, String> colorNames) {
this.colorNames = colorNames;
}

Expand Down
@@ -1,9 +1,9 @@
package mezz.jei.config;
package mezz.jei.common.config;

import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.api.ingredients.ITypedIngredient;
import mezz.jei.common.ingredients.IngredientFilter;
import mezz.jei.core.config.IngredientBlacklistType;
import mezz.jei.ingredients.IngredientFilter;

public interface IEditModeConfig {
<V> boolean isIngredientOnConfigBlacklist(ITypedIngredient<V> ingredient, IIngredientHelper<V> ingredientHelper);
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.config;
package mezz.jei.common.config;

import mezz.jei.core.search.SearchMode;

Expand Down
7 changes: 7 additions & 0 deletions Common/src/main/java/mezz/jei/common/config/package-info.java
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mezz.jei.common.config;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
@@ -1,4 +1,4 @@
package mezz.jei.gui;
package mezz.jei.common.gui;

import mezz.jei.common.util.ImmutableRect2i;
import net.minecraft.client.gui.components.Button;
Expand Down
@@ -1,7 +1,9 @@
package mezz.jei.gui;
package mezz.jei.common.gui;

import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.ingredients.IIngredientRenderer;
import mezz.jei.common.platform.IPlatformRenderHelper;
import mezz.jei.common.platform.Services;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -37,6 +39,7 @@ private static void drawHoveringText(PoseStack poseStack, List<Component> textLi
}

Optional<TooltipComponent> tooltipImage = itemStack.getTooltipImage();
screen.renderTooltip(poseStack, textLines, tooltipImage, x, y, font, itemStack);
IPlatformRenderHelper renderHelper = Services.PLATFORM.getRenderHelper();
renderHelper.renderTooltip(screen, poseStack, textLines, tooltipImage, x, y, font, itemStack);
}
}
@@ -1,10 +1,10 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.gui.ITickTimer;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.gui.TickTimer;
import mezz.jei.common.util.TickTimer;

public class DrawableAnimated implements IDrawableAnimated {
private final IDrawableStatic drawable;
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.gui.drawable.IDrawableAnimated;
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import net.minecraft.resources.ResourceLocation;

Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.systems.RenderSystem;
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.BufferBuilder;
Expand All @@ -7,8 +7,8 @@
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.math.Matrix4f;
import mezz.jei.config.Constants;
import mezz.jei.gui.textures.JeiSpriteUploader;
import mezz.jei.common.Constants;
import mezz.jei.common.gui.textures.JeiSpriteUploader;
import mezz.jei.common.util.ImmutableRect2i;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
Expand Down
@@ -1,18 +1,19 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexFormat;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.Tesselator;
import mezz.jei.common.Constants;
import mezz.jei.common.gui.textures.JeiSpriteUploader;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import net.minecraft.resources.ResourceLocation;

import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.config.Constants;
import mezz.jei.gui.textures.JeiSpriteUploader;

import com.mojang.math.Matrix4f;

public class DrawableSprite implements IDrawableStatic {
Expand Down
@@ -1,13 +1,12 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.Internal;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.gui.textures.Textures;
import mezz.jei.input.UserInput;
import mezz.jei.input.mouse.IUserInputHandler;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.input.IUserInputHandler;
import mezz.jei.common.input.UserInput;
import mezz.jei.common.util.ImmutableRect2i;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;
Expand All @@ -21,10 +20,12 @@
*/
public class GuiIconButton extends Button {
private final IDrawable icon;
private final Textures textures;

public GuiIconButton(IDrawable icon, OnPress pressable) {
public GuiIconButton(IDrawable icon, OnPress pressable, Textures textures) {
super(0, 0, 0, 0, TextComponent.EMPTY, pressable);
this.icon = icon;
this.textures = textures;
}

public void updateBounds(ImmutableRect2i area) {
Expand All @@ -34,6 +35,10 @@ public void updateBounds(ImmutableRect2i area) {
this.height = area.getHeight();
}

public void setHeight(int value) {
this.height = value;
}

@Override
public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) {
if (this.visible) {
Expand All @@ -42,22 +47,15 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic
RenderSystem.enableBlend();
RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
Textures textures = Internal.getTextures();
Minecraft minecraft = Minecraft.getInstance();
DrawableNineSliceTexture texture = textures.getButtonForState(this.active, hovered);
texture.draw(poseStack, this.x, this.y, this.width, this.height);
this.renderBg(poseStack, minecraft, mouseX, mouseY);

int color = 14737632;
if (packedFGColor != 0) {
color = packedFGColor;
} else if (!this.active) {
color = 10526880;
int color = 0xFFE0E0E0;
if (!this.active) {
color = 0xFFA0A0A0;
} else if (hovered) {
color = 16777120;
}
if ((color & -67108864) == 0) {
color |= -16777216;
color = 0xFFFFFFA0;
}

float red = (color >> 16 & 255) / 255.0F;
Expand Down
@@ -1,25 +1,25 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.util.ImmutableRect2i;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.components.Button;

import mezz.jei.Internal;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.gui.textures.Textures;
import net.minecraft.network.chat.TextComponent;

/**
* A small gui button that has an {@link IDrawable} instead of a string label.
*/
public class GuiIconButtonSmall extends Button {
private final IDrawable icon;
private final Textures textures;

public GuiIconButtonSmall(int x, int y, int widthIn, int heightIn, IDrawable icon, Button.OnPress pressable) {
public GuiIconButtonSmall(int x, int y, int widthIn, int heightIn, IDrawable icon, Button.OnPress pressable, Textures textures) {
super(x, y, widthIn, heightIn, TextComponent.EMPTY, pressable);
this.icon = icon;
this.textures = textures;
}

public ImmutableRect2i getArea() {
Expand All @@ -32,21 +32,15 @@ public void render(PoseStack poseStack, int mouseX, int mouseY, float partialTic
Minecraft minecraft = Minecraft.getInstance();
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
boolean hovered = isMouseOver(mouseX, mouseY);
Textures textures = Internal.getTextures();
DrawableNineSliceTexture texture = textures.getButtonForState(this.active, hovered);
texture.draw(poseStack, this.x, this.y, this.width, this.height);
this.renderBg(poseStack, minecraft, mouseX, mouseY);

int color = 14737632;
if (packedFGColor != 0) {
color = packedFGColor;
} else if (!this.active) {
color = 10526880;
int color = 0xFFE0E0E0;
if (!this.active) {
color = 0xFFA0A0A0;
} else if (hovered) {
color = 16777120;
}
if ((color & -67108864) == 0) {
color |= -16777216;
color = 0xFFFFFFA0;
}

float red = (color >> 16 & 255) / 255.0F;
Expand Down
@@ -1,11 +1,12 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.gui.HoverChecker;
import mezz.jei.gui.TooltipRenderer;
import mezz.jei.input.UserInput;
import mezz.jei.input.mouse.IUserInputHandler;
import mezz.jei.common.gui.HoverChecker;
import mezz.jei.common.gui.TooltipRenderer;
import mezz.jei.common.gui.textures.Textures;
import mezz.jei.common.input.IUserInputHandler;
import mezz.jei.common.input.UserInput;
import mezz.jei.common.util.ImmutableRect2i;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
Expand All @@ -20,11 +21,10 @@ public abstract class GuiIconToggleButton {
private final GuiIconButton button;
private final HoverChecker hoverChecker;

public GuiIconToggleButton(IDrawable offIcon, IDrawable onIcon) {
public GuiIconToggleButton(IDrawable offIcon, IDrawable onIcon, Textures textures) {
this.offIcon = offIcon;
this.onIcon = onIcon;
this.button = new GuiIconButton(new DrawableBlank(0, 0), b -> {
});
this.button = new GuiIconButton(new DrawableBlank(0, 0), b -> {}, textures);
this.hoverChecker = new HoverChecker();
this.hoverChecker.updateBounds(this.button);
}
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.google.common.base.Preconditions;
import com.mojang.blaze3d.vertex.PoseStack;
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.elements;
package mezz.jei.common.gui.elements;

import com.mojang.blaze3d.vertex.PoseStack;
import mezz.jei.api.gui.drawable.IDrawable;
Expand Down
@@ -1,6 +1,6 @@
@ParametersAreNonnullByDefault
@FieldsAndMethodsAreNonnullByDefault
package mezz.jei.gui.textures;
package mezz.jei.common.gui.elements;

import javax.annotation.ParametersAreNonnullByDefault;

Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.ingredients;
package mezz.jei.common.gui.ingredients;

import mezz.jei.api.ingredients.ITypedIngredient;
import net.minecraft.client.gui.screens.Screen;
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.ingredients;
package mezz.jei.common.gui.ingredients;

import mezz.jei.api.ingredients.ITypedIngredient;

Expand Down
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mezz.jei.common.gui.ingredients;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
@@ -1,4 +1,4 @@
package mezz.jei.gui.overlay;
package mezz.jei.common.gui.overlay;

public interface IFilterTextSource {
String getFilterText();
Expand Down
@@ -1,4 +1,4 @@
package mezz.jei.gui.overlay;
package mezz.jei.common.gui.overlay;

import mezz.jei.api.ingredients.ITypedIngredient;
import org.jetbrains.annotations.Unmodifiable;
Expand Down
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mezz.jei.common.gui.overlay;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
7 changes: 7 additions & 0 deletions Common/src/main/java/mezz/jei/common/gui/package-info.java
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package mezz.jei.common.gui;

import net.minecraft.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;

0 comments on commit fdd0593

Please sign in to comment.