diff --git a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEPatternProvider.java b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEPatternProvider.java index 70ec8bb9..fcd9a961 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/GuiMEPatternProvider.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/GuiMEPatternProvider.java @@ -3,6 +3,7 @@ import appeng.client.gui.widgets.GuiCustomSlot; import appeng.fluids.client.gui.widgets.GuiFluidTank; import github.kasuminova.mmce.client.gui.slot.GuiFullCapFluidTank; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.Button; import github.kasuminova.mmce.client.gui.widget.Button4State; import github.kasuminova.mmce.client.gui.widget.ButtonElements; @@ -84,9 +85,9 @@ public GuiMEPatternProvider(final MEPatternProvider owner, final EntityPlayer pl // Init ReturnItems... Button4State returnItems = new Button4State(); returnItems - .setMouseDownTextureXY(176 + 18 + 18, 214) - .setHoveredTextureXY(176 + 18, 214) - .setTextureXY(176, 214) + .setMouseDownTexture(176 + 18 + 18, 214) + .setHoveredTexture(176 + 18, 214) + .setTexture(176, 214) .setTextureLocation(GuiMEPatternProvider.GUI_TEXTURE) .setTooltipFunction((btn) -> { List tooltips = new ArrayList<>(); @@ -100,17 +101,17 @@ public GuiMEPatternProvider(final MEPatternProvider owner, final EntityPlayer pl // Init WorkModeSetting... workModeSetting // ButtonTexture 1 - .addElement(MEPatternProvider.WorkModeSetting.DEFAULT, 140, 196, GuiMEPatternProvider.GUI_TEXTURE) + .addElement(MEPatternProvider.WorkModeSetting.DEFAULT, TextureProperties.of(140, 196, 16, 16)) // ButtonTexture 2 - .addElement(MEPatternProvider.WorkModeSetting.BLOCKING_MODE, 140 + 18, 196, GuiMEPatternProvider.GUI_TEXTURE) + .addElement(MEPatternProvider.WorkModeSetting.BLOCKING_MODE, TextureProperties.of(140 + 18, 196, 16, 16)) // ButtonTexture 3 - .addElement(MEPatternProvider.WorkModeSetting.CRAFTING_LOCK_MODE, 140 + 18 + 18, 196, GuiMEPatternProvider.GUI_TEXTURE) + .addElement(MEPatternProvider.WorkModeSetting.CRAFTING_LOCK_MODE, TextureProperties.of(140 + 18 + 18, 196, 16, 16)) // ButtonTexture 5 - .setMouseDownTextureXY(140 + 18 + 18 + 18 + 18 + 18, 196) + .setMouseDownTexture(140 + 18 + 18 + 18 + 18 + 18, 196) // ButtonTexture 5 - .setHoveredTextureXY(140 + 18 + 18 + 18 + 18, 196) + .setHoveredTexture(140 + 18 + 18 + 18 + 18, 196) // ButtonTexture 4 - .setTextureXY(140 + 18 + 18 + 18, 196) + .setTexture(140 + 18 + 18 + 18, 196) .setTextureLocation(GuiMEPatternProvider.GUI_TEXTURE) .setTooltipFunction((btn) -> { MEPatternProvider.WorkModeSetting current = workModeSetting.getCurrentSelection(); @@ -141,8 +142,8 @@ public GuiMEPatternProvider(final MEPatternProvider owner, final EntityPlayer pl Button singleInvTip = new Button(); singleInvTip .setTextureLocation(GuiMEPatternProvider.GUI_TEXTURE) - .setTextureXY(230, 214) - .setHoveredTextureXY(230 + 11, 214) + .setTexture(230, 214) + .setHoveredTexture(230 + 11, 214) .setTooltipFunction((btn) -> { List tooltips = new ArrayList<>(); tooltips.add(I18n.format("gui.mepatternprovider.single_inv.desc")); diff --git a/src/main/java/github/kasuminova/mmce/client/gui/util/TextureProperties.java b/src/main/java/github/kasuminova/mmce/client/gui/util/TextureProperties.java new file mode 100644 index 00000000..a5221ee6 --- /dev/null +++ b/src/main/java/github/kasuminova/mmce/client/gui/util/TextureProperties.java @@ -0,0 +1,220 @@ +package github.kasuminova.mmce.client.gui.util; + +import com.github.bsideup.jabel.Desugar; +import com.google.common.base.Preconditions; +import github.kasuminova.mmce.client.gui.widget.base.WidgetGui; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.util.ResourceLocation; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.Optional; +import java.util.function.Consumer; + +@Desugar +@ParametersAreNonnullByDefault +@SuppressWarnings("unused") +public record TextureProperties(@Nullable ResourceLocation texRes, int texX, int texY, int width, int height) { + + public static final TextureProperties EMPTY = new TextureProperties(null, 0, 0, 0, 0); + + public static TextureProperties of(@Nullable final ResourceLocation texRes, final int texX, final int texY, final int width, final int height) { + return new TextureProperties(texRes, texX, texY, width, height); + } + + public static TextureProperties of(final int texX, final int texY, final int width, final int height) { + return of(null, texX, texY, width, height); + } + + public static TextureProperties of(final int texX, final int texY, final int widthHeight) { + return of(null, texX, texY, widthHeight, widthHeight); + } + + public static TextureProperties of(@Nullable final ResourceLocation texRes, final int texX, final int texY) { + return of(texRes, texX, texY, 0, 0); + } + + public static TextureProperties of(final int texX, final int texY) { + return of(null, texX, texY); + } + + public void bind(final TextureManager textureManager) { + if (texRes != null) { + bind(textureManager, texRes); + } + } + + private static void bind(final TextureManager textureManager, final ResourceLocation texRes) { + textureManager.bindTexture(texRes); + } + + // Default render + + public void render(final RenderPos renderPos, final WidgetGui gui) { + render(renderPos, gui.getGui()); + } + + public void render(final RenderPos renderPos, final GuiScreen gui) { + bind(gui.mc.getTextureManager()); + gui.drawTexturedModalRect(renderPos.posX(), renderPos.posY(), texX, texY, width, height); + } + + public void renderIfPresent(final RenderPos renderPos, final WidgetGui gui) { + ifPresent(t -> t.render(renderPos, gui)); + } + + public void renderIfPresent(final RenderPos renderPos, final GuiScreen gui) { + ifPresent(t -> t.render(renderPos, gui)); + } + + public void renderIfPresent(final RenderPos renderPos, final WidgetGui gui, final Consumer before) { + ifPresent(t -> before.andThen(t1 -> t.render(renderPos, gui)).accept(t)); + } + + public void renderIfPresent(final RenderPos renderPos, final GuiScreen gui, final Consumer before) { + ifPresent(t -> before.andThen(t1 -> t.render(renderPos, gui)).accept(t)); + } + + public void renderIfPresent(final RenderPos renderPos, final WidgetGui gui, @Nullable final Consumer before, @Nullable final Consumer after) { + ifPresent(t -> { + Optional.ofNullable(before).ifPresent(bc -> bc.accept(t)); + t.render(renderPos, gui); + Optional.ofNullable(after).ifPresent(ac -> ac.accept(t)); + }); + } + + public void renderIfPresent(final RenderPos renderPos, final GuiScreen gui, @Nullable final Consumer before, @Nullable final Consumer after) { + ifPresent(t -> { + Optional.ofNullable(before).ifPresent(bc -> bc.accept(t)); + t.render(renderPos, gui); + Optional.ofNullable(after).ifPresent(ac -> ac.accept(t)); + }); + } + + public void ifPresent(final Consumer runnable) { + if (texRes != null && width > 0 && height > 0) { + runnable.accept(this); + } + } + + // Custom texture render + + public void render(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final WidgetGui gui) { + render(customTexRes, renderPos, gui.getGui()); + } + + public void render(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final GuiScreen gui) { + TextureManager textureManager = gui.mc.getTextureManager(); + if (texRes != null) { + bind(textureManager); + } else { + bind(textureManager, Preconditions.checkNotNull(customTexRes, "texRes is null, but customTexRes is null too!")); + } + gui.drawTexturedModalRect(renderPos.posX(), renderPos.posY(), texX, texY, width, height); + } + + public void renderIfPresent(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final WidgetGui gui) { + ifSizePresent(t -> t.render(customTexRes, renderPos, gui)); + } + + public void renderIfPresent(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final GuiScreen gui) { + ifSizePresent(t -> t.render(customTexRes, renderPos, gui)); + } + + public void renderIfPresent(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final WidgetGui gui, final Consumer before) { + ifSizePresent(t -> before.andThen(t1 -> t.render(customTexRes, renderPos, gui)).accept(t)); + } + + public void renderIfPresent(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final GuiScreen gui, final Consumer before) { + ifSizePresent(t -> before.andThen(t1 -> t.render(customTexRes, renderPos, gui)).accept(t)); + } + + public void renderIfPresent(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final WidgetGui gui, @Nullable final Consumer before, @Nullable final Consumer after) { + ifPresent(t -> { + Optional.ofNullable(before).ifPresent(bc -> bc.accept(t)); + t.render(customTexRes, renderPos, gui); + Optional.ofNullable(after).ifPresent(ac -> ac.accept(t)); + }); + } + + public void renderIfPresent(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final GuiScreen gui, @Nullable final Consumer before, @Nullable final Consumer after) { + ifPresent(t -> { + Optional.ofNullable(before).ifPresent(bc -> bc.accept(t)); + t.render(customTexRes, renderPos, gui); + Optional.ofNullable(after).ifPresent(ac -> ac.accept(t)); + }); + } + + public void ifSizePresent(final Consumer runnable) { + if (width > 0 && height > 0) { + runnable.accept(this); + } + } + + // Custom texture and size render + + public void render(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final RenderSize renderSize, final WidgetGui gui) { + render(customTexRes, renderPos, renderSize, gui.getGui()); + } + + public void render(@Nullable final ResourceLocation customTexRes, final RenderPos renderPos, final RenderSize renderSize, final GuiScreen gui) { + TextureManager textureManager = gui.mc.getTextureManager(); + if (texRes != null) { + bind(textureManager); + } else { + bind(textureManager, Preconditions.checkNotNull(customTexRes, "texRes is null, but customTexRes is null too!")); + } + gui.drawTexturedModalRect(renderPos.posX(), renderPos.posY(), texX, texY, renderSize.width(), renderSize.height()); + } + + // Custom size render + + public void render(final RenderPos renderPos, final RenderSize renderSize, final WidgetGui gui) { + render(renderPos, renderSize, gui.getGui()); + } + + public void render(final RenderPos renderPos, final RenderSize renderSize, final GuiScreen gui) { + bind(gui.mc.getTextureManager()); + gui.drawTexturedModalRect(renderPos.posX(), renderPos.posY(), texX, texY, renderSize.width(), renderSize.height()); + } + + public void renderIfPresent(final RenderPos renderPos, final RenderSize renderSize, final WidgetGui gui) { + ifTexPresent(t -> t.render(renderPos, renderSize, gui)); + } + + public void renderIfPresent(final RenderPos renderPos, final RenderSize renderSize, final GuiScreen gui) { + ifTexPresent(t -> t.render(renderPos, renderSize, gui)); + } + + public void renderIfPresent(final RenderPos renderPos, final RenderSize renderSize, final WidgetGui gui, final Consumer before) { + ifTexPresent(t -> before.andThen(t1 -> t.render(renderPos, renderSize, gui)).accept(t)); + } + + public void renderIfPresent(final RenderPos renderPos, final RenderSize renderSize, final GuiScreen gui, final Consumer before) { + ifTexPresent(t -> before.andThen(t1 -> t.render(renderPos, renderSize, gui)).accept(t)); + } + + public void renderIfPresent(final RenderPos renderPos, final RenderSize renderSize, final WidgetGui gui, @Nullable final Consumer before, @Nullable final Consumer after) { + ifPresent(t -> { + Optional.ofNullable(before).ifPresent(bc -> bc.accept(t)); + t.render(renderPos, renderSize, gui); + Optional.ofNullable(after).ifPresent(ac -> ac.accept(t)); + }); + } + + public void renderIfPresent(final RenderPos renderPos, final RenderSize renderSize, final GuiScreen gui, @Nullable final Consumer before, @Nullable final Consumer after) { + ifPresent(t -> { + Optional.ofNullable(before).ifPresent(bc -> bc.accept(t)); + t.render(renderPos, renderSize, gui); + Optional.ofNullable(after).ifPresent(ac -> ac.accept(t)); + }); + } + + public void ifTexPresent(final Consumer runnable) { + if (texRes != null) { + runnable.accept(this); + } + } + +} diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/Button.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/Button.java index fcf21a24..114dd877 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/Button.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/Button.java @@ -3,11 +3,13 @@ import github.kasuminova.mmce.client.gui.util.MousePos; import github.kasuminova.mmce.client.gui.util.RenderPos; import github.kasuminova.mmce.client.gui.util.RenderSize; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.base.DynamicWidget; import github.kasuminova.mmce.client.gui.widget.base.WidgetGui; import net.minecraft.util.ResourceLocation; import java.util.List; +import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; @@ -18,15 +20,9 @@ public class Button extends DynamicWidget { protected ResourceLocation textureLocation = null; - - protected int textureX = 0; - protected int textureY = 0; - - protected int hoveredTextureX = 0; - protected int hoveredTextureY = 0; - - protected int unavailableTextureX = 0; - protected int unavailableTextureY = 0; + protected TextureProperties texture = TextureProperties.EMPTY; + protected TextureProperties hoveredTexture = TextureProperties.EMPTY; + protected TextureProperties unavailableTexture= TextureProperties.EMPTY; protected boolean available = true; @@ -35,25 +31,18 @@ public class Button extends DynamicWidget { @Override public void render(final WidgetGui gui, final RenderSize renderSize, final RenderPos renderPos, final MousePos mousePos) { - if (isVisible() && textureLocation != null) { - int texX; - int texY; - - if (isUnavailable()) { - texX = unavailableTextureX; - texY = unavailableTextureY; - } else if (isMouseOver(mousePos)) { - texX = hoveredTextureX; - texY = hoveredTextureY; - } else { - texX = textureX; - texY = textureY; - } - - gui.getGui().mc.getTextureManager().bindTexture(textureLocation); - - gui.getGui().drawTexturedModalRect(renderPos.posX(), renderPos.posY(), texX, texY, width, height); + if (!isVisible()) { + return; } + if (isUnavailable()) { + unavailableTexture.render(textureLocation, renderPos, renderSize, gui); + return; + } + if (isMouseOver(mousePos)) { + hoveredTexture.render(textureLocation, renderPos, renderSize, gui); + return; + } + texture.render(textureLocation, renderPos, renderSize, gui); } @Override @@ -86,75 +75,42 @@ public Button setTextureLocation(final ResourceLocation textureLocation) { return this; } - public int getTextureX() { - return textureX; - } - - public Button setTextureX(final int textureX) { - this.textureX = textureX; - return this; - } - - public int getTextureY() { - return textureY; + public Button setTexture(final int textureX, final int textureY) { + return setTexture(TextureProperties.of(textureX, textureY)); } - public Button setTextureY(final int textureY) { - this.textureY = textureY; - return this; + public Button setHoveredTexture(final int hoveredTextureX, final int hoveredTextureY) { + return setHoveredTexture(TextureProperties.of(hoveredTextureX, hoveredTextureY)); } - public Button setTextureXY(final int textureX, final int textureY) { - this.textureX = textureX; - this.textureY = textureY; - return this; + public Button setUnavailableTexture(final int unavailableTextureX, final int unavailableTextureY) { + return setUnavailableTexture(TextureProperties.of(unavailableTextureX, unavailableTextureY)); } - public int getHoveredTextureX() { - return hoveredTextureX; + public TextureProperties getTexture() { + return texture; } - public Button setHoveredTextureX(final int hoveredTextureX) { - this.hoveredTextureX = hoveredTextureX; + public Button setTexture(final TextureProperties texture) { + this.texture = Optional.ofNullable(texture).orElse(TextureProperties.EMPTY); return this; } - public int getHoveredTextureY() { - return hoveredTextureY; + public TextureProperties getHoveredTexture() { + return hoveredTexture; } - public Button setHoveredTextureY(final int hoveredTextureY) { - this.hoveredTextureY = hoveredTextureY; + public Button setHoveredTexture(final TextureProperties hoveredTexture) { + this.hoveredTexture = Optional.ofNullable(hoveredTexture).orElse(TextureProperties.EMPTY); return this; } - public Button setHoveredTextureXY(final int hoveredTextureX, final int hoveredTextureY) { - this.hoveredTextureX = hoveredTextureX; - this.hoveredTextureY = hoveredTextureY; - return this; - } - - public int getUnavailableTextureX() { - return unavailableTextureX; - } - - public Button setUnavailableTextureX(final int unavailableTextureX) { - this.unavailableTextureX = unavailableTextureX; - return this; - } - - public int getUnavailableTextureY() { - return unavailableTextureY; - } - - public Button setUnavailableTextureY(final int unavailableTextureY) { - this.unavailableTextureY = unavailableTextureY; - return this; + public TextureProperties getUnavailableTexture() { + return unavailableTexture; } - public Button setUnavailableTextureXY(final int unavailableTextureX, final int unavailableTextureY) { - this.unavailableTextureX = unavailableTextureX; - this.unavailableTextureY = unavailableTextureY; + public Button setUnavailableTexture(final TextureProperties unavailableTexture) { + this.unavailableTexture = Optional.ofNullable(unavailableTexture).orElse(TextureProperties.EMPTY); return this; } diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/Button4State.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/Button4State.java index d071da32..83b6ae74 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/Button4State.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/Button4State.java @@ -3,10 +3,12 @@ import github.kasuminova.mmce.client.gui.util.MousePos; import github.kasuminova.mmce.client.gui.util.RenderPos; import github.kasuminova.mmce.client.gui.util.RenderSize; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.base.WidgetGui; import java.util.Collections; import java.util.List; +import java.util.Optional; /** * Inherits the normal button with an additional press state. @@ -14,36 +16,28 @@ @SuppressWarnings("unused") public class Button4State extends Button { - protected int mouseDownTextureX = 0; - protected int mouseDownTextureY = 0; + protected TextureProperties mouseDownTexture = TextureProperties.EMPTY; protected boolean mouseDown = false; @Override public void render(final WidgetGui gui, final RenderSize renderSize, final RenderPos renderPos, final MousePos mousePos) { - if (!isVisible() || textureLocation == null) { + if (!isVisible()) { return; } - - int texX; - int texY; - if (isUnavailable()) { - texX = unavailableTextureX; - texY = unavailableTextureY; - } else if (mouseDown) { - texX = mouseDownTextureX; - texY = mouseDownTextureY; - } else if (isMouseOver(mousePos)) { - texX = hoveredTextureX; - texY = hoveredTextureY; - } else { - texX = textureX; - texY = textureY; + unavailableTexture.render(textureLocation, renderPos, renderSize, gui); + return; } - - gui.getGui().mc.getTextureManager().bindTexture(textureLocation); - gui.getGui().drawTexturedModalRect(renderPos.posX(), renderPos.posY(), texX, texY, width, height); + if (mouseDown) { + mouseDownTexture.render(textureLocation, renderPos, renderSize, gui); + return; + } + if (isMouseOver(mousePos)) { + hoveredTexture.render(textureLocation, renderPos, renderSize, gui); + return; + } + texture.render(textureLocation, renderPos, renderSize, gui); } @Override @@ -75,27 +69,21 @@ public List getHoverTooltips(final WidgetGui widgetGui, final MousePos m return super.getHoverTooltips(widgetGui, mousePos); } - public Button4State setMouseDownTextureXY(final int mouseDownTextureX, final int mouseDownTextureY) { - this.mouseDownTextureX = mouseDownTextureX; - this.mouseDownTextureY = mouseDownTextureY; - return this; + public Button4State setMouseDownTexture(final int mouseDownTextureX, final int mouseDownTextureY) { + return setMouseDownTexture(TextureProperties.of(mouseDownTextureX, mouseDownTextureY)); } - public int getMouseDownTextureX() { - return mouseDownTextureX; + public TextureProperties getMouseDownTexture() { + return mouseDownTexture; } - public Button4State setMouseDownTextureX(final int mouseDownTextureX) { - this.mouseDownTextureX = mouseDownTextureX; + public Button4State setMouseDownTexture(final TextureProperties mouseDownTexture) { + this.mouseDownTexture = Optional.ofNullable(mouseDownTexture).orElse(TextureProperties.EMPTY); return this; } - public int getMouseDownTextureY() { - return mouseDownTextureY; + public boolean isMouseDown() { + return mouseDown; } - public Button4State setMouseDownTextureY(final int mouseDownTextureY) { - this.mouseDownTextureY = mouseDownTextureY; - return this; - } } diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/Button5State.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/Button5State.java index 51dbca6f..c766a580 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/Button5State.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/Button5State.java @@ -3,10 +3,10 @@ import github.kasuminova.mmce.client.gui.util.MousePos; import github.kasuminova.mmce.client.gui.util.RenderPos; import github.kasuminova.mmce.client.gui.util.RenderSize; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.base.WidgetGui; -import java.util.Collections; -import java.util.List; +import java.util.Optional; /** * Inherits the 4 states of the button with the addition of a persistent press state. @@ -14,39 +14,32 @@ @SuppressWarnings("unused") public class Button5State extends Button4State { - protected int clickedTextureX = 0; - protected int clickedTextureY = 0; + protected TextureProperties clickedTexture = TextureProperties.EMPTY; protected boolean clicked = false; @Override public void render(final WidgetGui gui, final RenderSize renderSize, final RenderPos renderPos, final MousePos mousePos) { - if (!isVisible() || textureLocation == null) { + if (!isVisible()) { return; } - - int texX; - int texY; - if (isUnavailable()) { - texX = unavailableTextureX; - texY = unavailableTextureY; - } else if (clicked) { - texX = clickedTextureX; - texY = clickedTextureY; - } else if (mouseDown) { - texX = mouseDownTextureX; - texY = mouseDownTextureY; - } else if (isMouseOver(mousePos)) { - texX = hoveredTextureX; - texY = hoveredTextureY; - } else { - texX = textureX; - texY = textureY; + unavailableTexture.render(textureLocation, renderPos, renderSize, gui); + return; } - - gui.getGui().mc.getTextureManager().bindTexture(textureLocation); - gui.getGui().drawTexturedModalRect(renderPos.posX(), renderPos.posY(), texX, texY, width, height); + if (clicked) { + clickedTexture.render(textureLocation, renderPos, renderSize, gui); + return; + } + if (mouseDown) { + mouseDownTexture.render(textureLocation, renderPos, renderSize, gui); + return; + } + if (isMouseOver(mousePos)) { + hoveredTexture.render(textureLocation, renderPos, renderSize, gui); + return; + } + texture.render(textureLocation, renderPos, renderSize, gui); } @Override @@ -63,27 +56,16 @@ public boolean onMouseReleased(final MousePos mousePos, final RenderPos renderPo return false; } - public Button5State setClickedTextureXY(final int clickedTextureX, final int clickedTextureY) { - this.clickedTextureX = clickedTextureX; - this.clickedTextureY = clickedTextureY; - return this; - } - - public int getClickedTextureX() { - return clickedTextureX; - } - - public Button5State setClickedTextureX(final int clickedTextureX) { - this.clickedTextureX = clickedTextureX; - return this; + public Button5State setClickedTexture(final int clickedTextureX, final int clickedTextureY) { + return setClickedTexture(TextureProperties.of(clickedTextureX, clickedTextureY)); } - public int getClickedTextureY() { - return clickedTextureY; + public TextureProperties getClickedTexture() { + return clickedTexture; } - public Button5State setClickedTextureY(final int clickedTextureY) { - this.clickedTextureY = clickedTextureY; + public Button5State setClickedTexture(final TextureProperties clickedTexture) { + this.clickedTexture = Optional.ofNullable(clickedTexture).orElse(TextureProperties.EMPTY);; return this; } diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/ButtonElements.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/ButtonElements.java index 3962d6d5..7e259272 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/ButtonElements.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/ButtonElements.java @@ -3,9 +3,9 @@ import github.kasuminova.mmce.client.gui.util.MousePos; import github.kasuminova.mmce.client.gui.util.RenderPos; import github.kasuminova.mmce.client.gui.util.RenderSize; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.base.WidgetGui; import it.unimi.dsi.fastutil.objects.ObjectArrayList; -import net.minecraft.util.ResourceLocation; import java.util.List; import java.util.stream.IntStream; @@ -19,7 +19,7 @@ public class ButtonElements extends Button4State { @Override public void render(final WidgetGui gui, final RenderSize renderSize, final RenderPos renderPos, final MousePos mousePos) { super.render(gui, renderSize, renderPos, mousePos); - if (!isVisible() || textureLocation == null) { + if (!isVisible()) { return; } @@ -28,8 +28,7 @@ public void render(final WidgetGui gui, final RenderSize renderSize, final Rende return; } - gui.getGui().mc.getTextureManager().bindTexture(current.textureLocation()); - gui.getGui().drawTexturedModalRect(renderPos.posX(), renderPos.posY(), current.texX(), current.texY(), width, height); + current.texture().render(textureLocation, renderPos, renderSize, gui); } @Override @@ -69,8 +68,8 @@ public E getCurrentSelection() { return current == null ? null : current.element(); } - public ButtonElements addElement(final E element, final int textureX, final int textureY, final ResourceLocation textureLocation) { - elements.add(new ElementInfo(element, textureX, textureY, textureLocation)); + public ButtonElements addElement(final E element, final TextureProperties texture) { + elements.add(new ElementInfo(element, texture)); return this; } @@ -83,32 +82,23 @@ public ButtonElements setCurrentSelection(final E element) { } public final class ElementInfo { + private final E element; - private final int texX; - private final int texY; - private final ResourceLocation textureLocation; + private final TextureProperties texture; - public ElementInfo(E element, int texX, int texY, ResourceLocation textureLocation) { + public ElementInfo(E element, final TextureProperties texture) { this.element = element; - this.texX = texX; - this.texY = texY; - this.textureLocation = textureLocation; + this.texture = texture; } public E element() { return element; } - public int texX() { - return texX; - } - - public int texY() { - return texY; + public TextureProperties texture() { + return texture; } - public ResourceLocation textureLocation() { - return textureLocation; - } } + } diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/patternprovider/PatternProviderIngredientList.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/patternprovider/PatternProviderIngredientList.java index 1aea661a..226e783b 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/patternprovider/PatternProviderIngredientList.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/patternprovider/PatternProviderIngredientList.java @@ -1,6 +1,7 @@ package github.kasuminova.mmce.client.gui.widget.impl.patternprovider; import github.kasuminova.mmce.client.gui.GuiMEPatternProvider; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.base.WidgetGui; import github.kasuminova.mmce.client.gui.widget.container.Row; import github.kasuminova.mmce.client.gui.widget.impl.preview.IngredientList; @@ -25,10 +26,10 @@ public void initWidget(final WidgetGui gui) { scrollbar.setMargin(5, 1, 1, 1); scrollbar.setWidthHeight(9, 124); scrollbar.getScroll() - .setMouseDownTextureXY(198, 232) - .setHoveredTextureXY(187, 232) - .setTextureXY(176, 232) - .setUnavailableTextureXY(209, 232) + .setMouseDownTexture(198, 232) + .setHoveredTexture(187, 232) + .setTexture(176, 232) + .setUnavailableTexture(209, 232) .setTextureLocation(GuiMEPatternProvider.GUI_TEXTURE) .setWidthHeight(9, 18); } @@ -71,7 +72,7 @@ private Row addGasSlots(final List gasList, Row row, int[] stackPerRow, final } protected static SlotVirtual initSlot(final SlotVirtual slot) { - return slot.setSlotTexLocation(GuiMEPatternProvider.GUI_TEXTURE).setSlotTexX(220).setSlotTexY(232); + return slot.setSlotTex(TextureProperties.of(GuiMEPatternProvider.GUI_TEXTURE, 220, 232)); } } diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/IngredientList.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/IngredientList.java index 36c346a5..d7496420 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/IngredientList.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/IngredientList.java @@ -1,5 +1,6 @@ package github.kasuminova.mmce.client.gui.widget.impl.preview; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.Scrollbar; import github.kasuminova.mmce.client.gui.widget.base.WidgetGui; import github.kasuminova.mmce.client.gui.widget.container.Row; @@ -35,10 +36,10 @@ public void initWidget(final WidgetGui gui) { scrollbar.setMargin(3, 1, 1, 1); scrollbar.setWidthHeight(8, 34); scrollbar.getScroll() - .setMouseDownTextureXY(204, 143) - .setHoveredTextureXY(194, 143) - .setTextureXY(184, 143) - .setUnavailableTextureXY(214, 143) + .setMouseDownTexture(204, 143) + .setHoveredTexture(194, 143) + .setTexture(184, 143) + .setUnavailableTexture(214, 143) .setTextureLocation(WIDGETS_TEX_LOCATION) .setWidthHeight(8, 13); } @@ -56,8 +57,7 @@ public IngredientList setStackList(final List list, List for (int i = 0; i < list.size(); i++) { final ItemStack stack = list.get(i); row.addWidget(SlotItemVirtual.ofJEI(stack) - .setSlotTexLocation(WIDGETS_TEX_LOCATION) - .setSlotTexX(184).setSlotTexY(194) + .setSlotTex(TextureProperties.of(WIDGETS_TEX_LOCATION, 184, 194)) ); stackPerRow++; if (stackPerRow >= maxStackPerRow && i + 1 < totalSize) { @@ -69,8 +69,7 @@ public IngredientList setStackList(final List list, List for (int i = 0; i < fluidList.size(); i++) { final FluidStack stack = fluidList.get(i); row.addWidget(SlotFluidVirtual.ofJEI(stack) - .setSlotTexLocation(WIDGETS_TEX_LOCATION) - .setSlotTexX(184).setSlotTexY(194) + .setSlotTex(TextureProperties.of(WIDGETS_TEX_LOCATION, 184, 194)) ); stackPerRow++; if (stackPerRow >= maxStackPerRow && i + 1 < totalSize) { diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/IngredientListVertical.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/IngredientListVertical.java index 7f7044df..0e1ebbdf 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/IngredientListVertical.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/IngredientListVertical.java @@ -32,10 +32,10 @@ public void initWidget(final WidgetGui gui) { scrollbar.setMargin(1, 1, 1, 1); scrollbar.setWidthHeight(6, 124); scrollbar.getScroll() - .setMouseDownTextureXY(200, 175) - .setHoveredTextureXY(192, 175) - .setTextureXY(184, 175) - .setUnavailableTextureXY(208, 175) + .setMouseDownTexture(200, 175) + .setHoveredTexture(192, 175) + .setTexture(184, 175) + .setUnavailableTexture(208, 175) .setTextureLocation(MachineStructurePreviewPanel.WIDGETS_TEX_LOCATION) .setWidthHeight(6, 17); checkScrollbarRange(); diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/LayerRenderScrollbar.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/LayerRenderScrollbar.java index cb6832d1..23289c0d 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/LayerRenderScrollbar.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/LayerRenderScrollbar.java @@ -29,10 +29,10 @@ public LayerRenderScrollbar(final WorldSceneRendererWidget renderer) { Button4State up = new Button4State(); Button4State down = new Button4State(); - up.setMouseDownTextureXY(184 + 11 + 11, 121) - .setHoveredTextureXY(184 + 11, 121) - .setTextureXY(184, 121) - .setUnavailableTextureXY(184 + 11 + 11 + 11, 121) + up.setMouseDownTexture(184 + 11 + 11, 121) + .setHoveredTexture(184 + 11, 121) + .setTexture(184, 121) + .setUnavailableTexture(184 + 11 + 11 + 11, 121) .setTextureLocation(MachineStructurePreviewPanel.WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> { int minY = renderer.getPattern().getMin().getY(); @@ -45,10 +45,10 @@ public LayerRenderScrollbar(final WorldSceneRendererWidget renderer) { ); }) .setWidthHeight(9, 9); - down.setMouseDownTextureXY(184 + 11 + 11, 132) - .setHoveredTextureXY(184 + 11, 132) - .setTextureXY(184, 132) - .setUnavailableTextureXY(184 + 11 + 11 + 11, 132) + down.setMouseDownTexture(184 + 11 + 11, 132) + .setHoveredTexture(184 + 11, 132) + .setTexture(184, 132) + .setUnavailableTexture(184 + 11 + 11 + 11, 132) .setTextureLocation(MachineStructurePreviewPanel.WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> { int minY = renderer.getPattern().getMin().getY(); @@ -62,10 +62,10 @@ public LayerRenderScrollbar(final WorldSceneRendererWidget renderer) { }) .setWidthHeight(9, 9); scrollbar.getScroll() - .setMouseDownTextureXY(202, 158) - .setHoveredTextureXY(193, 158) - .setTextureXY(184, 158) - .setUnavailableTextureXY(211, 158) + .setMouseDownTexture(202, 158) + .setHoveredTexture(193, 158) + .setTexture(184, 158) + .setUnavailableTexture(211, 158) .setTextureLocation(MachineStructurePreviewPanel.WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> { int minY = renderer.getPattern().getMin().getY(); diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/MachineStructurePreviewPanel.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/MachineStructurePreviewPanel.java index c5a436bd..cfd4749f 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/MachineStructurePreviewPanel.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/impl/preview/MachineStructurePreviewPanel.java @@ -1,5 +1,6 @@ package github.kasuminova.mmce.client.gui.widget.impl.preview; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.Button; import github.kasuminova.mmce.client.gui.widget.Button4State; import github.kasuminova.mmce.client.gui.widget.Button5State; @@ -98,35 +99,35 @@ public MachineStructurePreviewPanel(final DynamicMachine machine) { previewStatusBar.setMaxWidth(172) .setAbsXY(6, 26); - menuBtn.setClickedTextureXY(184 + 15 + 15, 15) - .setMouseDownTextureXY(184 + 15 + 15, 15) - .setHoveredTextureXY(184 + 15, 15) - .setTextureXY(184, 15) + menuBtn.setClickedTexture(184 + 15 + 15, 15) + .setMouseDownTexture(184 + 15 + 15, 15) + .setHoveredTexture(184 + 15, 15) + .setTexture(184, 15) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> Collections.singletonList(I18n.format( "gui.preview.button.menu.tip"))) .setWidthHeight(13, 13); - toggleLayerRender.setClickedTextureXY(184 + 15 + 15 + 15, 30) - .setMouseDownTextureXY(184 + 15 + 15, 30) - .setHoveredTextureXY(184 + 15, 30) - .setTextureXY(184, 30) + toggleLayerRender.setClickedTexture(184 + 15 + 15 + 15, 30) + .setMouseDownTexture(184 + 15 + 15, 30) + .setHoveredTexture(184 + 15, 30) + .setTexture(184, 30) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> toggleLayerRender.isClicked() ? Collections.singletonList(I18n.format("gui.preview.button.toggle_3d_render.tip")) : Collections.singletonList(I18n.format("gui.preview.button.toggle_layer_render.tip"))) .setWidthHeight(13, 13); placeWorldPreview - .setMouseDownTextureXY(184 + 15 + 15, 45) - .setHoveredTextureXY(184 + 15, 45) - .setTextureXY(184, 45) + .setMouseDownTexture(184 + 15 + 15, 45) + .setHoveredTexture(184 + 15, 45) + .setTexture(184, 45) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> Collections.singletonList(I18n.format( "gui.preview.button.place_world_preview.tip"))) .setWidthHeight(13, 13); - enableCycleReplaceableBlocks.setClickedTextureXY(184 + 15 + 15, 105) - .setMouseDownTextureXY(184 + 15 + 15, 105) - .setHoveredTextureXY(184 + 15, 105) - .setTextureXY(184, 105) + enableCycleReplaceableBlocks.setClickedTexture(184 + 15 + 15, 105) + .setMouseDownTexture(184 + 15 + 15, 105) + .setHoveredTexture(184 + 15, 105) + .setTexture(184, 105) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> enableCycleReplaceableBlocks.isClicked() ? Collections.singletonList(I18n.format("gui.preview.button.disable_cycle_replaceable_blocks.tip")) @@ -135,56 +136,56 @@ public MachineStructurePreviewPanel(final DynamicMachine machine) { I18n.format("gui.preview.button.enable_cycle_replaceable_blocks.tip.1"))) .setWidthHeight(13, 13); dynamicPatternPlus - .setMouseDownTextureXY(184 + 15 + 15, 60) - .setHoveredTextureXY(184 + 15, 60) - .setTextureXY(184, 60) + .setMouseDownTexture(184 + 15 + 15, 60) + .setHoveredTexture(184 + 15, 60) + .setTexture(184, 60) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> Collections.singletonList(I18n.format( "gui.preview.button.dynamic_pattern_plus.tip", renderer.getDynamicPatternSize()))) .setWidthHeight(13, 13); dynamicPatternSubtract - .setMouseDownTextureXY(184 + 15 + 15, 75) - .setHoveredTextureXY(184 + 15, 75) - .setTextureXY(184, 75) + .setMouseDownTexture(184 + 15 + 15, 75) + .setHoveredTexture(184 + 15, 75) + .setTexture(184, 75) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> Collections.singletonList(I18n.format( "gui.preview.button.dynamic_pattern_subtract.tip", renderer.getDynamicPatternSize()))) .setWidthHeight(13, 13); - machineExtraInfo.setHoveredTextureXY(184 + 15, 214) - .setTextureXY(184, 214) + machineExtraInfo.setHoveredTexture(184 + 15, 214) + .setTexture(184, 214) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> getMachineExtraInfo(machine)) .setWidthHeight(13, 13); - toggleFormed.setClickedTextureXY(184 + 15 + 15 + 15, 0) - .setMouseDownTextureXY(184 + 15 + 15, 0) - .setHoveredTextureXY(184 + 15, 0) - .setTextureXY(184, 0) + toggleFormed.setClickedTexture(184 + 15 + 15 + 15, 0) + .setMouseDownTexture(184 + 15 + 15, 0) + .setHoveredTexture(184 + 15, 0) + .setTexture(184, 0) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> toggleFormed.isClicked() ? Collections.singletonList(I18n.format("gui.preview.button.toggle_unformed.tip")) : Collections.singletonList(I18n.format("gui.preview.button.toggle_formed.tip"))) .setWidthHeight(13, 13); - showUpgrades.setClickedTextureXY(184 + 15 + 15, 90) - .setMouseDownTextureXY(184 + 15 + 15, 90) - .setHoveredTextureXY(184 + 15, 90) - .setTextureXY(184, 90) + showUpgrades.setClickedTexture(184 + 15 + 15, 90) + .setMouseDownTexture(184 + 15 + 15, 90) + .setHoveredTexture(184 + 15, 90) + .setTexture(184, 90) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> showUpgrades.isClicked() ? Collections.singletonList(I18n.format("gui.preview.button.toggle_upgrade_display.disable.tip")) : Collections.singletonList(I18n.format("gui.preview.button.toggle_upgrade_display.enable.tip"))) .setWidthHeight(13, 13); - resetCenter.setMouseDownTextureXY(184 + 15 + 15, 229) - .setHoveredTextureXY(184 + 15, 229) - .setTextureXY(184, 229) + resetCenter.setMouseDownTexture(184 + 15 + 15, 229) + .setHoveredTexture(184 + 15, 229) + .setTexture(184, 229) .setTextureLocation(WIDGETS_TEX_LOCATION) .setTooltipFunction(btn -> Collections.singletonList(I18n.format("gui.preview.button.reset_center.tip"))) .setWidthHeight(13, 13); ingredientList.setAbsXY(5, 179); - selectedBlockIngredientMain.setSlotTexX(229).setSlotTexY(105) - .setSlotTexLocation(WIDGETS_TEX_LOCATION) + selectedBlockIngredientMain + .setSlotTex(TextureProperties.of(WIDGETS_TEX_LOCATION, 229, 105)) .setAbsXY(8, 28); selectedBlockIngredientList.setAbsXY(8, 48); diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotFluidVirtual.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotFluidVirtual.java index 5b31e6c9..9395f0e5 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotFluidVirtual.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotFluidVirtual.java @@ -51,12 +51,10 @@ public void render(final WidgetGui gui, final RenderSize renderSize, final Rende int rx = renderPos.posX(); int ry = renderPos.posY(); - if (slotTexLocation != null) { + slotTex.renderIfPresent(renderPos, renderSize, gui, (tex) -> { GlStateManager.enableBlend(); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - mc.getTextureManager().bindTexture(slotTexLocation); - gui.getGui().drawTexturedModalRect(rx, ry, slotTexX, slotTexY, getWidth(), getHeight()); - } + }); if (fluidStack != null && fluidStack.amount > 0) { int fluidColor = fluidStack.getFluid().getColor(fluidStack); diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotGasVirtual.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotGasVirtual.java index cbbe2f01..18c3728e 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotGasVirtual.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotGasVirtual.java @@ -51,12 +51,10 @@ public void render(final WidgetGui gui, final RenderSize renderSize, final Rende int rx = renderPos.posX(); int ry = renderPos.posY(); - if (slotTexLocation != null) { + slotTex.renderIfPresent(renderPos, renderSize, gui, (tex) -> { GlStateManager.enableBlend(); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - mc.getTextureManager().bindTexture(slotTexLocation); - gui.getGui().drawTexturedModalRect(rx, ry, slotTexX, slotTexY, getWidth(), getHeight()); - } + }); if (gasStack != null && gasStack.amount > 0) { int fluidColor = gasStack.getGas().getTint(); diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotItemVirtual.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotItemVirtual.java index 7ae73d48..05c88083 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotItemVirtual.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotItemVirtual.java @@ -69,12 +69,10 @@ public void render(final WidgetGui widgetGui, final RenderSize renderSize, final int rx = renderPos.posX(); int ry = renderPos.posY(); - if (slotTexLocation != null) { + slotTex.renderIfPresent(renderPos, renderSize, gui, (tex) -> { GlStateManager.enableBlend(); GlStateManager.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); - mc.getTextureManager().bindTexture(slotTexLocation); - gui.drawTexturedModalRect(rx, ry, slotTexX, slotTexY, getWidth(), getHeight()); - } + }); if (stackInSlot.isEmpty()) { return; diff --git a/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotVirtual.java b/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotVirtual.java index f05277e4..9ab31940 100644 --- a/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotVirtual.java +++ b/src/main/java/github/kasuminova/mmce/client/gui/widget/slot/SlotVirtual.java @@ -1,18 +1,17 @@ package github.kasuminova.mmce.client.gui.widget.slot; import github.kasuminova.mmce.client.gui.util.MousePos; +import github.kasuminova.mmce.client.gui.util.TextureProperties; import github.kasuminova.mmce.client.gui.widget.base.DynamicWidget; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.util.ResourceLocation; import java.awt.*; +import java.util.Optional; public abstract class SlotVirtual extends DynamicWidget { - protected ResourceLocation slotTexLocation = null; - protected int slotTexX = 0; - protected int slotTexY = 0; + protected TextureProperties slotTex = TextureProperties.EMPTY; protected boolean mouseOver = false; @@ -34,18 +33,12 @@ protected void drawHoverOverlay(final MousePos mousePos, final int rx, final int // Texture Location. - public SlotVirtual setSlotTexLocation(final ResourceLocation slotTexLocation) { - this.slotTexLocation = slotTexLocation; - return this; - } - - public SlotVirtual setSlotTexX(final int slotTexX) { - this.slotTexX = slotTexX; - return this; + public TextureProperties getSlotTex() { + return slotTex; } - public SlotVirtual setSlotTexY(final int slotTexY) { - this.slotTexY = slotTexY; + public SlotVirtual setSlotTex(final TextureProperties slotTex) { + this.slotTex = Optional.ofNullable(slotTex).orElse(TextureProperties.EMPTY); return this; } diff --git a/src/main/java/github/kasuminova/mmce/common/tile/MEPatternProvider.java b/src/main/java/github/kasuminova/mmce/common/tile/MEPatternProvider.java index e4b46194..e0b62c71 100644 --- a/src/main/java/github/kasuminova/mmce/common/tile/MEPatternProvider.java +++ b/src/main/java/github/kasuminova/mmce/common/tile/MEPatternProvider.java @@ -222,7 +222,7 @@ protected void refreshPattern(final int slot) { } ICraftingPatternDetails detail = patternItem.getPatternForItem(pattern, getWorld()); - if (detail != null) { + if (detail != null && !detail.isCraftable()) { details.set(slot, detail); } } diff --git a/src/main/java/github/kasuminova/mmce/common/world/MMWorldEventListener.java b/src/main/java/github/kasuminova/mmce/common/world/MMWorldEventListener.java index a6e0b443..3033d5d6 100644 --- a/src/main/java/github/kasuminova/mmce/common/world/MMWorldEventListener.java +++ b/src/main/java/github/kasuminova/mmce/common/world/MMWorldEventListener.java @@ -1,6 +1,7 @@ package github.kasuminova.mmce.common.world; import github.kasuminova.mmce.client.world.BlockModelHider; +import it.unimi.dsi.fastutil.Function; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import net.minecraft.block.state.IBlockState; @@ -55,12 +56,12 @@ public void onWorldUnloaded(WorldEvent.Unload event) { } @SubscribeEvent - public void onWorldTickStart(TickEvent.WorldTickEvent event) { + public void onServerTickStart(TickEvent.ServerTickEvent event) { if (event.side != Side.SERVER || event.phase != TickEvent.Phase.START) { return; } - worldChangedChunks.put(event.world, new Long2ObjectOpenHashMap<>()); + worldChangedChunks.values().forEach(Function::clear); } @SubscribeEvent