From ad350507c9cc04046f4e8cbfb61ee99fdb8aedaa Mon Sep 17 00:00:00 2001 From: PepperBell <44146161+PepperCode1@users.noreply.github.com> Date: Sun, 14 Nov 2021 16:11:14 -0800 Subject: [PATCH] The great screen refactor - Use vanilla's widget lists instead of custom ones - Use press callback instead of overriding mouseClicked - Switch old container classes to extend ContainerBase or GhostItemContainer - Organize foundation.gui package - Remove deprecated methods in Color - Various other changes --- .../com/simibubi/create/CreateClient.java | 2 - .../simibubi/create/compat/jei/CreateJEI.java | 18 +- .../create/compat/jei/DoubleItemIcon.java | 2 +- .../compat/jei/GhostIngredientHandler.java | 6 +- .../simibubi/create/compat/jei/SlotMover.java | 3 +- .../compat/jei/category/BasinCategory.java | 10 +- .../jei/category/BlockCuttingCategory.java | 8 +- .../compat/jei/category/CrushingCategory.java | 6 +- .../jei/category/DeployingCategory.java | 10 +- .../jei/category/FanBlastingCategory.java | 2 +- .../jei/category/FanSmokingCategory.java | 2 +- .../jei/category/FanWashingCategory.java | 14 +- .../jei/category/ItemDrainCategory.java | 10 +- .../category/MechanicalCraftingCategory.java | 6 +- .../compat/jei/category/MillingCategory.java | 10 +- .../MysteriousItemConversionCategory.java | 8 +- .../compat/jei/category/PackingCategory.java | 8 +- .../jei/category/PolishingCategory.java | 10 +- .../compat/jei/category/PressingCategory.java | 10 +- .../category/ProcessingViaFanCategory.java | 10 +- .../compat/jei/category/SawingCategory.java | 8 +- .../category/SequencedAssemblyCategory.java | 10 +- .../compat/jei/category/SpoutCategory.java | 10 +- .../category/animations/AnimatedCrafter.java | 2 +- .../category/animations/AnimatedKinetics.java | 2 +- .../animations/AnimatedMillstone.java | 2 +- .../SequencedAssemblySubCategory.java | 4 +- .../clock/CuckooClockTileEntity.java | 4 +- .../crafter/MechanicalCraftingInventory.java | 2 +- .../flywheel/FlywheelTileEntity.java | 2 +- .../MountedFluidStorage.java | 2 +- .../fluids/particle/FluidStackParticle.java | 5 +- .../fluids/tank/FluidTankRenderer.java | 2 +- .../fluids/tank/FluidTankTileEntity.java | 2 +- .../goggles/GoggleConfigScreen.java | 2 +- .../goggles/GoggleOverlayRenderer.java | 2 +- .../processing/InWorldProcessing.java | 2 +- .../sequencer/SequencedGearshiftScreen.java | 36 ++- .../contraptions/relays/gauge/GaugeBlock.java | 2 +- .../armor/CopperBacktankArmorLayer.java | 2 +- .../symmetry/SymmetryWandScreen.java | 38 ++-- .../toolbox/RadialToolboxMenu.java | 36 +-- .../curiosities/toolbox/ToolboxContainer.java | 14 +- .../toolbox/ToolboxHandlerClient.java | 2 +- .../curiosities/toolbox/ToolboxScreen.java | 87 ++++---- .../curiosities/tools/BlueprintContainer.java | 2 +- .../curiosities/tools/BlueprintEntity.java | 4 +- .../tools/BlueprintOverlayRenderer.java | 10 +- .../curiosities/tools/BlueprintScreen.java | 53 ++--- .../curiosities/zapper/ZapperScreen.java | 45 ++-- .../terrainzapper/WorldshaperScreen.java | 116 +++++----- .../belts/tunnel/BeltTunnelInstance.java | 2 +- .../belts/tunnel/BeltTunnelTileEntity.java | 2 +- .../block/chute/ChuteTileEntity.java | 2 +- .../block/depot/EjectorTargetHandler.java | 2 +- .../block/funnel/FunnelTileEntity.java | 2 +- .../inventories/AdjustableCrateContainer.java | 75 +++---- .../inventories/AdjustableCrateScreen.java | 23 +- .../block/mechanicalArm/ArmTileEntity.java | 2 +- .../block/redstone/AnalogLeverTileEntity.java | 2 +- .../block/redstone/StockpileSwitchScreen.java | 44 ++-- .../item/LinkedControllerContainer.java | 128 ++--------- .../item/LinkedControllerScreen.java | 49 ++--- .../item/filter/AbstractFilterContainer.java | 2 +- .../item/filter/AbstractFilterScreen.java | 86 ++++---- .../item/filter/AttributeFilterScreen.java | 87 ++++---- .../logistics/item/filter/FilterScreen.java | 63 +++--- .../block/SchematicTableContainer.java | 90 ++++---- .../block/SchematicTableScreen.java | 129 ++++++----- .../block/SchematicTableTileEntity.java | 2 +- .../block/SchematicannonContainer.java | 74 +++---- .../block/SchematicannonScreen.java | 164 +++++++------- .../client/SchematicEditScreen.java | 48 ++-- .../client/SchematicHotbarSlotOverlay.java | 2 +- .../client/SchematicPromptScreen.java | 50 ++--- .../client/SchematicTransformation.java | 4 +- .../packet/ConfigureSchematicannonPacket.java | 2 +- .../packet/SchematicUploadPacket.java | 2 +- .../config/ui/BaseConfigScreen.java | 22 +- .../config/ui/ConfigModListScreen.java | 24 +- .../foundation/config/ui/ConfigScreen.java | 15 +- .../config/ui/ConfigScreenList.java | 18 +- .../config/ui/OpenCreateMenuButton.java | 2 +- .../config/ui/SubMenuConfigScreen.java | 35 ++- .../config/ui/entries/BooleanEntry.java | 4 +- .../config/ui/entries/EnumEntry.java | 8 +- .../config/ui/entries/NumberEntry.java | 2 +- .../config/ui/entries/SubMenuEntry.java | 4 +- .../config/ui/entries/ValueEntry.java | 4 +- .../foundation/data/CreateEntityBuilder.java | 6 +- .../data/CreateTileEntityBuilder.java | 5 +- .../gui/AbstractSimiContainerScreen.java | 208 ------------------ .../foundation/gui/AbstractSimiScreen.java | 157 +++++-------- .../create/foundation/gui/AllGuiTextures.java | 184 ++++++++-------- .../create/foundation/gui/AllIcons.java | 76 ++++--- .../foundation/gui/ConfirmationScreen.java | 22 +- .../{mainMenu => }/CreateMainMenuScreen.java | 11 +- .../foundation/gui/IScreenRenderable.java | 20 -- .../simibubi/create/foundation/gui/Theme.java | 14 +- .../gui/TickableGuiEventListener.java | 7 + .../foundation/gui/ToolSelectionScreen.java | 9 +- .../AbstractSimiContainerScreen.java | 151 +++++++++++++ .../{ => container}/ClearContainerPacket.java | 2 +- .../gui/{ => container}/ContainerBase.java | 8 +- .../{ => container}/GhostItemContainer.java | 18 +- .../GhostItemSubmitPacket.java | 2 +- .../{ => container}/IClearableContainer.java | 2 +- .../gui/{ => element}/BoxElement.java | 2 +- .../{ => element}/CombinedStencilElement.java | 2 +- .../DelegatedStencilElement.java | 3 +- .../gui/{ => element}/GuiGameElement.java | 8 +- .../gui/{ => element}/RenderElement.java | 27 +-- .../foundation/gui/element/ScreenElement.java | 13 ++ .../gui/{ => element}/StencilElement.java | 2 +- .../gui/{ => element}/TextStencilElement.java | 2 +- .../AbstractSimiWidget.java | 30 ++- .../gui/{widgets => widget}/BoxWidget.java | 6 +- .../{widgets => widget}/ElementWidget.java | 8 +- .../gui/{widgets => widget}/IconButton.java | 26 +-- .../gui/{widgets => widget}/Indicator.java | 24 +- .../gui/{widgets => widget}/Label.java | 6 +- .../gui/{widgets => widget}/ScrollInput.java | 5 +- .../SelectionScrollInput.java | 2 +- .../foundation/networking/AllPackets.java | 4 +- .../ponder/NavigatableSimiScreen.java | 43 ++-- .../foundation/ponder/PonderProgressBar.java | 4 +- .../create/foundation/ponder/PonderUI.java | 53 +++-- .../foundation/ponder/SceneBuilder.java | 4 +- .../ponder/content/PonderChapter.java | 6 +- .../ponder/content/PonderIndexScreen.java | 22 +- .../foundation/ponder/content/PonderTag.java | 8 +- .../ponder/content/PonderTagIndexScreen.java | 26 ++- .../ponder/content/PonderTagScreen.java | 28 ++- .../ponder/elements/InputWindowElement.java | 4 +- .../ponder/elements/TextWindowElement.java | 2 +- .../foundation/ponder/ui/ChapterLabel.java | 2 +- .../foundation/ponder/ui/PonderButton.java | 8 +- .../tileEntity/SmartTileEntity.java | 2 +- .../tileEntity/behaviour/ValueBox.java | 2 +- .../create/foundation/utility/Color.java | 24 +- .../{gui => utility}/IInteractionChecker.java | 2 +- .../utility/ServerSpeedProvider.java | 2 +- .../animation}/InterpolatedAngle.java | 6 +- .../animation}/InterpolatedChasingAngle.java | 6 +- .../animation}/InterpolatedChasingValue.java | 6 +- .../animation}/InterpolatedValue.java | 6 +- .../utility/animation/LerpedFloat.java | 24 +- .../utility/placement/PlacementHelpers.java | 4 +- 148 files changed, 1454 insertions(+), 1853 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java rename src/main/java/com/simibubi/create/foundation/gui/{mainMenu => }/CreateMainMenuScreen.java (94%) delete mode 100644 src/main/java/com/simibubi/create/foundation/gui/IScreenRenderable.java create mode 100644 src/main/java/com/simibubi/create/foundation/gui/TickableGuiEventListener.java create mode 100644 src/main/java/com/simibubi/create/foundation/gui/container/AbstractSimiContainerScreen.java rename src/main/java/com/simibubi/create/foundation/gui/{ => container}/ClearContainerPacket.java (94%) rename src/main/java/com/simibubi/create/foundation/gui/{ => container}/ContainerBase.java (94%) rename src/main/java/com/simibubi/create/foundation/gui/{ => container}/GhostItemContainer.java (92%) rename src/main/java/com/simibubi/create/foundation/gui/{ => container}/GhostItemSubmitPacket.java (95%) rename src/main/java/com/simibubi/create/foundation/gui/{ => container}/IClearableContainer.java (81%) rename src/main/java/com/simibubi/create/foundation/gui/{ => element}/BoxElement.java (99%) rename src/main/java/com/simibubi/create/foundation/gui/{ => element}/CombinedStencilElement.java (97%) rename src/main/java/com/simibubi/create/foundation/gui/{ => element}/DelegatedStencilElement.java (93%) rename src/main/java/com/simibubi/create/foundation/gui/{ => element}/GuiGameElement.java (96%) rename src/main/java/com/simibubi/create/foundation/gui/{ => element}/RenderElement.java (66%) create mode 100644 src/main/java/com/simibubi/create/foundation/gui/element/ScreenElement.java rename src/main/java/com/simibubi/create/foundation/gui/{ => element}/StencilElement.java (96%) rename src/main/java/com/simibubi/create/foundation/gui/{ => element}/TextStencilElement.java (97%) rename src/main/java/com/simibubi/create/foundation/gui/{widgets => widget}/AbstractSimiWidget.java (83%) rename src/main/java/com/simibubi/create/foundation/gui/{widgets => widget}/BoxWidget.java (96%) rename src/main/java/com/simibubi/create/foundation/gui/{widgets => widget}/ElementWidget.java (94%) rename src/main/java/com/simibubi/create/foundation/gui/{widgets => widget}/IconButton.java (55%) rename src/main/java/com/simibubi/create/foundation/gui/{widgets => widget}/Indicator.java (89%) rename src/main/java/com/simibubi/create/foundation/gui/{widgets => widget}/Label.java (92%) rename src/main/java/com/simibubi/create/foundation/gui/{widgets => widget}/ScrollInput.java (97%) rename src/main/java/com/simibubi/create/foundation/gui/{widgets => widget}/SelectionScrollInput.java (97%) rename src/main/java/com/simibubi/create/foundation/{gui => utility}/IInteractionChecker.java (73%) rename src/main/java/com/simibubi/create/foundation/{gui/widgets => utility/animation}/InterpolatedAngle.java (67%) rename src/main/java/com/simibubi/create/foundation/{gui/widgets => utility/animation}/InterpolatedChasingAngle.java (75%) rename src/main/java/com/simibubi/create/foundation/{gui/widgets => utility/animation}/InterpolatedChasingValue.java (86%) rename src/main/java/com/simibubi/create/foundation/{gui/widgets => utility/animation}/InterpolatedValue.java (81%) diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 09a515768..633387202 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -25,7 +25,6 @@ import com.simibubi.create.foundation.utility.outliner.Outliner; import net.minecraft.ChatFormatting; import net.minecraft.client.GraphicsStatus; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.ChatType; import net.minecraft.network.chat.ClickEvent; import net.minecraft.network.chat.ComponentUtils; @@ -40,7 +39,6 @@ public class CreateClient { public static final SuperByteBufferCache BUFFER_CACHE = new SuperByteBufferCache(); public static final Outliner OUTLINER = new Outliner(); public static final GhostBlocks GHOST_BLOCKS = new GhostBlocks(); - public static final Screen EMPTY_SCREEN = new Screen(new TextComponent("")) {}; public static final ModelSwapper MODEL_SWAPPER = new ModelSwapper(); public static final CasingConnectivity CASING_CONNECTIVITY = new CasingConnectivity(); diff --git a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java index 9c5cccaa0..b0491fe78 100644 --- a/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java +++ b/src/main/java/com/simibubi/create/compat/jei/CreateJEI.java @@ -40,18 +40,13 @@ import com.simibubi.create.content.contraptions.components.press.MechanicalPress import com.simibubi.create.content.contraptions.components.saw.SawTileEntity; import com.simibubi.create.content.contraptions.fluids.recipe.PotionMixingRecipeManager; import com.simibubi.create.content.contraptions.processing.BasinRecipe; -import com.simibubi.create.content.curiosities.toolbox.ToolboxScreen; import com.simibubi.create.content.curiosities.tools.BlueprintScreen; -import com.simibubi.create.content.logistics.block.inventories.AdjustableCrateScreen; import com.simibubi.create.content.logistics.item.LinkedControllerScreen; import com.simibubi.create.content.logistics.item.filter.AbstractFilterScreen; -import com.simibubi.create.content.logistics.item.filter.AttributeFilterScreen; -import com.simibubi.create.content.logistics.item.filter.FilterScreen; -import com.simibubi.create.content.schematics.block.SchematicTableScreen; -import com.simibubi.create.content.schematics.block.SchematicannonScreen; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.CRecipes; import com.simibubi.create.foundation.config.ConfigBase.ConfigBool; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; import com.simibubi.create.foundation.utility.recipe.IRecipeTypeInfo; import mezz.jei.api.IModPlugin; @@ -247,18 +242,11 @@ public class CreateJEI implements IModPlugin { @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void registerGuiHandlers(IGuiHandlerRegistration registration) { - SlotMover slotMover = new SlotMover(); - registration.addGuiContainerHandler(SchematicTableScreen.class, slotMover); - registration.addGuiContainerHandler(SchematicannonScreen.class, slotMover); - registration.addGuiContainerHandler(AdjustableCrateScreen.class, slotMover); - registration.addGuiContainerHandler(FilterScreen.class, slotMover); - registration.addGuiContainerHandler(AttributeFilterScreen.class, slotMover); - registration.addGuiContainerHandler(BlueprintScreen.class, slotMover); - registration.addGuiContainerHandler(LinkedControllerScreen.class, slotMover); - registration.addGuiContainerHandler(ToolboxScreen.class, slotMover); + registration.addGenericGuiContainerHandler(AbstractSimiContainerScreen.class, new SlotMover()); registration.addGhostIngredientHandler(AbstractFilterScreen.class, new GhostIngredientHandler()); registration.addGhostIngredientHandler(BlueprintScreen.class, new GhostIngredientHandler()); + registration.addGhostIngredientHandler(LinkedControllerScreen.class, new GhostIngredientHandler()); } private class CategoryBuilder> { diff --git a/src/main/java/com/simibubi/create/compat/jei/DoubleItemIcon.java b/src/main/java/com/simibubi/create/compat/jei/DoubleItemIcon.java index 62ea7e696..917597d56 100644 --- a/src/main/java/com/simibubi/create/compat/jei/DoubleItemIcon.java +++ b/src/main/java/com/simibubi/create/compat/jei/DoubleItemIcon.java @@ -4,7 +4,7 @@ import java.util.function.Supplier; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.GuiGameElement; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import mezz.jei.api.gui.drawable.IDrawable; import net.minecraft.world.item.ItemStack; diff --git a/src/main/java/com/simibubi/create/compat/jei/GhostIngredientHandler.java b/src/main/java/com/simibubi/create/compat/jei/GhostIngredientHandler.java index 939b691d2..58025e657 100644 --- a/src/main/java/com/simibubi/create/compat/jei/GhostIngredientHandler.java +++ b/src/main/java/com/simibubi/create/compat/jei/GhostIngredientHandler.java @@ -6,9 +6,9 @@ import java.util.List; import javax.annotation.ParametersAreNonnullByDefault; import com.simibubi.create.content.logistics.item.filter.AttributeFilterScreen; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; -import com.simibubi.create.foundation.gui.GhostItemContainer; -import com.simibubi.create.foundation.gui.GhostItemSubmitPacket; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.container.GhostItemContainer; +import com.simibubi.create.foundation.gui.container.GhostItemSubmitPacket; import com.simibubi.create.foundation.networking.AllPackets; import mezz.jei.api.gui.handlers.IGhostIngredientHandler; diff --git a/src/main/java/com/simibubi/create/compat/jei/SlotMover.java b/src/main/java/com/simibubi/create/compat/jei/SlotMover.java index d99a44ec8..0198d562c 100644 --- a/src/main/java/com/simibubi/create/compat/jei/SlotMover.java +++ b/src/main/java/com/simibubi/create/compat/jei/SlotMover.java @@ -2,7 +2,7 @@ package com.simibubi.create.compat.jei; import java.util.List; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; import mezz.jei.api.gui.handlers.IGuiContainerHandler; import net.minecraft.client.renderer.Rect2i; @@ -18,4 +18,5 @@ public class SlotMover implements IGuiContainerHandler getGuiExtraAreas(AbstractSimiContainerScreen containerScreen) { return containerScreen.getExtraAreas(); } + } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/BasinCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/BasinCategory.java index 91874af66..36cff7aa4 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/BasinCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/BasinCategory.java @@ -158,25 +158,25 @@ public class BasinCategory extends CreateRecipeCategory { int yOffset = 0; for (int i = 0; i < size; i++) - AllGuiTextures.JEI_SLOT.draw(matrixStack, 16 + xOffset + (i % 3) * 19, 50 - (i / 3) * 19 + yOffset); + AllGuiTextures.JEI_SLOT.render(matrixStack, 16 + xOffset + (i % 3) * 19, 50 - (i / 3) * 19 + yOffset); boolean noHeat = requiredHeat == HeatCondition.NONE; int vRows = (1 + outSize) / 2; for (int i = 0; i < outSize; i++) - AllGuiTextures.JEI_SLOT.draw(matrixStack, + AllGuiTextures.JEI_SLOT.render(matrixStack, 141 - (outSize % 2 != 0 && i == outSize - 1 ? 0 : i % 2 == 0 ? 10 : -9), -19 * (i / 2) + 50 + yOffset); if (vRows <= 2) - AllGuiTextures.JEI_DOWN_ARROW.draw(matrixStack, 136, -19 * (vRows - 1) + 32 + yOffset); + AllGuiTextures.JEI_DOWN_ARROW.render(matrixStack, 136, -19 * (vRows - 1) + 32 + yOffset); AllGuiTextures shadow = noHeat ? AllGuiTextures.JEI_SHADOW : AllGuiTextures.JEI_LIGHT; - shadow.draw(matrixStack, 81, 58 + (noHeat ? 10 : 30)); + shadow.render(matrixStack, 81, 58 + (noHeat ? 10 : 30)); if (!needsHeating) return; AllGuiTextures heatBar = noHeat ? AllGuiTextures.JEI_NO_HEAT_BAR : AllGuiTextures.JEI_HEAT_BAR; - heatBar.draw(matrixStack, 4, 80); + heatBar.render(matrixStack, 4, 80); Minecraft.getInstance().font.draw(matrixStack, Lang.translate(requiredHeat.getTranslationKey()), 9, 86, requiredHeat.getColor()); } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/BlockCuttingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/BlockCuttingCategory.java index f6f6ff01c..eed9b78a9 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/BlockCuttingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/BlockCuttingCategory.java @@ -59,15 +59,15 @@ public class BlockCuttingCategory extends CreateRecipeCategory results = recipe.getRollableResults(); - AllGuiTextures.JEI_SLOT.draw(matrixStack, 50, 2); - AllGuiTextures.JEI_DOWN_ARROW.draw(matrixStack, 72, 7); + AllGuiTextures.JEI_SLOT.render(matrixStack, 50, 2); + AllGuiTextures.JEI_DOWN_ARROW.render(matrixStack, 72, 7); int size = results.size(); int offset = -size * 19 / 2; for (int outputIndex = 0; outputIndex < results.size(); outputIndex++) - getRenderedSlot(recipe, outputIndex).draw(matrixStack, getBackground().getWidth() / 2 + offset + 19 * outputIndex, 78); + getRenderedSlot(recipe, outputIndex).render(matrixStack, getBackground().getWidth() / 2 + offset + 19 * outputIndex, 78); crushingWheels.draw(matrixStack, 62, 59); } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/DeployingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/DeployingCategory.java index 49b754466..941e34500 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/DeployingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/DeployingCategory.java @@ -72,11 +72,11 @@ public class DeployingCategory extends CreateRecipeCategory 9 ? 8 : 0); - getRenderedSlot(recipe, i).draw(matrixStack, 126 + xOffset, 47 + yOffset); + getRenderedSlot(recipe, i).render(matrixStack, 126 + xOffset, 47 + yOffset); } } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/ItemDrainCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/ItemDrainCategory.java index 3c29b190b..f47f7f6c8 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/ItemDrainCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/ItemDrainCategory.java @@ -128,11 +128,11 @@ public class ItemDrainCategory extends CreateRecipeCategory { @Override public void draw(EmptyingRecipe recipe, PoseStack matrixStack, double mouseX, double mouseY) { - AllGuiTextures.JEI_SLOT.draw(matrixStack, 131, 7); - AllGuiTextures.JEI_SLOT.draw(matrixStack, 26, 7); - getRenderedSlot(recipe, 0).draw(matrixStack, 131, 26); - AllGuiTextures.JEI_SHADOW.draw(matrixStack, 62, 37); - AllGuiTextures.JEI_DOWN_ARROW.draw(matrixStack, 73, 4); + AllGuiTextures.JEI_SLOT.render(matrixStack, 131, 7); + AllGuiTextures.JEI_SLOT.render(matrixStack, 26, 7); + getRenderedSlot(recipe, 0).render(matrixStack, 131, 26); + AllGuiTextures.JEI_SHADOW.render(matrixStack, 62, 37); + AllGuiTextures.JEI_DOWN_ARROW.render(matrixStack, 73, 4); drain.withFluid(recipe.getResultingFluid()) .draw(matrixStack, getBackground().getWidth() / 2 - 13, 40); } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/MechanicalCraftingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/MechanicalCraftingCategory.java index 1b7de336f..fe5b7fa48 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/MechanicalCraftingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/MechanicalCraftingCategory.java @@ -107,14 +107,14 @@ public class MechanicalCraftingCategory extends CreateRecipeCategory ingredients = recipe.getIngredients(); ItemStack[] matchingStacks = ingredients.get(0) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/PressingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/PressingCategory.java index 7237f2fc0..b18b0e9b6 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/PressingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/PressingCategory.java @@ -55,13 +55,13 @@ public class PressingCategory extends CreateRecipeCategory { @Override public void draw(PressingRecipe recipe, PoseStack matrixStack, double mouseX, double mouseY) { - AllGuiTextures.JEI_SLOT.draw(matrixStack, 26, 50); - getRenderedSlot(recipe, 0).draw(matrixStack, 131, 50); + AllGuiTextures.JEI_SLOT.render(matrixStack, 26, 50); + getRenderedSlot(recipe, 0).render(matrixStack, 131, 50); if (recipe.getRollableResults() .size() > 1) - getRenderedSlot(recipe, 1).draw(matrixStack, 131 + 19, 50); - AllGuiTextures.JEI_SHADOW.draw(matrixStack, 61, 41); - AllGuiTextures.JEI_LONG_ARROW.draw(matrixStack, 52, 54); + getRenderedSlot(recipe, 1).render(matrixStack, 131 + 19, 50); + AllGuiTextures.JEI_SHADOW.render(matrixStack, 61, 41); + AllGuiTextures.JEI_LONG_ARROW.render(matrixStack, 52, 54); press.draw(matrixStack, getBackground().getWidth() / 2 - 17, 22); } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java index 4ea34d30d..59e2d42cb 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/ProcessingViaFanCategory.java @@ -55,11 +55,11 @@ public abstract class ProcessingViaFanCategory> extends Crea } protected void renderWidgets(PoseStack matrixStack, T recipe, double mouseX, double mouseY) { - AllGuiTextures.JEI_SLOT.draw(matrixStack, 20, 47); - AllGuiTextures.JEI_SLOT.draw(matrixStack, 139, 47); - AllGuiTextures.JEI_SHADOW.draw(matrixStack, 47, 29); - AllGuiTextures.JEI_LIGHT.draw(matrixStack, 66, 39); - AllGuiTextures.JEI_LONG_ARROW.draw(matrixStack, 53, 51); + AllGuiTextures.JEI_SLOT.render(matrixStack, 20, 47); + AllGuiTextures.JEI_SLOT.render(matrixStack, 139, 47); + AllGuiTextures.JEI_SHADOW.render(matrixStack, 47, 29); + AllGuiTextures.JEI_LIGHT.render(matrixStack, 66, 39); + AllGuiTextures.JEI_LONG_ARROW.render(matrixStack, 53, 51); } @Override diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java index 6689047a0..437d0ce34 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SawingCategory.java @@ -58,16 +58,16 @@ public class SawingCategory extends CreateRecipeCategory { @Override public void draw(CuttingRecipe recipe, PoseStack matrixStack, double mouseX, double mouseY) { - AllGuiTextures.JEI_SLOT.draw(matrixStack, 43, 4); + AllGuiTextures.JEI_SLOT.render(matrixStack, 43, 4); int size = recipe.getRollableResults() .size(); for (int i = 0; i < size; i++) { int xOffset = i % 2 == 0 ? 0 : 19; int yOffset = (i / 2) * -19; - getRenderedSlot(recipe, i).draw(matrixStack, 117 + xOffset, 47 + yOffset); + getRenderedSlot(recipe, i).render(matrixStack, 117 + xOffset, 47 + yOffset); } - AllGuiTextures.JEI_DOWN_ARROW.draw(matrixStack, 70, 6); - AllGuiTextures.JEI_SHADOW.draw(matrixStack, 72 - 17, 42 + 13); + AllGuiTextures.JEI_DOWN_ARROW.render(matrixStack, 70, 6); + AllGuiTextures.JEI_SHADOW.render(matrixStack, 72 - 17, 42 + 13); saw.draw(matrixStack, 72, 42); } diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SequencedAssemblyCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SequencedAssemblyCategory.java index 69c032821..b83355017 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SequencedAssemblyCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SequencedAssemblyCategory.java @@ -131,11 +131,11 @@ public class SequencedAssemblyCategory extends CreateRecipeCategory 1) { matrixStack.pushPose(); matrixStack.translate(15, 9, 0); - AllIcons.I_SEQ_REPEAT.draw(matrixStack, 50 + xOffset, 75); + AllIcons.I_SEQ_REPEAT.render(matrixStack, 50 + xOffset, 75); Component repeat = new TextComponent("x" + recipe.getLoops()); font.draw(matrixStack, repeat, 66 + xOffset, 80, 0x888888); matrixStack.popPose(); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/SpoutCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/SpoutCategory.java index cb9d41b34..5b96069b2 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/SpoutCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/SpoutCategory.java @@ -144,11 +144,11 @@ public class SpoutCategory extends CreateRecipeCategory { @Override public void draw(FillingRecipe recipe, PoseStack matrixStack, double mouseX, double mouseY) { - AllGuiTextures.JEI_SLOT.draw(matrixStack, 26, 31); - AllGuiTextures.JEI_SLOT.draw(matrixStack, 26, 50); - getRenderedSlot(recipe, 0).draw(matrixStack, 131, 50); - AllGuiTextures.JEI_SHADOW.draw(matrixStack, 62, 57); - AllGuiTextures.JEI_DOWN_ARROW.draw(matrixStack, 126, 29); + AllGuiTextures.JEI_SLOT.render(matrixStack, 26, 31); + AllGuiTextures.JEI_SLOT.render(matrixStack, 26, 50); + getRenderedSlot(recipe, 0).render(matrixStack, 131, 50); + AllGuiTextures.JEI_SHADOW.render(matrixStack, 62, 57); + AllGuiTextures.JEI_DOWN_ARROW.render(matrixStack, 126, 29); spout.withFluids(recipe.getRequiredFluid() .getMatchingFluidStacks()) .draw(matrixStack, getBackground().getWidth() / 2 - 13, 22); diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrafter.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrafter.java index ff52e9dda..26084893b 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrafter.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedCrafter.java @@ -11,7 +11,7 @@ public class AnimatedCrafter extends AnimatedKinetics { public void draw(PoseStack matrixStack, int xOffset, int yOffset) { matrixStack.pushPose(); matrixStack.translate(xOffset, yOffset, 0); - AllGuiTextures.JEI_SHADOW.draw(matrixStack, -16, 13); + AllGuiTextures.JEI_SHADOW.render(matrixStack, -16, 13); matrixStack.translate(3, 16, 0); MatrixTransformStack.of(matrixStack) diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java index 7e3cc74db..b78a6672a 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedKinetics.java @@ -4,8 +4,8 @@ import com.jozufozu.flywheel.core.PartialModel; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.gui.CustomLightingSettings; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.gui.ILightingSettings; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.utility.AnimationTickHolder; import mezz.jei.api.gui.drawable.IDrawable; diff --git a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMillstone.java b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMillstone.java index 90553ec26..85ee7970c 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMillstone.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/animations/AnimatedMillstone.java @@ -11,7 +11,7 @@ public class AnimatedMillstone extends AnimatedKinetics { public void draw(PoseStack matrixStack, int xOffset, int yOffset) { matrixStack.pushPose(); matrixStack.translate(xOffset, yOffset, 0); - AllGuiTextures.JEI_SHADOW.draw(matrixStack, -16, 13); + AllGuiTextures.JEI_SHADOW.render(matrixStack, -16, 13); matrixStack.translate(-2, 18, 0); int scale = 22; diff --git a/src/main/java/com/simibubi/create/compat/jei/category/sequencedAssembly/SequencedAssemblySubCategory.java b/src/main/java/com/simibubi/create/compat/jei/category/sequencedAssembly/SequencedAssemblySubCategory.java index 199f4a0c9..3f32f4602 100644 --- a/src/main/java/com/simibubi/create/compat/jei/category/sequencedAssembly/SequencedAssemblySubCategory.java +++ b/src/main/java/com/simibubi/create/compat/jei/category/sequencedAssembly/SequencedAssemblySubCategory.java @@ -89,7 +89,7 @@ public abstract class SequencedAssemblySubCategory { @Override public void draw(SequencedRecipe recipe, PoseStack ms, double mouseX, double mouseY, int index) { spout.offset = index; - AllGuiTextures.JEI_SLOT.draw(ms, 3, 14); + AllGuiTextures.JEI_SLOT.render(ms, 3, 14); ms.pushPose(); ms.translate(-7, 50, 0); ms.scale(.75f, .75f, .75f); @@ -143,7 +143,7 @@ public abstract class SequencedAssemblySubCategory { ms.scale(.75f, .75f, .75f); deployer.draw(ms, getWidth() / 2, 0); ms.popPose(); - AllGuiTextures.JEI_SLOT.draw(ms, 3, 14); + AllGuiTextures.JEI_SLOT.render(ms, 3, 14); } } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java index 0db837924..9ccffd952 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/clock/CuckooClockTileEntity.java @@ -6,11 +6,11 @@ import static com.simibubi.create.foundation.utility.AngleHelper.rad; import com.simibubi.create.content.contraptions.base.KineticTileEntity; import com.simibubi.create.foundation.advancement.AllTriggers; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; -import com.simibubi.create.foundation.gui.widgets.InterpolatedValue; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; +import com.simibubi.create.foundation.utility.animation.InterpolatedValue; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCraftingInventory.java b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCraftingInventory.java index cf9fc24aa..239c9c7b6 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCraftingInventory.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/crafter/MechanicalCraftingInventory.java @@ -11,7 +11,7 @@ import net.minecraft.world.item.ItemStack; public class MechanicalCraftingInventory extends CraftingContainer { - private static AbstractContainerMenu dummyContainer = new AbstractContainerMenu(null, -1) { + private static final AbstractContainerMenu dummyContainer = new AbstractContainerMenu(null, -1) { public boolean stillValid(Player playerIn) { return false; } diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java index 3fcbb19d9..2a27d7ee8 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/flywheel/FlywheelTileEntity.java @@ -1,7 +1,7 @@ package com.simibubi.create.content.contraptions.components.flywheel; import com.simibubi.create.content.contraptions.base.GeneratingKineticTileEntity; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; diff --git a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MountedFluidStorage.java b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MountedFluidStorage.java index 83ecbf247..303a15587 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MountedFluidStorage.java +++ b/src/main/java/com/simibubi/create/content/contraptions/components/structureMovement/MountedFluidStorage.java @@ -5,9 +5,9 @@ import com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTil import com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank; import com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity; import com.simibubi.create.foundation.fluid.SmartFluidTank; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.NBTHelper; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java index 55d8112a2..f0e3a670c 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/particle/FluidStackParticle.java @@ -11,7 +11,6 @@ import net.minecraft.client.particle.TextureSheetParticle; import net.minecraft.core.particles.ParticleType; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.inventory.InventoryMenu; -import net.minecraft.world.phys.Vec3; import net.minecraftforge.fluids.FluidStack; public class FluidStackParticle extends TextureSheetParticle { @@ -98,10 +97,10 @@ public class FluidStackParticle extends TextureSheetParticle { if (!onGround && level.random.nextFloat() < 1 / 8f) return; - Vec3 rgb = Color.vectorFromRGB(fluid.getFluid() + Color color = new Color(fluid.getFluid() .getAttributes() .getColor(fluid)); - level.addParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, rgb.x, rgb.y, rgb.z); + level.addParticle(ParticleTypes.ENTITY_EFFECT, x, y, z, color.getRedAsFloat(), color.getGreenAsFloat(), color.getBlueAsFloat()); } protected boolean canEvaporate() { diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankRenderer.java index 89ef9939d..52aae668b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankRenderer.java @@ -2,8 +2,8 @@ package com.simibubi.create.content.contraptions.fluids.tank; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.fluid.FluidRenderer; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.tileEntity.renderer.SafeTileEntityRenderer; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider; diff --git a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java index dac144981..15179e99b 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java +++ b/src/main/java/com/simibubi/create/content/contraptions/fluids/tank/FluidTankTileEntity.java @@ -11,9 +11,9 @@ import com.simibubi.create.content.contraptions.fluids.tank.FluidTankBlock.Shape import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.fluid.SmartFluidTank; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java index fbe265773..7f36c2e55 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleConfigScreen.java @@ -7,7 +7,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.gui.AbstractSimiScreen; -import com.simibubi.create.foundation.gui.GuiGameElement; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.utility.Lang; import net.minecraft.ChatFormatting; diff --git a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java index 6ba5e0318..7568eebf1 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java +++ b/src/main/java/com/simibubi/create/content/contraptions/goggles/GoggleOverlayRenderer.java @@ -15,8 +15,8 @@ import com.simibubi.create.content.contraptions.components.structureMovement.pis import com.simibubi.create.content.contraptions.components.structureMovement.piston.PistonExtensionPoleBlock; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.CClient; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.gui.Theme; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.tileEntity.behaviour.ValueBox; import com.simibubi.create.foundation.utility.Color; import com.simibubi.create.foundation.utility.Iterate; diff --git a/src/main/java/com/simibubi/create/content/contraptions/processing/InWorldProcessing.java b/src/main/java/com/simibubi/create/content/contraptions/processing/InWorldProcessing.java index 3f2d0cb03..c865d406a 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/processing/InWorldProcessing.java +++ b/src/main/java/com/simibubi/create/content/contraptions/processing/InWorldProcessing.java @@ -310,7 +310,7 @@ public class InWorldProcessing { world.addParticle(ParticleTypes.POOF, vec.x, vec.y + .25f, vec.z, 0, 1 / 16f, 0); break; case SPLASHING: - Vector3f color = new Vector3f(Color.vectorFromRGB(0x0055FF)); + Vector3f color = new Color(0x0055FF).asVectorF(); world.addParticle(new DustParticleOptions(color, 1), vec.x + (world.random.nextFloat() - .5f) * .5f, vec.y + .5f, vec.z + (world.random.nextFloat() - .5f) * .5f, 0, 1 / 8f, 0); world.addParticle(ParticleTypes.SPIT, vec.x + (world.random.nextFloat() - .5f) * .5f, vec.y + .5f, diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java index 50b7223e2..26d8d5f9d 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/advanced/sequencer/SequencedGearshiftScreen.java @@ -7,10 +7,10 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.IconButton; -import com.simibubi.create.foundation.gui.widgets.ScrollInput; -import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.gui.widget.ScrollInput; +import com.simibubi.create.foundation.gui.widget.SelectionScrollInput; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.Lang; @@ -44,7 +44,6 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { setWindowSize(background.width, background.height); setWindowOffset(-20, 0); super.init(); - widgets.clear(); int x = guiLeft; int y = guiTop; @@ -58,7 +57,10 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); - widgets.add(confirmButton); + confirmButton.withCallback(() -> { + onClose(); + }); + addRenderableWidget(confirmButton); } public void initInputsOfRow(int row, int backgroundX, int backgroundY) { @@ -67,7 +69,7 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { int rowHeight = 22; Vector rowInputs = inputs.get(row); - rowInputs.forEach(widgets::remove); + removeWidgets(rowInputs); rowInputs.clear(); int index = row; Instruction instruction = instructions.get(row); @@ -88,7 +90,7 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { rowInputs.add(value); rowInputs.add(direction); - widgets.addAll(rowInputs); + addRenderableWidgets(rowInputs); updateParamsOfRow(row); } @@ -130,19 +132,19 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { int x = guiLeft; int y = guiTop; - background.draw(ms, this, x, y); + background.render(ms, x, y, this); for (int row = 0; row < instructions.capacity(); row++) { AllGuiTextures toDraw = AllGuiTextures.SEQUENCER_EMPTY; int yOffset = toDraw.height * row; if (row >= instructions.size()) { - toDraw.draw(ms, x, y + 14 + yOffset); + toDraw.render(ms, x, y + 14 + yOffset, this); continue; } Instruction instruction = instructions.get(row); SequencerInstructions def = instruction.instruction; - def.background.draw(ms, x, y + 14 + yOffset); + def.background.render(ms, x, y + 14 + yOffset, this); label(ms, 36, yOffset - 3, Lang.translate(def.translationKey)); if (def.hasValueParameter) { @@ -187,7 +189,7 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { for (int i = instructions.size() - 1; i > index; i--) { instructions.remove(i); Vector rowInputs = inputs.get(i); - rowInputs.forEach(widgets::remove); + removeWidgets(rowInputs); rowInputs.clear(); } } else { @@ -198,14 +200,4 @@ public class SequencedGearshiftScreen extends AbstractSimiScreen { } } - @Override - public boolean mouseClicked(double x, double y, int button) { - if (confirmButton.isHovered()) { - minecraft.player.closeContainer(); - return true; - } - - return super.mouseClicked(x, y, button); - } - } diff --git a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeBlock.java b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeBlock.java index 19c980762..64f421053 100644 --- a/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeBlock.java +++ b/src/main/java/com/simibubi/create/content/contraptions/relays/gauge/GaugeBlock.java @@ -132,7 +132,7 @@ public class GaugeBlock extends DirectionalAxisKineticBlock implements ITE { + onClose(); + }); + addRenderableWidget(confirmButton); } private void initAlign(SymmetryMirror element, int x, int y) { if (areaAlign != null) - widgets.remove(areaAlign); + removeWidget(areaAlign); areaAlign = new SelectionScrollInput(x + 45, y + 43, 109, 18).forOptions(element.getAlignToolTips()) .titled(orientation.plainCopy()) @@ -111,7 +113,7 @@ public class SymmetryWandScreen extends AbstractSimiScreen { .setState(element.getOrientationIndex()) .calling(element::setOrientation); - widgets.add(areaAlign); + addRenderableWidget(areaAlign); } @Override @@ -119,7 +121,7 @@ public class SymmetryWandScreen extends AbstractSimiScreen { int x = guiLeft; int y = guiTop; - background.draw(ms, this, x, y); + background.render(ms, x, y, this); font.draw(ms, wand.getHoverName(), x + 11, y + 4, 0x6B3802); renderBlock(ms, x, y); @@ -149,14 +151,4 @@ public class SymmetryWandScreen extends AbstractSimiScreen { AllPackets.channel.sendToServer(new ConfigureSymmetryWandPacket(hand, currentElement)); } - @Override - public boolean mouseClicked(double x, double y, int button) { - if (confirmButton.isHovered()) { - onClose(); - return true; - } - - return super.mouseClicked(x, y, button); - } - } diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/RadialToolboxMenu.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/RadialToolboxMenu.java index f2f929dab..13a5a35e9 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/RadialToolboxMenu.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/RadialToolboxMenu.java @@ -12,7 +12,7 @@ import com.simibubi.create.AllKeys; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.AnimationTickHolder; @@ -86,19 +86,19 @@ public class RadialToolboxMenu extends AbstractSimiScreen { hoveredSlot = UNEQUIP; ms.pushPose(); - AllGuiTextures.TOOLBELT_INACTIVE_SLOT.draw(ms, this, -12, -12); + AllGuiTextures.TOOLBELT_INACTIVE_SLOT.render(ms, -12, -12, this); GuiGameElement.of(AllBlocks.TOOLBOXES.get(DyeColor.BROWN) .asStack()) .at(-9, -9) .render(ms); ms.translate(0, -40 + (10 * (1 - fade) * (1 - fade)), 0); - AllGuiTextures.TOOLBELT_SLOT.draw(ms, this, -12, -12); + AllGuiTextures.TOOLBELT_SLOT.render(ms, -12, -12, this); ms.translate(-0.5, 0.5, 0); - AllIcons.I_DISABLE.draw(ms, this, -9, -9); + AllIcons.I_DISABLE.render(ms, -9, -9, this); ms.translate(0.5, -0.5, 0); if (!scrollMode && hoveredSlot == UNEQUIP) { - AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.draw(ms, this, -13, -13); + AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.render(ms, -13, -13, this); tip = Lang.translate("toolbox.detach") .withStyle(ChatFormatting.GOLD); } @@ -111,12 +111,12 @@ public class RadialToolboxMenu extends AbstractSimiScreen { ms.pushPose(); ms.translate(80 + (-5 * (1 - fade) * (1 - fade)), 0, 0); - AllGuiTextures.TOOLBELT_SLOT.draw(ms, this, -12, -12); + AllGuiTextures.TOOLBELT_SLOT.render(ms, -12, -12, this); ms.translate(-0.5, 0.5, 0); - AllIcons.I_TOOLBOX.draw(ms, this, -9, -9); + AllIcons.I_TOOLBOX.render(ms, -9, -9, this); ms.translate(0.5, -0.5, 0); if (!scrollMode && hoveredSlot == DEPOSIT) { - AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.draw(ms, this, -13, -13); + AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.render(ms, -13, -13, this); tip = Lang.translate(state == State.SELECT_BOX ? "toolbox.depositAll" : "toolbox.depositBox") .withStyle(ChatFormatting.GOLD); } @@ -138,23 +138,23 @@ public class RadialToolboxMenu extends AbstractSimiScreen { boolean empty = inv.getStackInSlot(slot * ToolboxInventory.STACKS_PER_COMPARTMENT) .isEmpty(); - (empty ? AllGuiTextures.TOOLBELT_INACTIVE_SLOT : AllGuiTextures.TOOLBELT_SLOT).draw(ms, this, 0, - 0); + (empty ? AllGuiTextures.TOOLBELT_INACTIVE_SLOT : AllGuiTextures.TOOLBELT_SLOT) + .render(ms, 0, 0, this); GuiGameElement.of(stackInSlot) .at(3, 3) .render(ms); if (slot == (scrollMode ? scrollSlot : hoveredSlot) && !empty) { - AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.draw(ms, this, -1, -1); + AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.render(ms, -1, -1, this); tip = stackInSlot.getHoverName(); } } else - AllGuiTextures.TOOLBELT_EMPTY_SLOT.draw(ms, this, 0, 0); + AllGuiTextures.TOOLBELT_EMPTY_SLOT.render(ms, 0, 0, this); } else if (state == State.SELECT_BOX) { if (slot < toolboxes.size()) { - AllGuiTextures.TOOLBELT_SLOT.draw(ms, this, 0, 0); + AllGuiTextures.TOOLBELT_SLOT.render(ms, 0, 0, this); ToolboxTileEntity toolboxTileEntity = toolboxes.get(slot); GuiGameElement.of(AllBlocks.TOOLBOXES.get(toolboxTileEntity.getColor()) .asStack()) @@ -162,11 +162,11 @@ public class RadialToolboxMenu extends AbstractSimiScreen { .render(ms); if (slot == (scrollMode ? scrollSlot : hoveredSlot)) { - AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.draw(ms, this, -1, -1); + AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.render(ms, -1, -1, this); tip = toolboxTileEntity.getDisplayName(); } } else - AllGuiTextures.TOOLBELT_EMPTY_SLOT.draw(ms, this, 0, 0); + AllGuiTextures.TOOLBELT_EMPTY_SLOT.render(ms, 0, 0, this); } @@ -175,10 +175,10 @@ public class RadialToolboxMenu extends AbstractSimiScreen { if (renderCenterSlot) { ms.pushPose(); - AllGuiTextures.TOOLBELT_SLOT.draw(ms, this, -12, -12); - (scrollMode ? AllIcons.I_REFRESH : AllIcons.I_FLIP).draw(ms, this, -9, -9); + AllGuiTextures.TOOLBELT_SLOT.render(ms, -12, -12, this); + (scrollMode ? AllIcons.I_REFRESH : AllIcons.I_FLIP).render(ms, -9, -9, this); if (!scrollMode && UNEQUIP == hoveredSlot) { - AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.draw(ms, this, -13, -13); + AllGuiTextures.TOOLBELT_SLOT_HIGHLIGHT.render(ms, -13, -13, this); tip = Lang.translate("toolbox.unequip", minecraft.player.getMainHandItem() .getHoverName()) .withStyle(ChatFormatting.GOLD); diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxContainer.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxContainer.java index fd2bbe54a..17b118fc7 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxContainer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxContainer.java @@ -3,7 +3,7 @@ package com.simibubi.create.content.curiosities.toolbox; import static com.simibubi.create.content.curiosities.toolbox.ToolboxInventory.STACKS_PER_COMPARTMENT; import com.simibubi.create.AllContainerTypes; -import com.simibubi.create.foundation.gui.ContainerBase; +import com.simibubi.create.foundation.gui.container.ContainerBase; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; @@ -21,10 +21,6 @@ import net.minecraftforge.items.SlotItemHandler; public class ToolboxContainer extends ContainerBase { - public static ToolboxContainer create(int id, Inventory inv, ToolboxTileEntity te) { - return new ToolboxContainer(AllContainerTypes.TOOLBOX.get(), id, inv, te); - } - public ToolboxContainer(MenuType type, int id, Inventory inv, FriendlyByteBuf extraData) { super(type, id, inv, extraData); } @@ -34,6 +30,10 @@ public class ToolboxContainer extends ContainerBase { te.startOpen(player); } + public static ToolboxContainer create(int id, Inventory inv, ToolboxTileEntity te) { + return new ToolboxContainer(AllContainerTypes.TOOLBOX.get(), id, inv, te); + } + @Override protected ToolboxTileEntity createOnClient(FriendlyByteBuf extraData) { BlockPos readBlockPos = extraData.readBlockPos(); @@ -121,7 +121,7 @@ public class ToolboxContainer extends ContainerBase { protected void addSlots() { ToolboxInventory inventory = contentHolder.inventory; - int x = 59; + int x = 79; int y = 37; int[] xOffsets = { x, x + 33, x + 66, x + 66 + 6, x + 66, x + 33, x, x - 6 }; @@ -138,7 +138,7 @@ public class ToolboxContainer extends ContainerBase { addSlot(new SlotItemHandler(inventory, baseIndex + i, -100, -100)); } - addPlayerSlots(-12, 166); + addPlayerSlots(8, 165); } @Override diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandlerClient.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandlerClient.java index dd1b74e91..5947e108e 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandlerClient.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandlerClient.java @@ -177,7 +177,7 @@ public class ToolboxHandlerClient { AllGuiTextures texture = ToolboxHandler.distance(player.position(), pos) < max * max ? selected ? TOOLBELT_SELECTED_ON : TOOLBELT_HOTBAR_ON : selected ? TOOLBELT_SELECTED_OFF : TOOLBELT_HOTBAR_OFF; - texture.draw(ms, x + 20 * slot - offset, y + offset); + texture.render(ms, x + 20 * slot - offset, y + offset); } ms.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxScreen.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxScreen.java index 4c70043cd..ba603c04a 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxScreen.java @@ -9,11 +9,11 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.AllBlocks; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.IconButton; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.IconButton; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Lang; @@ -27,8 +27,9 @@ import net.minecraft.world.item.ItemStack; public class ToolboxScreen extends AbstractSimiContainerScreen { - AllGuiTextures BG = AllGuiTextures.TOOLBOX; - AllGuiTextures PLAYER = AllGuiTextures.PLAYER_INVENTORY; + protected static final AllGuiTextures BG = AllGuiTextures.TOOLBOX; + protected static final AllGuiTextures PLAYER = AllGuiTextures.PLAYER_INVENTORY; + protected Slot hoveredToolboxSlot; private IconButton confirmButton; private IconButton disposeButton; @@ -43,18 +44,28 @@ public class ToolboxScreen extends AbstractSimiContainerScreen @Override protected void init() { + setWindowSize(30 + BG.width, BG.height + PLAYER.height - 24); + setWindowOffset(-11, 0); super.init(); - widgets.clear(); - setWindowSize(BG.width, 256); - confirmButton = new IconButton(getGuiLeft() + BG.width - 23, getGuiTop() + BG.height - 24, AllIcons.I_CONFIRM); - disposeButton = new IconButton(getGuiLeft() + 91, getGuiTop() + 69, AllIcons.I_TOOLBOX); - disposeButton.setToolTip(Lang.translate("toolbox.depositBox")); - widgets.add(confirmButton); - widgets.add(disposeButton); + color = menu.contentHolder.getColor(); - extraAreas = ImmutableList.of(new Rect2i(getGuiLeft() + -28, getGuiTop() + 141, 80, 100), - new Rect2i(getGuiLeft() + 162, getGuiTop() + 111, 100, 70)); + confirmButton = new IconButton(leftPos + 30 + BG.width - 33, topPos + BG.height - 24, AllIcons.I_CONFIRM); + confirmButton.withCallback(() -> { + minecraft.player.closeContainer(); + }); + addRenderableWidget(confirmButton); + + disposeButton = new IconButton(leftPos + 30 + 81, topPos + 69, AllIcons.I_TOOLBOX); + disposeButton.withCallback(() -> { + AllPackets.channel.sendToServer(new ToolboxDisposeAllPacket(menu.contentHolder.getBlockPos())); + }); + disposeButton.setToolTip(Lang.translate("toolbox.depositBox")); + addRenderableWidget(disposeButton); + + extraAreas = ImmutableList.of( + new Rect2i(leftPos + 30 + BG.width, topPos + BG.height - 15 - 34 - 6, 72, 68) + ); } @Override @@ -65,18 +76,18 @@ public class ToolboxScreen extends AbstractSimiContainerScreen } @Override - public void setBlitOffset(int p_230926_1_) { - super.setBlitOffset(p_230926_1_); - } + protected void renderBg(PoseStack ms, float partialTicks, int mouseX, int mouseY) { + int x = leftPos + imageWidth - BG.width; + int y = topPos; - @Override - protected void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks) { - BG.draw(ms, this, leftPos + 10, topPos); - PLAYER.draw(ms, this, leftPos + (BG.width - PLAYER.width) / 2 - 26, topPos + imageHeight - PLAYER.height); - font.draw(ms, title, leftPos + 24, topPos + 4, 0x442000); - font.draw(ms, playerInventoryTitle, leftPos - 13, topPos + 154, 0x404040); + BG.render(ms, x, y, this); + font.draw(ms, title, x + 15, y + 4, 0x442000); - renderToolbox(ms, mouseX, mouseY, partialTicks); + int invX = leftPos; + int invY = topPos + imageHeight - PLAYER.height; + renderPlayerInventory(ms, invX, invY); + + renderToolbox(ms, x + BG.width + 50, y + BG.height + 12, partialTicks); hoveredToolboxSlot = null; for (int compartment = 0; compartment < 8; compartment++) { @@ -91,7 +102,7 @@ public class ToolboxScreen extends AbstractSimiContainerScreen if (!itemstack.isEmpty()) { int count = menu.totalCountInCompartment(compartment); - String s = count + ""; + String s = String.valueOf(count); setBlitOffset(100); itemRenderer.blitOffset = 100.0F; RenderSystem.enableDepthTest(); @@ -113,9 +124,9 @@ public class ToolboxScreen extends AbstractSimiContainerScreen } } - private void renderToolbox(PoseStack ms, int mouseX, int mouseY, float partialTicks) { + private void renderToolbox(PoseStack ms, int x, int y, float partialTicks) { ms.pushPose(); - ms.translate(leftPos + 247, topPos + 180, 100); + ms.translate(x, y, 100); MatrixTransformStack.of(ms) .scale(50) .rotateX(-22) @@ -146,28 +157,10 @@ public class ToolboxScreen extends AbstractSimiContainerScreen } @Override - protected void renderWindowForeground(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { + protected void renderForeground(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { if (hoveredToolboxSlot != null) hoveredSlot = hoveredToolboxSlot; - super.renderWindowForeground(matrixStack, mouseX, mouseY, partialTicks); - } - - @Override - public boolean mouseClicked(double x, double y, int button) { - boolean mouseClicked = super.mouseClicked(x, y, button); - - if (button == 0) { - if (confirmButton.isHovered()) { - minecraft.player.closeContainer(); - return true; - } - if (disposeButton.isHovered()) { - AllPackets.channel.sendToServer(new ToolboxDisposeAllPacket(menu.contentHolder.getBlockPos())); - return true; - } - } - - return mouseClicked; + super.renderForeground(matrixStack, mouseX, mouseY, partialTicks); } @Override diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintContainer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintContainer.java index 87d76fcde..78c43e52c 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintContainer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintContainer.java @@ -4,7 +4,7 @@ import java.util.Optional; import com.simibubi.create.AllContainerTypes; import com.simibubi.create.content.curiosities.tools.BlueprintEntity.BlueprintSection; -import com.simibubi.create.foundation.gui.GhostItemContainer; +import com.simibubi.create.foundation.gui.container.GhostItemContainer; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java index 6994f8558..dd8928408 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintEntity.java @@ -16,9 +16,9 @@ import com.simibubi.create.content.logistics.item.filter.FilterItem; import com.simibubi.create.content.schematics.ISpecialEntityItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement; import com.simibubi.create.content.schematics.ItemRequirement.ItemUseType; -import com.simibubi.create.foundation.gui.IInteractionChecker; import com.simibubi.create.foundation.networking.ISyncPersistentData; import com.simibubi.create.foundation.utility.Couple; +import com.simibubi.create.foundation.utility.IInteractionChecker; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.core.BlockPos; @@ -456,7 +456,7 @@ public class BlueprintEntity extends HangingEntity static class BlueprintCraftingInventory extends CraftingContainer { - private static AbstractContainerMenu dummyContainer = new AbstractContainerMenu(null, -1) { + private static final AbstractContainerMenu dummyContainer = new AbstractContainerMenu(null, -1) { public boolean stillValid(Player playerIn) { return false; } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintOverlayRenderer.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintOverlayRenderer.java index e3a626c12..05ecbf43c 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintOverlayRenderer.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintOverlayRenderer.java @@ -16,7 +16,7 @@ import com.simibubi.create.content.logistics.item.filter.AttributeFilterContaine import com.simibubi.create.content.logistics.item.filter.FilterItem; import com.simibubi.create.content.logistics.item.filter.ItemAttribute; import com.simibubi.create.foundation.gui.AllGuiTextures; -import com.simibubi.create.foundation.gui.GuiGameElement; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Pair; @@ -219,7 +219,7 @@ public class BlueprintOverlayRenderer { for (Pair pair : ingredients) { RenderSystem.enableBlend(); - (pair.getSecond() ? AllGuiTextures.HOTSLOT_ACTIVE : AllGuiTextures.HOTSLOT).draw(ms, x, y); + (pair.getSecond() ? AllGuiTextures.HOTSLOT_ACTIVE : AllGuiTextures.HOTSLOT).render(ms, x, y); ItemStack itemStack = pair.getFirst(); String count = pair.getSecond() ? null : ChatFormatting.GOLD.toString() + itemStack.getCount(); drawItemStack(ms, mc, x, y, itemStack, count); @@ -228,16 +228,16 @@ public class BlueprintOverlayRenderer { x += 5; RenderSystem.enableBlend(); - AllGuiTextures.HOTSLOT_ARROW.draw(ms, x, y + 4); + AllGuiTextures.HOTSLOT_ARROW.render(ms, x, y + 4); x += 25; if (result.isEmpty()) { - AllGuiTextures.HOTSLOT.draw(ms, x, y); + AllGuiTextures.HOTSLOT.render(ms, x, y); GuiGameElement.of(Items.BARRIER) .at(x + 3, y + 3) .render(ms); } else { - (resultCraftable ? AllGuiTextures.HOTSLOT_SUPER_ACTIVE : AllGuiTextures.HOTSLOT).draw(ms, + (resultCraftable ? AllGuiTextures.HOTSLOT_SUPER_ACTIVE : AllGuiTextures.HOTSLOT).render(ms, resultCraftable ? x - 1 : x, resultCraftable ? y - 1 : y); drawItemStack(ms, mc, x, y, result, null); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintScreen.java b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintScreen.java index f97b2fbb0..45e25aeee 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/tools/BlueprintScreen.java @@ -11,11 +11,11 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.logistics.item.filter.FilterScreenPacket; import com.simibubi.create.content.logistics.item.filter.FilterScreenPacket.Option; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.IconButton; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.IconButton; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.Lang; @@ -41,18 +41,25 @@ public class BlueprintScreen extends AbstractSimiContainerScreen { + menu.clearContents(); + contentsCleared(); + menu.sendClearPacket(); + }); confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); + confirmButton.withCallback(() -> { + minecraft.player.closeContainer(); + }); - widgets.add(resetButton); - widgets.add(confirmButton); + addRenderableWidget(resetButton); + addRenderableWidget(confirmButton); extraAreas = ImmutableList.of( new Rect2i(x + background.width, y + background.height - 36, 56, 44) @@ -60,7 +67,7 @@ public class BlueprintScreen extends AbstractSimiContainerScreen { + onClose(); + }); + addRenderableWidget(confirmButton); patternButtons.clear(); for (int row = 0; row <= 1; row++) { for (int col = 0; col <= 2; col++) { int id = patternButtons.size(); PlacementPatterns pattern = PlacementPatterns.values()[id]; - patternButtons - .add(new IconButton(x + background.width - 76 + col * 18, y + 21 + row * 18, pattern.icon)); - patternButtons.get(id) - .setToolTip(Lang.translate("gui.terrainzapper.pattern." + pattern.translationKey)); + IconButton patternButton = new IconButton(x + background.width - 76 + col * 18, y + 21 + row * 18, pattern.icon); + patternButton.withCallback(() -> { + patternButtons.forEach(b -> b.active = true); + patternButton.active = false; + currentPattern = pattern; + }); + patternButton.setToolTip(Lang.translate("gui.terrainzapper.pattern." + pattern.translationKey)); + patternButtons.add(patternButton); } } patternButtons.get(currentPattern.ordinal()).active = false; - widgets.addAll(patternButtons); + addRenderableWidgets(patternButtons); } @Override @@ -90,7 +96,7 @@ public abstract class ZapperScreen extends AbstractSimiScreen { int x = guiLeft; int y = guiTop; - background.draw(ms, this, x, y); + background.render(ms, x, y, this); drawOnBackground(ms, x, y); renderBlock(ms, x, y); @@ -114,25 +120,6 @@ public abstract class ZapperScreen extends AbstractSimiScreen { AllPackets.channel.sendToServer(packet); } - @Override - public boolean mouseClicked(double x, double y, int button) { - for (IconButton patternButton : patternButtons) { - if (patternButton.isHovered()) { - patternButtons.forEach(b -> b.active = true); - patternButton.active = false; - patternButton.playDownSound(minecraft.getSoundManager()); - currentPattern = PlacementPatterns.values()[patternButtons.indexOf(patternButton)]; - } - } - - if (confirmButton.isHovered()) { - onClose(); - return true; - } - - return super.mouseClicked(x, y, button); - } - protected void renderZapper(PoseStack ms, int x, int y) { GuiGameElement.of(zapper) .scale(4) diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperScreen.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperScreen.java index 5002c39ae..806ae600c 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperScreen.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/terrainzapper/WorldshaperScreen.java @@ -8,12 +8,12 @@ import com.simibubi.create.content.curiosities.zapper.ConfigureZapperPacket; import com.simibubi.create.content.curiosities.zapper.ZapperScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.widgets.IconButton; -import com.simibubi.create.foundation.gui.widgets.Indicator; -import com.simibubi.create.foundation.gui.widgets.Indicator.State; -import com.simibubi.create.foundation.gui.widgets.Label; -import com.simibubi.create.foundation.gui.widgets.ScrollInput; -import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput; +import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.gui.widget.Indicator; +import com.simibubi.create.foundation.gui.widget.Indicator.State; +import com.simibubi.create.foundation.gui.widget.Label; +import com.simibubi.create.foundation.gui.widget.ScrollInput; +import com.simibubi.create.foundation.gui.widget.SelectionScrollInput; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.NBTHelper; @@ -93,8 +93,8 @@ public class WorldshaperScreen extends ZapperScreen { brushInput.setState(currentBrush.ordinal()); - widgets.add(brushLabel); - widgets.add(brushInput); + addRenderableWidget(brushLabel); + addRenderableWidget(brushInput); initBrushParams(x, y); } @@ -104,8 +104,8 @@ public class WorldshaperScreen extends ZapperScreen { // Brush Params - widgets.removeAll(brushParamLabels); - widgets.removeAll(brushParams); + removeWidgets(brushParamLabels); + removeWidgets(brushParams); brushParamLabels.clear(); brushParams.clear(); @@ -136,16 +136,16 @@ public class WorldshaperScreen extends ZapperScreen { brushParams.add(input); } - widgets.addAll(brushParamLabels); - widgets.addAll(brushParams); + addRenderableWidgets(brushParamLabels); + addRenderableWidgets(brushParams); // Connectivity Options if (followDiagonals != null) { - widgets.remove(followDiagonals); - widgets.remove(followDiagonalsIndicator); - widgets.remove(acrossMaterials); - widgets.remove(acrossMaterialsIndicator); + removeWidget(followDiagonals); + removeWidget(followDiagonalsIndicator); + removeWidget(acrossMaterials); + removeWidget(acrossMaterialsIndicator); followDiagonals = null; followDiagonalsIndicator = null; acrossMaterials = null; @@ -161,12 +161,20 @@ public class WorldshaperScreen extends ZapperScreen { acrossMaterialsIndicator = new Indicator(x1, y1 - 6, TextComponent.EMPTY); acrossMaterials = new IconButton(x1, y1, AllIcons.I_FOLLOW_MATERIAL); + followDiagonals.withCallback(() -> { + followDiagonalsIndicator.state = followDiagonalsIndicator.state == State.OFF ? State.ON : State.OFF; + currentFollowDiagonals = !currentFollowDiagonals; + }); followDiagonals.setToolTip(Lang.translate("gui.terrainzapper.searchDiagonal")); + acrossMaterials.withCallback(() -> { + acrossMaterialsIndicator.state = acrossMaterialsIndicator.state == State.OFF ? State.ON : State.OFF; + currentAcrossMaterials = !currentAcrossMaterials; + }); acrossMaterials.setToolTip(Lang.translate("gui.terrainzapper.searchFuzzy")); - widgets.add(followDiagonals); - widgets.add(followDiagonalsIndicator); - widgets.add(acrossMaterials); - widgets.add(acrossMaterialsIndicator); + addRenderableWidget(followDiagonals); + addRenderableWidget(followDiagonalsIndicator); + addRenderableWidget(acrossMaterials); + addRenderableWidget(acrossMaterialsIndicator); if (currentFollowDiagonals) followDiagonalsIndicator.state = State.ON; if (currentAcrossMaterials) @@ -176,15 +184,20 @@ public class WorldshaperScreen extends ZapperScreen { // Tools if (toolButtons != null) - widgets.removeAll(toolButtons); + removeWidgets(toolButtons); TerrainTools[] toolValues = currentBrush.getSupportedTools(); toolButtons = new Vector<>(toolValues.length); for (int id = 0; id < toolValues.length; id++) { TerrainTools tool = toolValues[id]; - toolButtons.add(new IconButton(x + 7 + id * 18, y + 79, tool.icon)); - toolButtons.get(id) - .setToolTip(Lang.translate("gui.terrainzapper.tool." + tool.translationKey)); + IconButton toolButton = new IconButton(x + 7 + id * 18, y + 79, tool.icon); + toolButton.withCallback(() -> { + toolButtons.forEach(b -> b.active = true); + toolButton.active = false; + currentTool = tool; + }); + toolButton.setToolTip(Lang.translate("gui.terrainzapper.tool." + tool.translationKey)); + toolButtons.add(toolButton); } int toolIndex = -1; @@ -197,72 +210,41 @@ public class WorldshaperScreen extends ZapperScreen { } toolButtons.get(toolIndex).active = false; - widgets.addAll(toolButtons); + addRenderableWidgets(toolButtons); // Placement Options if (placementButtons != null) - widgets.removeAll(placementButtons); + removeWidgets(placementButtons); if (currentBrush.hasPlacementOptions()) { PlacementOptions[] placementValues = PlacementOptions.values(); placementButtons = new Vector<>(placementValues.length); for (int id = 0; id < placementValues.length; id++) { PlacementOptions option = placementValues[id]; - placementButtons.add(new IconButton(x + 136 + id * 18, y + 79, option.icon)); - placementButtons.get(id) - .setToolTip(Lang.translate("gui.terrainzapper.placement." + option.translationKey)); + IconButton placementButton = new IconButton(x + 136 + id * 18, y + 79, option.icon); + placementButton.withCallback(() -> { + placementButtons.forEach(b -> b.active = true); + placementButton.active = false; + currentPlacement = option; + }); + placementButton.setToolTip(Lang.translate("gui.terrainzapper.placement." + option.translationKey)); + placementButtons.add(placementButton); } placementButtons.get(currentPlacement.ordinal()).active = false; - widgets.addAll(placementButtons); + addRenderableWidgets(placementButtons); } } - @Override - public boolean mouseClicked(double x, double y, int button) { - TerrainTools[] supportedTools = currentBrush.get() - .getSupportedTools(); - for (IconButton toolButton : toolButtons) { - if (toolButton.isHovered()) { - toolButtons.forEach(b -> b.active = true); - toolButton.active = false; - toolButton.playDownSound(minecraft.getSoundManager()); - currentTool = supportedTools[toolButtons.indexOf(toolButton)]; - } - } - - if (placementButtons != null) { - for (IconButton placementButton : placementButtons) { - if (placementButton.isHovered()) { - placementButtons.forEach(b -> b.active = true); - placementButton.active = false; - placementButton.playDownSound(minecraft.getSoundManager()); - currentPlacement = PlacementOptions.values()[placementButtons.indexOf(placementButton)]; - } - } - } - - if (followDiagonals != null && followDiagonals.isHovered()) { - followDiagonalsIndicator.state = followDiagonalsIndicator.state == State.OFF ? State.ON : State.OFF; - currentFollowDiagonals = !currentFollowDiagonals; - } - if (acrossMaterials != null && acrossMaterials.isHovered()) { - acrossMaterialsIndicator.state = acrossMaterialsIndicator.state == State.OFF ? State.ON : State.OFF; - currentAcrossMaterials = !currentAcrossMaterials; - } - - return super.mouseClicked(x, y, button); - } - @Override protected void drawOnBackground(PoseStack matrixStack, int x, int y) { super.drawOnBackground(matrixStack, x, y); Brush currentBrush = this.currentBrush.get(); for (int index = 2; index >= currentBrush.amtParams; index--) - AllGuiTextures.TERRAINZAPPER_INACTIVE_PARAM.draw(matrixStack, x + 56 + 20 * index, y + 40); + AllGuiTextures.TERRAINZAPPER_INACTIVE_PARAM.render(matrixStack, x + 56 + 20 * index, y + 40, this); font.draw(matrixStack, toolSection, x + 7, y + 69, fontColor); if (currentBrush.hasPlacementOptions()) diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java index 21f24d13e..22a11ad9c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelInstance.java @@ -12,9 +12,9 @@ import com.jozufozu.flywheel.backend.instancing.tile.TileEntityInstance; import com.jozufozu.flywheel.backend.material.MaterialManager; import com.simibubi.create.AllBlockPartials; import com.simibubi.create.content.logistics.block.FlapData; -import com.simibubi.create.foundation.gui.widgets.InterpolatedValue; import com.simibubi.create.foundation.render.AllMaterialSpecs; import com.simibubi.create.foundation.utility.AnimationTickHolder; +import com.simibubi.create.foundation.utility.animation.InterpolatedValue; import net.minecraft.core.Direction; import net.minecraft.world.level.LightLayer; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java index a532288e8..39e17521e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/belts/tunnel/BeltTunnelTileEntity.java @@ -15,11 +15,11 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock.Shape; import com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock; import com.simibubi.create.content.logistics.packet.TunnelFlapPacket; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Iterate; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java index 65304587c..c72b26ff8 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/chute/ChuteTileEntity.java @@ -17,7 +17,6 @@ import com.simibubi.create.content.contraptions.particle.AirParticleData; import com.simibubi.create.content.logistics.block.funnel.FunnelBlock; import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.gui.widgets.InterpolatedValue; import com.simibubi.create.foundation.item.ItemHelper; import com.simibubi.create.foundation.item.ItemHelper.ExtractionCountMode; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; @@ -29,6 +28,7 @@ import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.Iterate; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.animation.InterpolatedValue; import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTargetHandler.java b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTargetHandler.java index ed80ec186..725752fc3 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTargetHandler.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/depot/EjectorTargetHandler.java @@ -208,7 +208,7 @@ public class EjectorTargetHandler { double tickOffset = totalFlyingTicks / segments; boolean valid = xDiff == validX && zDiff == validZ; int intColor = valid ? 0x9ede73 : 0xff7171; - Vector3f color = new Vector3f(Color.vectorFromRGB(intColor)); + Vector3f color = new Color(intColor).asVectorF(); DustParticleOptions data = new DustParticleOptions(color, 1); ClientLevel world = mc.level; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java index d4963284d..dee43167c 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/funnel/FunnelTileEntity.java @@ -14,7 +14,6 @@ import com.simibubi.create.content.contraptions.relays.belt.transport.Transporte import com.simibubi.create.content.logistics.block.funnel.BeltFunnelBlock.Shape; import com.simibubi.create.content.logistics.packet.FunnelFlapPacket; import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; @@ -23,6 +22,7 @@ import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringBe import com.simibubi.create.foundation.tileEntity.behaviour.inventory.InvManipulationBehaviour; import com.simibubi.create.foundation.utility.BlockFace; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateContainer.java b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateContainer.java index 5996bff8a..7e0b2d33f 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateContainer.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateContainer.java @@ -1,72 +1,72 @@ package com.simibubi.create.content.logistics.block.inventories; import com.simibubi.create.AllContainerTypes; +import com.simibubi.create.foundation.gui.container.ContainerBase; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; +import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.items.SlotItemHandler; -public class AdjustableCrateContainer extends AbstractContainerMenu { +public class AdjustableCrateContainer extends ContainerBase { - public AdjustableCrateTileEntity te; - public Inventory playerInventory; - public boolean doubleCrate; + protected boolean doubleCrate; public AdjustableCrateContainer(MenuType type, int id, Inventory inv, FriendlyByteBuf extraData) { - super(type, id); - ClientLevel world = Minecraft.getInstance().level; - BlockEntity tileEntity = world.getBlockEntity(extraData.readBlockPos()); - this.playerInventory = inv; - if (tileEntity instanceof AdjustableCrateTileEntity) { - this.te = (AdjustableCrateTileEntity) tileEntity; - this.te.handleUpdateTag(extraData.readNbt()); - init(); - } + super(type, id, inv, extraData); } public AdjustableCrateContainer(MenuType type, int id, Inventory inv, AdjustableCrateTileEntity te) { - super(type, id); - this.te = te; - this.playerInventory = inv; - init(); + super(type, id, inv, te); } public static AdjustableCrateContainer create(int id, Inventory inv, AdjustableCrateTileEntity te) { return new AdjustableCrateContainer(AllContainerTypes.FLEXCRATE.get(), id, inv, te); } - private void init() { - doubleCrate = te.isDoubleCrate(); + @Override + protected AdjustableCrateTileEntity createOnClient(FriendlyByteBuf extraData) { + BlockPos readBlockPos = extraData.readBlockPos(); + CompoundTag readNbt = extraData.readNbt(); + + ClientLevel world = Minecraft.getInstance().level; + BlockEntity tileEntity = world.getBlockEntity(readBlockPos); + if (tileEntity instanceof AdjustableCrateTileEntity crate) { + crate.handleUpdateTag(readNbt); + return crate; + } + + return null; + } + + @Override + protected void initAndReadInventory(AdjustableCrateTileEntity contentHolder) { + doubleCrate = contentHolder.isDoubleCrate(); + } + + @Override + protected void addSlots() { int x = doubleCrate ? 23 : 53; int maxCol = doubleCrate ? 8 : 4; for (int row = 0; row < 4; ++row) { for (int col = 0; col < maxCol; ++col) { - this.addSlot(new SlotItemHandler(te.inventory, col + row * maxCol, x + col * 18, 20 + row * 18)); + this.addSlot(new SlotItemHandler(contentHolder.inventory, col + row * maxCol, x + col * 18, 20 + row * 18)); } } - // player Slots - int xOffset = doubleCrate ? 20 : 8; - int yOffset = 149; - for (int row = 0; row < 3; ++row) { - for (int col = 0; col < 9; ++col) { - this.addSlot(new Slot(playerInventory, col + row * 9 + 9, xOffset + col * 18, yOffset + row * 18)); - } - } + addPlayerSlots(doubleCrate ? 20 : 8, 149); + } - for (int hotbarSlot = 0; hotbarSlot < 9; ++hotbarSlot) { - this.addSlot(new Slot(playerInventory, hotbarSlot, xOffset + hotbarSlot * 18, yOffset + 58)); - } - - broadcastChanges(); + @Override + protected void saveData(AdjustableCrateTileEntity contentHolder) { } @Override @@ -79,16 +79,11 @@ public class AdjustableCrateContainer extends AbstractContainerMenu { int crateSize = doubleCrate ? 32 : 16; if (index < crateSize) { moveItemStackTo(stack, crateSize, slots.size(), false); - te.inventory.onContentsChanged(index); + contentHolder.inventory.onContentsChanged(index); } else moveItemStackTo(stack, 0, crateSize - 1, false); return ItemStack.EMPTY; } - @Override - public boolean stillValid(Player player) { - return te != null && te.canPlayerUse(player); - } - } diff --git a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateScreen.java b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateScreen.java index 8be9aca26..394b101a9 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/inventories/AdjustableCrateScreen.java @@ -11,11 +11,11 @@ import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.logistics.packet.ConfigureFlexcratePacket; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.Label; -import com.simibubi.create.foundation.gui.widgets.ScrollInput; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.Label; +import com.simibubi.create.foundation.gui.widget.ScrollInput; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.Lang; @@ -44,7 +44,7 @@ public class AdjustableCrateScreen extends AbstractSimiContainerScreen lastModification = 0); allowedItems.onChanged(); - widgets.add(allowedItemsLabel); - widgets.add(allowedItems); + addRenderableWidget(allowedItemsLabel); + addRenderableWidget(allowedItems); extraAreas = ImmutableList.of( new Rect2i(x + background.width, y + background.height - 56 + itemYShift, 80, 80) @@ -81,7 +80,7 @@ public class AdjustableCrateScreen extends AbstractSimiContainerScreen= 0) lastModification++; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java index b5766740e..e8e92c852 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/mechanicalArm/ArmTileEntity.java @@ -14,7 +14,6 @@ import com.simibubi.create.content.logistics.block.mechanicalArm.ArmInteractionP import com.simibubi.create.foundation.advancement.AllTriggers; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.widgets.InterpolatedAngle; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.tileEntity.behaviour.CenteredSideValueBoxTransform; @@ -24,6 +23,7 @@ import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.animation.InterpolatedAngle; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverTileEntity.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverTileEntity.java index 9dd9ffe36..6e29d82aa 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverTileEntity.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/AnalogLeverTileEntity.java @@ -4,10 +4,10 @@ import java.util.List; import com.jozufozu.flywheel.backend.instancing.IInstanceRendered; import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; diff --git a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchScreen.java b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchScreen.java index b0bc53daa..413b76886 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/redstone/StockpileSwitchScreen.java @@ -6,9 +6,9 @@ import com.simibubi.create.content.logistics.packet.ConfigureStockswitchPacket; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.IconButton; -import com.simibubi.create.foundation.gui.widgets.ScrollInput; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.gui.widget.ScrollInput; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.animation.LerpedFloat; @@ -47,7 +47,6 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { setWindowSize(background.width, background.height); setWindowOffset(-20, 0); super.init(); - widgets.clear(); int x = guiLeft; int y = guiTop; @@ -84,16 +83,22 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { onAbove.onChanged(); offBelow.onChanged(); - widgets.add(onAbove); - widgets.add(offBelow); + addRenderableWidget(onAbove); + addRenderableWidget(offBelow); confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); - widgets.add(confirmButton); + confirmButton.withCallback(() -> { + onClose(); + }); + addRenderableWidget(confirmButton); flipSignals = new IconButton(x + 14, y + 40, AllIcons.I_FLIP); + flipSignals.withCallback(() -> { + send(!te.isInverted()); + }); flipSignals.setToolTip(invertSignal); - widgets.add(flipSignals); + addRenderableWidget(flipSignals); } @Override @@ -101,10 +106,10 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { int x = guiLeft; int y = guiTop; - background.draw(ms, this, x, y); + background.render(ms, x, y, this); - AllGuiTextures.STOCKSWITCH_POWERED_LANE.draw(ms, this, x + 36, y + (te.isInverted() ? 18 : 40)); - AllGuiTextures.STOCKSWITCH_UNPOWERED_LANE.draw(ms, this, x + 36, y + (te.isInverted() ? 40 : 18)); + AllGuiTextures.STOCKSWITCH_POWERED_LANE.render(ms, x + 36, y + (te.isInverted() ? 18 : 40), this); + AllGuiTextures.STOCKSWITCH_UNPOWERED_LANE.render(ms, x + 36, y + (te.isInverted() ? 40 : 18), this); drawCenteredString(ms, font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); AllGuiTextures sprite = AllGuiTextures.STOCKSWITCH_INTERVAL; @@ -116,15 +121,15 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { (int) (sprite.width - upperBound), sprite.height); blit(ms, x + 37, y + 40, sprite.startX, sprite.startY, (int) (lowerBound), sprite.height); - AllGuiTextures.STOCKSWITCH_ARROW_UP.draw(ms, this, (int) (x + lowerBound + 36) - 2, y + 35); - AllGuiTextures.STOCKSWITCH_ARROW_DOWN.draw(ms, this, (int) (x + upperBound + 36) - 3, y + 17); + AllGuiTextures.STOCKSWITCH_ARROW_UP.render(ms, (int) (x + lowerBound + 36) - 2, y + 35, this); + AllGuiTextures.STOCKSWITCH_ARROW_DOWN.render(ms, (int) (x + upperBound + 36) - 3, y + 17, this); if (te.currentLevel != -1) { AllGuiTextures cursor = AllGuiTextures.STOCKSWITCH_CURSOR; ms.pushPose(); ms.translate(Math.min(99, this.cursor.getValue(partialTicks) * sprite.width), cursorLane.getValue(partialTicks) * 22, 0); - cursor.draw(ms, this, x + 34, y + 19); + cursor.render(ms, x + 34, y + 19, this); ms.popPose(); } @@ -162,15 +167,4 @@ public class StockpileSwitchScreen extends AbstractSimiScreen { onAbove.getState() / 100f, invert)); } - @Override - public boolean mouseClicked(double x, double y, int button) { - if (flipSignals.isHovered()) - send(!te.isInverted()); - if (confirmButton.isHovered()) { - minecraft.player.closeContainer(); - return true; - } - return super.mouseClicked(x, y, button); - } - } diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerContainer.java b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerContainer.java index 06c108091..ab08fd0a6 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerContainer.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerContainer.java @@ -1,69 +1,52 @@ package com.simibubi.create.content.logistics.item; import com.simibubi.create.AllContainerTypes; -import com.simibubi.create.foundation.gui.IClearableContainer; +import com.simibubi.create.foundation.gui.container.GhostItemContainer; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.ClickType; import net.minecraft.world.inventory.MenuType; -import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.items.SlotItemHandler; -public class LinkedControllerContainer extends AbstractContainerMenu implements IClearableContainer { - - public Player player; - protected Inventory playerInventory; - public ItemStack mainItem; - public ItemStackHandler filterInventory; +public class LinkedControllerContainer extends GhostItemContainer { public LinkedControllerContainer(MenuType type, int id, Inventory inv, FriendlyByteBuf extraData) { - this(type, id, inv, extraData.readItem()); + super(type, id, inv, extraData); } public LinkedControllerContainer(MenuType type, int id, Inventory inv, ItemStack filterItem) { - super(type, id); - player = inv.player; - playerInventory = inv; - this.mainItem = filterItem; - init(); + super(type, id, inv, filterItem); } public static LinkedControllerContainer create(int id, Inventory inv, ItemStack filterItem) { return new LinkedControllerContainer(AllContainerTypes.LINKED_CONTROLLER.get(), id, inv, filterItem); } - protected void init() { - this.filterInventory = createFilterInventory(); -// readData(mainItem); - addPlayerSlots(); - addLinkSlots(); - broadcastChanges(); + @Override + protected ItemStack createOnClient(FriendlyByteBuf extraData) { + return extraData.readItem(); } - protected void addPlayerSlots() { - int x = 8; - int y = 131; - - for (int hotbarSlot = 0; hotbarSlot < 9; ++hotbarSlot) - this.addSlot(new Slot(playerInventory, hotbarSlot, x + hotbarSlot * 18, y + 58)); - for (int row = 0; row < 3; ++row) - for (int col = 0; col < 9; ++col) - this.addSlot(new Slot(playerInventory, col + row * 9 + 9, x + col * 18, y + row * 18)); + @Override + protected ItemStackHandler createGhostInventory() { + return LinkedControllerItem.getFrequencyItems(contentHolder); } - protected void addLinkSlots() { + @Override + protected void addSlots() { + addPlayerSlots(8, 131); + int x = 12; int y = 34; int slot = 0; - + for (int column = 0; column < 6; column++) { for (int row = 0; row < 2; ++row) - addSlot(new SlotItemHandler(filterInventory, slot++, x, y + row * 18)); + addSlot(new SlotItemHandler(ghostInventory, slot++, x, y + row * 18)); x += 24; if (column == 3) x += 11; @@ -71,89 +54,26 @@ public class LinkedControllerContainer extends AbstractContainerMenu implements } @Override - public void clearContents() { - for (int i = 0; i < filterInventory.getSlots(); i++) - filterInventory.setStackInSlot(i, ItemStack.EMPTY); + protected void saveData(ItemStack contentHolder) { + contentHolder.getOrCreateTag() + .put("Items", ghostInventory.serializeNBT()); } @Override - public boolean canTakeItemForPickAll(ItemStack stack, Slot slotIn) { - return canDragTo(slotIn); - } - - @Override - public boolean canDragTo(Slot slotIn) { - return slotIn.container == playerInventory; - } - - @Override - public boolean stillValid(Player playerIn) { - return playerInventory.getSelected() == mainItem; + protected boolean allowRepeats() { + return true; } @Override public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) { if (slotId == playerInventory.selected && clickTypeIn != ClickType.THROW) return; - - ItemStack held = getCarried(); - if (slotId < 36) { - super.clicked(slotId, dragType, clickTypeIn, player); - return; - } - if (clickTypeIn == ClickType.THROW) - return; - - int slot = slotId - 36; - if (clickTypeIn == ClickType.CLONE) { - if (player.isCreative() && held.isEmpty()) { - ItemStack stackInSlot = filterInventory.getStackInSlot(slot) - .copy(); - stackInSlot.setCount(64); - setCarried(stackInSlot); - return; - } - return; - } - - if (held.isEmpty()) { - filterInventory.setStackInSlot(slot, ItemStack.EMPTY); - return; - } - - ItemStack insert = held.copy(); - insert.setCount(1); - filterInventory.setStackInSlot(slot, insert); - } - - protected ItemStackHandler createFilterInventory() { - return LinkedControllerItem.getFrequencyItems(mainItem); + super.clicked(slotId, dragType, clickTypeIn, player); } @Override - public ItemStack quickMoveStack(Player playerIn, int index) { - if (index < 36) { - ItemStack stackToInsert = playerInventory.getItem(index); - for (int i = 0; i < filterInventory.getSlots(); i++) { - ItemStack stack = filterInventory.getStackInSlot(i); - if (stack.isEmpty()) { - ItemStack copy = stackToInsert.copy(); - copy.setCount(1); - filterInventory.insertItem(i, copy, false); - break; - } - } - } else - filterInventory.extractItem(index - 36, 1, false); - return ItemStack.EMPTY; - } - - @Override - public void removed(Player playerIn) { - super.removed(playerIn); - mainItem.getOrCreateTag() - .put("Items", filterInventory.serializeNBT()); -// saveData(filterItem); + public boolean stillValid(Player playerIn) { + return playerInventory.getSelected() == contentHolder; } } diff --git a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerScreen.java b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerScreen.java index 92b7c12f4..972b2815e 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/LinkedControllerScreen.java @@ -8,11 +8,11 @@ import java.util.List; import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.IconButton; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.IconButton; import com.simibubi.create.foundation.utility.Lang; import net.minecraft.ChatFormatting; @@ -37,18 +37,24 @@ public class LinkedControllerScreen extends AbstractSimiContainerScreen { + menu.clearContents(); + menu.sendClearPacket(); + }); confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); + confirmButton.withCallback(() -> { + minecraft.player.closeContainer(); + }); - widgets.add(resetButton); - widgets.add(confirmButton); + addRenderableWidget(resetButton); + addRenderableWidget(confirmButton); extraAreas = ImmutableList.of( new Rect2i(x + background.width + 4, y + background.height - 44, 64, 56) @@ -56,7 +62,7 @@ public class LinkedControllerScreen extends AbstractSimiContainerScreenat(x + background.width - 4, y + background.height - 56, -200) .scale(5) .render(ms); @@ -76,27 +82,10 @@ public class LinkedControllerScreen extends AbstractSimiContainerScreen ex protected void init() { setWindowSize(Math.max(background.width, PLAYER_INVENTORY.width), background.height + 4 + PLAYER_INVENTORY.height); super.init(); - widgets.clear(); int x = leftPos; int y = topPos; resetButton = new IconButton(x + background.width - 62, y + background.height - 24, AllIcons.I_TRASH); + resetButton.withCallback(() -> { + menu.clearContents(); + contentsCleared(); + menu.sendClearPacket(); + }); confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); + confirmButton.withCallback(() -> { + minecraft.player.closeContainer(); + }); - widgets.add(resetButton); - widgets.add(confirmButton); + addRenderableWidget(resetButton); + addRenderableWidget(confirmButton); extraAreas = ImmutableList.of( new Rect2i(x + background.width, y + background.height - 40, 80, 48) @@ -60,7 +66,7 @@ public abstract class AbstractFilterScreen ex } @Override - protected void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks) { + protected void renderBg(PoseStack ms, float partialTicks, int mouseX, int mouseY) { int invX = getLeftOfCentered(PLAYER_INVENTORY.width); int invY = topPos + background.height + 4; renderPlayerInventory(ms, invX, invY); @@ -68,7 +74,7 @@ public abstract class AbstractFilterScreen ex int x = leftPos; int y = topPos; - background.draw(ms, this, x, y); + background.render(ms, x, y, this); drawCenteredString(ms, font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); GuiGameElement.of(menu.contentHolder) @@ -79,27 +85,16 @@ public abstract class AbstractFilterScreen ex @Override protected void containerTick() { - handleTooltips(); - handleIndicators(); - if (!menu.player.getMainHandItem() .equals(menu.contentHolder, false)) - minecraft.player.closeContainer(); + menu.player.closeContainer(); + + super.containerTick(); + + handleTooltips(); + handleIndicators(); } - public void handleIndicators() { - List tooltipButtons = getTooltipButtons(); - for (IconButton button : tooltipButtons) - button.active = isButtonEnabled(button); - for (AbstractWidget w : widgets) - if (w instanceof Indicator) - ((Indicator) w).state = isIndicatorOn((Indicator) w) ? State.ON : State.OFF; - } - - protected abstract boolean isButtonEnabled(IconButton button); - - protected abstract boolean isIndicatorOn(Indicator indicator); - protected void handleTooltips() { List tooltipButtons = getTooltipButtons(); @@ -120,6 +115,17 @@ public abstract class AbstractFilterScreen ex } } + public void handleIndicators() { + for (IconButton button : getTooltipButtons()) + button.active = isButtonEnabled(button); + for (Indicator indicator : getIndicators()) + indicator.state = isIndicatorOn(indicator) ? State.ON : State.OFF; + } + + protected abstract boolean isButtonEnabled(IconButton button); + + protected abstract boolean isIndicatorOn(Indicator indicator); + protected List getTooltipButtons() { return Collections.emptyList(); } @@ -128,6 +134,10 @@ public abstract class AbstractFilterScreen ex return Collections.emptyList(); } + protected List getIndicators() { + return Collections.emptyList(); + } + private void fillToolTip(IconButton button, Component tooltip) { if (!button.isHovered()) return; @@ -135,26 +145,6 @@ public abstract class AbstractFilterScreen ex tip.addAll(TooltipHelper.cutTextComponent(tooltip, GRAY, GRAY)); } - @Override - public boolean mouseClicked(double x, double y, int button) { - boolean mouseClicked = super.mouseClicked(x, y, button); - - if (button == 0) { - if (confirmButton.isHovered()) { - minecraft.player.closeContainer(); - return true; - } - if (resetButton.isHovered()) { - menu.clearContents(); - contentsCleared(); - menu.sendClearPacket(); - return true; - } - } - - return mouseClicked; - } - protected void contentsCleared() {} protected void sendOptionUpdate(Option option) { diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/AttributeFilterScreen.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/AttributeFilterScreen.java index 465ef40e1..38c99970b 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/AttributeFilterScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/AttributeFilterScreen.java @@ -10,10 +10,10 @@ import com.simibubi.create.content.logistics.item.filter.AttributeFilterContaine import com.simibubi.create.content.logistics.item.filter.FilterScreenPacket.Option; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.widgets.IconButton; -import com.simibubi.create.foundation.gui.widgets.Indicator; -import com.simibubi.create.foundation.gui.widgets.Label; -import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput; +import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.gui.widget.Indicator; +import com.simibubi.create.foundation.gui.widget.Label; +import com.simibubi.create.foundation.gui.widget.SelectionScrollInput; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.Pair; @@ -30,11 +30,6 @@ public class AttributeFilterScreen extends AbstractFilterScreen attributesOfItem = new ArrayList<>(); private List selectedAttributes = new ArrayList<>(); @@ -61,29 +61,47 @@ public class AttributeFilterScreen extends AbstractFilterScreen { + menu.whitelistMode = WhitelistMode.WHITELIST_DISJ; + sendOptionUpdate(Option.WHITELIST); + }); whitelistDis.setToolTip(allowDisN); whitelistCon = new IconButton(x + 65, y + 59, AllIcons.I_WHITELIST_AND); + whitelistCon.withCallback(() -> { + menu.whitelistMode = WhitelistMode.WHITELIST_CONJ; + sendOptionUpdate(Option.WHITELIST2); + }); whitelistCon.setToolTip(allowConN); blacklist = new IconButton(x + 83, y + 59, AllIcons.I_WHITELIST_NOT); + blacklist.withCallback(() -> { + menu.whitelistMode = WhitelistMode.BLACKLIST; + sendOptionUpdate(Option.BLACKLIST); + }); blacklist.setToolTip(denyN); whitelistDisIndicator = new Indicator(x + 47, y + 53, TextComponent.EMPTY); whitelistConIndicator = new Indicator(x + 65, y + 53, TextComponent.EMPTY); blacklistIndicator = new Indicator(x + 83, y + 53, TextComponent.EMPTY); - widgets.addAll(Arrays.asList(blacklist, whitelistCon, whitelistDis, blacklistIndicator, whitelistConIndicator, - whitelistDisIndicator)); + addRenderableWidgets(blacklist, whitelistCon, whitelistDis, blacklistIndicator, whitelistConIndicator, + whitelistDisIndicator); - widgets.add(add = new IconButton(x + 182, y + 21, AllIcons.I_ADD)); - widgets.add(addInverted = new IconButton(x + 200, y + 21, AllIcons.I_ADD_INVERTED_ATTRIBUTE)); + addRenderableWidget(add = new IconButton(x + 182, y + 21, AllIcons.I_ADD)); + addRenderableWidget(addInverted = new IconButton(x + 200, y + 21, AllIcons.I_ADD_INVERTED_ATTRIBUTE)); + add.withCallback(() -> { + handleAddedAttibute(false); + }); add.setToolTip(addDESC); + addInverted.withCallback(() -> { + handleAddedAttibute(true); + }); addInverted.setToolTip(addInvertedDESC); handleIndicators(); @@ -95,8 +113,8 @@ public class AttributeFilterScreen extends AbstractFilterScreen getIndicators() { + return Arrays.asList(blacklistIndicator, whitelistConIndicator, whitelistDisIndicator); } protected boolean handleAddedAttibute(boolean inverted) { diff --git a/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterScreen.java b/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterScreen.java index b3ca41fc6..ad0567943 100644 --- a/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterScreen.java +++ b/src/main/java/com/simibubi/create/content/logistics/item/filter/FilterScreen.java @@ -6,8 +6,8 @@ import java.util.List; import com.simibubi.create.content.logistics.item.filter.FilterScreenPacket.Option; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.widgets.IconButton; -import com.simibubi.create.foundation.gui.widgets.Indicator; +import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.gui.widget.Indicator; import com.simibubi.create.foundation.utility.Lang; import net.minecraft.network.chat.Component; @@ -47,58 +47,40 @@ public class FilterScreen extends AbstractFilterScreen { int y = topPos; blacklist = new IconButton(x + 18, y + 73, AllIcons.I_BLACKLIST); + blacklist.withCallback(() -> { + menu.blacklist = true; + sendOptionUpdate(Option.BLACKLIST); + }); blacklist.setToolTip(denyN); whitelist = new IconButton(x + 36, y + 73, AllIcons.I_WHITELIST); + whitelist.withCallback(() -> { + menu.blacklist = false; + sendOptionUpdate(Option.WHITELIST); + }); whitelist.setToolTip(allowN); blacklistIndicator = new Indicator(x + 18, y + 67, TextComponent.EMPTY); whitelistIndicator = new Indicator(x + 36, y + 67, TextComponent.EMPTY); - widgets.addAll(Arrays.asList(blacklist, whitelist, blacklistIndicator, whitelistIndicator)); + addRenderableWidgets(blacklist, whitelist, blacklistIndicator, whitelistIndicator); respectNBT = new IconButton(x + 60, y + 73, AllIcons.I_RESPECT_NBT); + respectNBT.withCallback(() -> { + menu.respectNBT = true; + sendOptionUpdate(Option.RESPECT_DATA); + }); respectNBT.setToolTip(respectDataN); ignoreNBT = new IconButton(x + 78, y + 73, AllIcons.I_IGNORE_NBT); + ignoreNBT.withCallback(() -> { + menu.respectNBT = false; + sendOptionUpdate(Option.IGNORE_DATA); + }); ignoreNBT.setToolTip(ignoreDataN); respectNBTIndicator = new Indicator(x + 60, y + 67, TextComponent.EMPTY); ignoreNBTIndicator = new Indicator(x + 78, y + 67, TextComponent.EMPTY); - widgets.addAll(Arrays.asList(respectNBT, ignoreNBT, respectNBTIndicator, ignoreNBTIndicator)); + addRenderableWidgets(respectNBT, ignoreNBT, respectNBTIndicator, ignoreNBTIndicator); handleIndicators(); } - @Override - public boolean mouseClicked(double x, double y, int button) { - boolean mouseClicked = super.mouseClicked(x, y, button); - - if (button != 0) - return mouseClicked; - - if (blacklist.isHovered()) { - menu.blacklist = true; - sendOptionUpdate(Option.BLACKLIST); - return true; - } - - if (whitelist.isHovered()) { - menu.blacklist = false; - sendOptionUpdate(Option.WHITELIST); - return true; - } - - if (respectNBT.isHovered()) { - menu.respectNBT = true; - sendOptionUpdate(Option.RESPECT_DATA); - return true; - } - - if (ignoreNBT.isHovered()) { - menu.respectNBT = false; - sendOptionUpdate(Option.IGNORE_DATA); - return true; - } - - return mouseClicked; - } - @Override protected List getTooltipButtons() { return Arrays.asList(blacklist, whitelist, respectNBT, ignoreNBT); @@ -109,6 +91,11 @@ public class FilterScreen extends AbstractFilterScreen { return Arrays.asList(denyDESC.plainCopy(), allowDESC.plainCopy(), respectDataDESC.plainCopy(), ignoreDataDESC.plainCopy()); } + @Override + protected List getIndicators() { + return Arrays.asList(blacklistIndicator, whitelistIndicator, respectNBTIndicator, ignoreNBTIndicator); + } + @Override protected boolean isButtonEnabled(IconButton button) { if (button == blacklist) diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableContainer.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableContainer.java index f8f33d40b..fa63ebf63 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableContainer.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableContainer.java @@ -2,51 +2,73 @@ package com.simibubi.create.content.schematics.block; import com.simibubi.create.AllContainerTypes; import com.simibubi.create.AllItems; +import com.simibubi.create.foundation.gui.container.ContainerBase; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.items.SlotItemHandler; -public class SchematicTableContainer extends AbstractContainerMenu { +public class SchematicTableContainer extends ContainerBase { - private SchematicTableTileEntity te; private Slot inputSlot; private Slot outputSlot; - private Player player; public SchematicTableContainer(MenuType type, int id, Inventory inv, FriendlyByteBuf extraData) { - super(type, id); - player = inv.player; - ClientLevel world = Minecraft.getInstance().level; - BlockEntity tileEntity = world.getBlockEntity(extraData.readBlockPos()); - if (tileEntity instanceof SchematicTableTileEntity) { - this.te = (SchematicTableTileEntity) tileEntity; - this.te.handleUpdateTag(extraData.readNbt()); - init(); - } + super(type, id, inv, extraData); } public SchematicTableContainer(MenuType type, int id, Inventory inv, SchematicTableTileEntity te) { - super(type, id); - this.player = inv.player; - this.te = te; - init(); + super(type, id, inv, te); } public static SchematicTableContainer create(int id, Inventory inv, SchematicTableTileEntity te) { return new SchematicTableContainer(AllContainerTypes.SCHEMATIC_TABLE.get(), id, inv, te); } - protected void init() { - inputSlot = new SlotItemHandler(te.inventory, 0, 21, 57) { + public boolean canWrite() { + return inputSlot.hasItem() && !outputSlot.hasItem(); + } + + @Override + public ItemStack quickMoveStack(Player playerIn, int index) { + Slot clickedSlot = getSlot(index); + if (!clickedSlot.hasItem()) + return ItemStack.EMPTY; + + ItemStack stack = clickedSlot.getItem(); + if (index < 2) + moveItemStackTo(stack, 2, slots.size(), false); + else + moveItemStackTo(stack, 0, 1, false); + + return ItemStack.EMPTY; + } + + @Override + protected SchematicTableTileEntity createOnClient(FriendlyByteBuf extraData) { + ClientLevel world = Minecraft.getInstance().level; + BlockEntity tileEntity = world.getBlockEntity(extraData.readBlockPos()); + if (tileEntity instanceof SchematicTableTileEntity schematicTable) { + schematicTable.handleUpdateTag(extraData.readNbt()); + return schematicTable; + } + return null; + } + + @Override + protected void initAndReadInventory(SchematicTableTileEntity contentHolder) { + } + + @Override + protected void addSlots() { + inputSlot = new SlotItemHandler(contentHolder.inventory, 0, 21, 57) { @Override public boolean mayPlace(ItemStack stack) { return AllItems.EMPTY_SCHEMATIC.isIn(stack) || AllItems.SCHEMATIC_AND_QUILL.isIn(stack) @@ -54,7 +76,7 @@ public class SchematicTableContainer extends AbstractContainerMenu { } }; - outputSlot = new SlotItemHandler(te.inventory, 1, 166, 57) { + outputSlot = new SlotItemHandler(contentHolder.inventory, 1, 166, 57) { @Override public boolean mayPlace(ItemStack stack) { return false; @@ -74,36 +96,10 @@ public class SchematicTableContainer extends AbstractContainerMenu { for (int hotbarSlot = 0; hotbarSlot < 9; ++hotbarSlot) { this.addSlot(new Slot(player.getInventory(), hotbarSlot, 38 + hotbarSlot * 18, 163)); } - - broadcastChanges(); - } - - public boolean canWrite() { - return inputSlot.hasItem() && !outputSlot.hasItem(); } @Override - public boolean stillValid(Player player) { - return te != null && te.canPlayerUse(player); - } - - @Override - public ItemStack quickMoveStack(Player playerIn, int index) { - Slot clickedSlot = getSlot(index); - if (!clickedSlot.hasItem()) - return ItemStack.EMPTY; - - ItemStack stack = clickedSlot.getItem(); - if (index < 2) - moveItemStackTo(stack, 2, slots.size(), false); - else - moveItemStackTo(stack, 0, 1, false); - - return ItemStack.EMPTY; - } - - public SchematicTableTileEntity getTileEntity() { - return te; + protected void saveData(SchematicTableTileEntity contentHolder) { } } diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java index 955542e22..028d62118 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableScreen.java @@ -12,14 +12,14 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateClient; import com.simibubi.create.content.schematics.ClientSchematicLoader; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.IconButton; -import com.simibubi.create.foundation.gui.widgets.Label; -import com.simibubi.create.foundation.gui.widgets.ScrollInput; -import com.simibubi.create.foundation.gui.widgets.SelectionScrollInput; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.gui.widget.Label; +import com.simibubi.create.foundation.gui.widget.ScrollInput; +import com.simibubi.create.foundation.gui.widget.SelectionScrollInput; import com.simibubi.create.foundation.utility.Lang; import net.minecraft.Util; @@ -32,8 +32,14 @@ import net.minecraft.world.item.ItemStack; public class SchematicTableScreen extends AbstractSimiContainerScreen { + private final Component uploading = Lang.translate("gui.schematicTable.uploading"); + private final Component finished = Lang.translate("gui.schematicTable.finished"); + private final Component refresh = Lang.translate("gui.schematicTable.refresh"); + private final Component folder = Lang.translate("gui.schematicTable.open_folder"); + private final Component noSchematics = Lang.translate("gui.schematicTable.noSchematics"); + private final Component availableSchematicsTitle = Lang.translate("gui.schematicTable.availableSchematics"); + protected AllGuiTextures background; - private List extraAreas = Collections.emptyList(); private ScrollInput schematicsArea; private IconButton confirmButton; @@ -41,18 +47,14 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen extraAreas = Collections.emptyList(); + public SchematicTableScreen(SchematicTableContainer container, Inventory playerInventory, Component title) { super(container, playerInventory, title); @@ -64,7 +66,6 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen availableSchematics = CreateClient.SCHEMATIC_SENDER.getAvailableSchematics(); @@ -79,20 +80,52 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen { + if (menu.canWrite() && schematicsArea != null) { + ClientSchematicLoader schematicSender = CreateClient.SCHEMATIC_SENDER; + lastChasingProgress = chasingProgress = progress = 0; + List availableSchematics1 = schematicSender.getAvailableSchematics(); + Component schematic = availableSchematics1.get(schematicsArea.getState()); + schematicSender.startNewUpload(schematic.getContents()); + } + }); folderButton = new IconButton(x + 21, y + 21, AllIcons.I_OPEN_FOLDER); + folderButton.withCallback(() -> { + Util.getPlatform() + .openFile(Paths.get("schematics/") + .toFile()); + }); folderButton.setToolTip(folder); refreshButton = new IconButton(x + 207, y + 21, AllIcons.I_REFRESH); + refreshButton.withCallback(() -> { + ClientSchematicLoader schematicSender = CreateClient.SCHEMATIC_SENDER; + schematicSender.refresh(); + List availableSchematics1 = schematicSender.getAvailableSchematics(); + removeWidget(schematicsArea); + + if (!availableSchematics1.isEmpty()) { + schematicsArea = new SelectionScrollInput(leftPos + 45, topPos + 21, 139, 18) + .forOptions(availableSchematics1) + .titled(availableSchematicsTitle.plainCopy()) + .writingTo(schematicsLabel); + schematicsArea.onChanged(); + addRenderableWidget(schematicsArea); + } else { + schematicsArea = null; + schematicsLabel.text = TextComponent.EMPTY; + } + }); refreshButton.setToolTip(refresh); - widgets.add(confirmButton); - widgets.add(folderButton); - widgets.add(refreshButton); + addRenderableWidget(confirmButton); + addRenderableWidget(folderButton); + addRenderableWidget(refreshButton); extraAreas = ImmutableList.of( new Rect2i(x + background.width, y + background.height - 40, 48, 48), @@ -101,7 +134,7 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen availableSchematics = schematicSender.getAvailableSchematics(); - Component schematic = availableSchematics.get(schematicsArea.getState()); - schematicSender.startNewUpload(schematic.getContents()); - } - - if (folderButton.isHovered()) { - Util.getPlatform() - .openFile(Paths.get("schematics/") - .toFile()); - } - - if (refreshButton.isHovered()) { - schematicSender.refresh(); - List availableSchematics = schematicSender.getAvailableSchematics(); - widgets.remove(schematicsArea); - - if (!availableSchematics.isEmpty()) { - schematicsArea = new SelectionScrollInput(leftPos + 45, topPos + 21, 139, 18) - .forOptions(availableSchematics) - .titled(availableSchematicsTitle.plainCopy()) - .writingTo(schematicsLabel); - schematicsArea.onChanged(); - widgets.add(schematicsArea); - } else { - schematicsArea = null; - schematicsLabel.text = TextComponent.EMPTY; - } - } - - return super.mouseClicked(p_mouseClicked_1_, p_mouseClicked_3_, p_mouseClicked_5_); - } - @Override public List getExtraAreas() { return extraAreas; diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableTileEntity.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableTileEntity.java index dd129065b..05da1f186 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableTileEntity.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicTableTileEntity.java @@ -2,9 +2,9 @@ package com.simibubi.create.content.schematics.block; import java.util.List; -import com.simibubi.create.foundation.gui.IInteractionChecker; import com.simibubi.create.foundation.tileEntity.SmartTileEntity; import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour; +import com.simibubi.create.foundation.utility.IInteractionChecker; import com.simibubi.create.foundation.utility.Lang; import net.minecraft.core.BlockPos; diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonContainer.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonContainer.java index bf80339e9..62f66221e 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonContainer.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonContainer.java @@ -1,82 +1,64 @@ package com.simibubi.create.content.schematics.block; import com.simibubi.create.AllContainerTypes; +import com.simibubi.create.foundation.gui.container.ContainerBase; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.MenuType; import net.minecraft.world.inventory.Slot; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.items.SlotItemHandler; -public class SchematicannonContainer extends AbstractContainerMenu { - - private SchematicannonTileEntity te; - private Player player; +public class SchematicannonContainer extends ContainerBase { public SchematicannonContainer(MenuType type, int id, Inventory inv, FriendlyByteBuf buffer) { - super(type, id); - player = inv.player; - ClientLevel world = Minecraft.getInstance().level; - BlockEntity tileEntity = world.getBlockEntity(buffer.readBlockPos()); - if (tileEntity instanceof SchematicannonTileEntity) { - this.te = (SchematicannonTileEntity) tileEntity; - this.te.handleUpdateTag(buffer.readNbt()); - init(); - } + super(type, id, inv, buffer); } public SchematicannonContainer(MenuType type, int id, Inventory inv, SchematicannonTileEntity te) { - super(type, id); - player = inv.player; - this.te = te; - init(); + super(type, id, inv, te); } public static SchematicannonContainer create(int id, Inventory inv, SchematicannonTileEntity te) { return new SchematicannonContainer(AllContainerTypes.SCHEMATICANNON.get(), id, inv, te); } - protected void init() { + @Override + protected SchematicannonTileEntity createOnClient(FriendlyByteBuf extraData) { + ClientLevel world = Minecraft.getInstance().level; + BlockEntity tileEntity = world.getBlockEntity(extraData.readBlockPos()); + if (tileEntity instanceof SchematicannonTileEntity schematicannon) { + schematicannon.handleUpdateTag(extraData.readNbt()); + return schematicannon; + } + return null; + } + + @Override + protected void initAndReadInventory(SchematicannonTileEntity contentHolder) { + } + + @Override + protected void addSlots() { int x = 0; int y = 0; - addSlot(new SlotItemHandler(te.inventory, 0, x + 15, y + 65)); - addSlot(new SlotItemHandler(te.inventory, 1, x + 171, y + 65)); - addSlot(new SlotItemHandler(te.inventory, 2, x + 134, y + 19)); - addSlot(new SlotItemHandler(te.inventory, 3, x + 174, y + 19)); - addSlot(new SlotItemHandler(te.inventory, 4, x + 15, y + 19)); + addSlot(new SlotItemHandler(contentHolder.inventory, 0, x + 15, y + 65)); + addSlot(new SlotItemHandler(contentHolder.inventory, 1, x + 171, y + 65)); + addSlot(new SlotItemHandler(contentHolder.inventory, 2, x + 134, y + 19)); + addSlot(new SlotItemHandler(contentHolder.inventory, 3, x + 174, y + 19)); + addSlot(new SlotItemHandler(contentHolder.inventory, 4, x + 15, y + 19)); - int invX = 37; - int invY = 161; - - // player Slots - for (int row = 0; row < 3; ++row) - for (int col = 0; col < 9; ++col) - addSlot(new Slot(player.getInventory(), col + row * 9 + 9, invX + col * 18, invY + row * 18)); - for (int hotbarSlot = 0; hotbarSlot < 9; ++hotbarSlot) - addSlot(new Slot(player.getInventory(), hotbarSlot, invX + hotbarSlot * 18, invY + 58)); - - broadcastChanges(); + addPlayerSlots(37, 161); } @Override - public boolean stillValid(Player player) { - return te != null && te.canPlayerUse(player); - } - - @Override - public void removed(Player playerIn) { - super.removed(playerIn); - } - - public SchematicannonTileEntity getTileEntity() { - return te; + protected void saveData(SchematicannonTileEntity contentHolder) { } @Override diff --git a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonScreen.java b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonScreen.java index 5122379e9..177000a05 100644 --- a/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonScreen.java +++ b/src/main/java/com/simibubi/create/content/schematics/block/SchematicannonScreen.java @@ -14,13 +14,13 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.schematics.packet.ConfigureSchematicannonPacket; import com.simibubi.create.content.schematics.packet.ConfigureSchematicannonPacket.Option; -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.IconButton; -import com.simibubi.create.foundation.gui.widgets.Indicator; -import com.simibubi.create.foundation.gui.widgets.Indicator.State; +import com.simibubi.create.foundation.gui.container.AbstractSimiContainerScreen; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.IconButton; +import com.simibubi.create.foundation.gui.widget.Indicator; +import com.simibubi.create.foundation.gui.widget.Indicator.State; import com.simibubi.create.foundation.item.ItemDescription.Palette; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.networking.AllPackets; @@ -39,6 +39,19 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen replaceLevelIndicators; protected Vector replaceLevelButtons; @@ -54,28 +67,16 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen extraAreas = Collections.emptyList(); - protected List placementSettingWidgets; - - private final Component listPrinter = Lang.translate("gui.schematicannon.listPrinter"); - private final String _gunpowderLevel = "gui.schematicannon.gunpowderLevel"; - private final String _shotsRemaining = "gui.schematicannon.shotsRemaining"; - private final String _showSettings = "gui.schematicannon.showOptions"; - private final String _shotsRemainingWithBackup = "gui.schematicannon.shotsRemainingWithBackup"; - - private final String _slotGunpowder = "gui.schematicannon.slot.gunpowder"; - private final String _slotListPrinter = "gui.schematicannon.slot.listPrinter"; - private final String _slotSchematic = "gui.schematicannon.slot.schematic"; - - private final Component optionEnabled = Lang.translate("gui.schematicannon.optionEnabled"); - private final Component optionDisabled = Lang.translate("gui.schematicannon.optionDisabled"); - - private final ItemStack renderedItem = AllBlocks.SCHEMATICANNON.asStack(); - private IconButton confirmButton; private IconButton showSettingsButton; private Indicator showSettingsIndicator; + protected List placementSettingWidgets; + + private final ItemStack renderedItem = AllBlocks.SCHEMATICANNON.asStack(); + + private List extraAreas = Collections.emptyList(); + public SchematicannonScreen(SchematicannonContainer container, Inventory inventory, Component title) { super(container, inventory, title); placementSettingWidgets = new ArrayList<>(); @@ -84,31 +85,46 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen { + sendOptionUpdate(Option.PLAY, true); + }); playIndicator = new Indicator(x + 75, y + 79, TextComponent.EMPTY); pauseButton = new IconButton(x + 93, y + 86, AllIcons.I_PAUSE); + pauseButton.withCallback(() -> { + sendOptionUpdate(Option.PAUSE, true); + }); pauseIndicator = new Indicator(x + 93, y + 79, TextComponent.EMPTY); resetButton = new IconButton(x + 111, y + 86, AllIcons.I_STOP); + resetButton.withCallback(() -> { + sendOptionUpdate(Option.STOP, true); + }); resetIndicator = new Indicator(x + 111, y + 79, TextComponent.EMPTY); resetIndicator.state = State.RED; - Collections.addAll(widgets, playButton, playIndicator, pauseButton, pauseIndicator, resetButton, + addRenderableWidgets(playButton, playIndicator, pauseButton, pauseIndicator, resetButton, resetIndicator); confirmButton = new IconButton(x + 180, y + 117, AllIcons.I_CONFIRM); - widgets.add(confirmButton); + confirmButton.withCallback(() -> { + minecraft.player.closeContainer(); + }); + addRenderableWidget(confirmButton); showSettingsButton = new IconButton(x + 9, y + 117, AllIcons.I_PLACEMENT_SETTINGS); + showSettingsButton.withCallback(() -> { + showSettingsIndicator.state = placementSettingsHidden() ? State.GREEN : State.OFF; + initPlacementSettings(); + }); showSettingsButton.setToolTip(Lang.translate(_showSettings)); - widgets.add(showSettingsButton); + addRenderableWidget(showSettingsButton); showSettingsIndicator = new Indicator(x + 9, y + 111, TextComponent.EMPTY); - widgets.add(showSettingsIndicator); + addRenderableWidget(showSettingsIndicator); extraAreas = ImmutableList.of(new Rect2i(x + BG_TOP.width, y + BG_TOP.height + BG_BOTTOM.height - 62, 84, 92)); @@ -116,7 +132,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen { + if (menu.contentHolder.replaceMode != replaceMode) + sendOptionUpdate(Option.values()[replaceMode], true); + }); + replaceLevelButton.setToolTip(toolTips.get(i)); + replaceLevelButtons.add(replaceLevelButton); } placementSettingWidgets.addAll(replaceLevelButtons); placementSettingWidgets.addAll(replaceLevelIndicators); // Other Settings skipMissingButton = new IconButton(x + 111, y + 117, AllIcons.I_SKIP_MISSING); + skipMissingButton.withCallback(() -> { + sendOptionUpdate(Option.SKIP_MISSING, !menu.contentHolder.skipMissing); + }); skipMissingButton.setToolTip(Lang.translate("gui.schematicannon.option.skipMissing")); skipMissingIndicator = new Indicator(x + 111, y + 111, TextComponent.EMPTY); Collections.addAll(placementSettingWidgets, skipMissingButton, skipMissingIndicator); skipTilesButton = new IconButton(x + 129, y + 117, AllIcons.I_SKIP_TILES); + skipTilesButton.withCallback(() -> { + sendOptionUpdate(Option.SKIP_TILES, !menu.contentHolder.replaceTileEntities); + }); skipTilesButton.setToolTip(Lang.translate("gui.schematicannon.option.skipTileEntities")); skipTilesIndicator = new Indicator(x + 129, y + 111, TextComponent.EMPTY); Collections.addAll(placementSettingWidgets, skipTilesButton, skipTilesIndicator); - widgets.addAll(placementSettingWidgets); + addRenderableWidgets(placementSettingWidgets); } protected boolean placementSettingsHidden() { @@ -164,11 +191,15 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen= paperX && mouseY >= paperY && mouseX <= paperX + 16 && mouseY <= paperY + 16) renderTooltip(matrixStack, listPrinter, mouseX, mouseY); - super.renderWindowForeground(matrixStack, mouseX, mouseY, partialTicks); + super.renderForeground(matrixStack, mouseX, mouseY, partialTicks); } protected List getFuelLevelTooltip(SchematicannonTileEntity te) { @@ -380,41 +411,8 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen rotationOptions = Lang.translatedOptions("schematic.rotation", "none", "cw90", "cw180", "cw270"); private final List mirrorOptions = @@ -42,12 +34,18 @@ public class SchematicEditScreen extends AbstractSimiScreen { private final Component rotationLabel = Lang.translate("schematic.rotation"); private final Component mirrorLabel = Lang.translate("schematic.mirror"); + private AllGuiTextures background; + + private EditBox xInput; + private EditBox yInput; + private EditBox zInput; + private IconButton confirmButton; + private ScrollInput rotationArea; private ScrollInput mirrorArea; private SchematicHandler handler; public SchematicEditScreen() { - super(); background = AllGuiTextures.SCHEMATIC; handler = CreateClient.SCHEMATIC_HANDLER; } @@ -57,7 +55,6 @@ public class SchematicEditScreen extends AbstractSimiScreen { setWindowSize(background.width, background.height); setWindowOffset(-6, 0); super.init(); - widgets.clear(); int x = guiLeft; int y = guiTop; @@ -113,12 +110,15 @@ public class SchematicEditScreen extends AbstractSimiScreen { .ordinal()) .writingTo(labelM); - Collections.addAll(widgets, xInput, yInput, zInput); - Collections.addAll(widgets, labelR, labelM, rotationArea, mirrorArea); + addRenderableWidgets(xInput, yInput, zInput); + addRenderableWidgets(labelR, labelM, rotationArea, mirrorArea); confirmButton = new IconButton(x + background.width - 33, y + background.height - 24, AllIcons.I_CONFIRM); - widgets.add(confirmButton); + confirmButton.withCallback(() -> { + onClose(); + }); + addRenderableWidget(confirmButton); } @Override @@ -155,7 +155,7 @@ public class SchematicEditScreen extends AbstractSimiScreen { int x = guiLeft; int y = guiTop; - background.draw(ms, this, x, y); + background.render(ms, x, y, this); String title = handler.getCurrentSchematicName(); drawCenteredString(ms, font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); @@ -196,14 +196,4 @@ public class SchematicEditScreen extends AbstractSimiScreen { } } - @Override - public boolean mouseClicked(double x, double y, int button) { - if (confirmButton.isHovered()) { - onClose(); - return true; - } - - return super.mouseClicked(x, y, button); - } - } diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHotbarSlotOverlay.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHotbarSlotOverlay.java index bcbbb76ab..09d6a6006 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicHotbarSlotOverlay.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicHotbarSlotOverlay.java @@ -16,7 +16,7 @@ public class SchematicHotbarSlotOverlay extends GuiComponent { int y = mainWindow.getGuiScaledHeight() - 19; RenderSystem.enableDepthTest(); matrixStack.pushPose(); - AllGuiTextures.SCHEMATIC_SLOT.draw(matrixStack, this, x + 20 * slot, y); + AllGuiTextures.SCHEMATIC_SLOT.render(matrixStack, x + 20 * slot, y, this); matrixStack.popPose(); } diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java index d5d9f612c..2e119f5b9 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicPromptScreen.java @@ -8,8 +8,8 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.widgets.IconButton; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.widget.IconButton; import com.simibubi.create.foundation.utility.Lang; import net.minecraft.client.gui.components.EditBox; @@ -38,7 +38,6 @@ public class SchematicPromptScreen extends AbstractSimiScreen { public void init() { setWindowSize(background.width, background.height); super.init(); - widgets.clear(); int x = guiLeft; int y = guiTop; @@ -49,23 +48,29 @@ public class SchematicPromptScreen extends AbstractSimiScreen { nameField.setBordered(false); nameField.setMaxLength(35); nameField.changeFocus(true); + addRenderableWidget(nameField); abort = new IconButton(x + 7, y + 53, AllIcons.I_TRASH); + abort.withCallback(() -> { + CreateClient.SCHEMATIC_AND_QUILL_HANDLER.discard(); + onClose(); + }); abort.setToolTip(abortLabel); - widgets.add(abort); + addRenderableWidget(abort); confirm = new IconButton(x + 158, y + 53, AllIcons.I_CONFIRM); + confirm.withCallback(() -> { + confirm(false); + }); confirm.setToolTip(confirmLabel); - widgets.add(confirm); + addRenderableWidget(confirm); convert = new IconButton(x + 180, y + 53, AllIcons.I_SCHEMATIC); + convert.withCallback(() -> { + confirm(true); + }); convert.setToolTip(convertLabel); - widgets.add(convert); - - widgets.add(confirm); - widgets.add(convert); - widgets.add(abort); - widgets.add(nameField); + addRenderableWidget(convert); } @Override @@ -73,8 +78,9 @@ public class SchematicPromptScreen extends AbstractSimiScreen { int x = guiLeft; int y = guiTop; - background.draw(ms, this, x, y); + background.render(ms, x, y, this); drawCenteredString(ms, font, title, x + (background.width - 8) / 2, y + 3, 0xFFFFFF); + GuiGameElement.of(AllItems.SCHEMATIC.asStack()) .at(x + 22, y + 23, 0) .render(ms); @@ -98,27 +104,9 @@ public class SchematicPromptScreen extends AbstractSimiScreen { return nameField.keyPressed(keyCode, p_keyPressed_2_, p_keyPressed_3_); } - @Override - public boolean mouseClicked(double x, double y, int button) { - if (confirm.isHovered()) { - confirm(false); - return true; - } - if (abort.isHovered()) { - CreateClient.SCHEMATIC_AND_QUILL_HANDLER.discard(); - minecraft.player.closeContainer(); - return true; - } - if (convert.isHovered()) { - confirm(true); - return true; - } - return super.mouseClicked(x, y, button); - } - private void confirm(boolean convertImmediately) { CreateClient.SCHEMATIC_AND_QUILL_HANDLER.saveSchematic(nameField.getValue(), convertImmediately); - minecraft.player.closeContainer(); + onClose(); } } diff --git a/src/main/java/com/simibubi/create/content/schematics/client/SchematicTransformation.java b/src/main/java/com/simibubi/create/content/schematics/client/SchematicTransformation.java index adc903023..75186528b 100644 --- a/src/main/java/com/simibubi/create/content/schematics/client/SchematicTransformation.java +++ b/src/main/java/com/simibubi/create/content/schematics/client/SchematicTransformation.java @@ -4,10 +4,10 @@ import static java.lang.Math.abs; import com.jozufozu.flywheel.util.transform.MatrixTransformStack; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingAngle; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingAngle; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction.Axis; diff --git a/src/main/java/com/simibubi/create/content/schematics/packet/ConfigureSchematicannonPacket.java b/src/main/java/com/simibubi/create/content/schematics/packet/ConfigureSchematicannonPacket.java index 624f8b40e..bb0a7b6a8 100644 --- a/src/main/java/com/simibubi/create/content/schematics/packet/ConfigureSchematicannonPacket.java +++ b/src/main/java/com/simibubi/create/content/schematics/packet/ConfigureSchematicannonPacket.java @@ -40,7 +40,7 @@ public class ConfigureSchematicannonPacket extends SimplePacketBase { if (player == null || !(player.containerMenu instanceof SchematicannonContainer)) return; - SchematicannonTileEntity te = ((SchematicannonContainer) player.containerMenu).getTileEntity(); + SchematicannonTileEntity te = ((SchematicannonContainer) player.containerMenu).contentHolder; switch (option) { case DONT_REPLACE: case REPLACE_ANY: diff --git a/src/main/java/com/simibubi/create/content/schematics/packet/SchematicUploadPacket.java b/src/main/java/com/simibubi/create/content/schematics/packet/SchematicUploadPacket.java index 481f3a9af..36382ac32 100644 --- a/src/main/java/com/simibubi/create/content/schematics/packet/SchematicUploadPacket.java +++ b/src/main/java/com/simibubi/create/content/schematics/packet/SchematicUploadPacket.java @@ -71,7 +71,7 @@ public class SchematicUploadPacket extends SimplePacketBase { if (player == null) return; if (code == BEGIN) { - BlockPos pos = ((SchematicTableContainer) player.containerMenu).getTileEntity() + BlockPos pos = ((SchematicTableContainer) player.containerMenu).contentHolder .getBlockPos(); Create.SCHEMATIC_RECEIVER.handleNewUpload(player, schematic, size, pos); } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java index 03260c5c7..c6f77e4ad 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java @@ -12,16 +12,15 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.DelegatedStencilElement; import com.simibubi.create.foundation.gui.ScreenOpener; -import com.simibubi.create.foundation.gui.TextStencilElement; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; -import com.simibubi.create.foundation.gui.widgets.BoxWidget; +import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; +import com.simibubi.create.foundation.gui.element.TextStencilElement; +import com.simibubi.create.foundation.gui.widget.BoxWidget; import com.simibubi.create.foundation.item.TooltipHelper; import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.TextComponent; import net.minecraftforge.common.ForgeConfigSpec; @@ -142,12 +141,11 @@ public class BaseConfigScreen extends ConfigScreen { @Override protected void init() { - widgets.clear(); super.init(); returnOnClose = true; TextStencilElement clientText = new TextStencilElement(minecraft.font, new TextComponent(clientTile)).centered(true, true); - widgets.add(clientConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 - 30, 200, 16).showingElement(clientText)); + addRenderableWidget(clientConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 - 30, 200, 16).showingElement(clientText)); if (clientSpec != null) { clientConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.CLIENT, clientSpec))); @@ -159,7 +157,7 @@ public class BaseConfigScreen extends ConfigScreen { } TextStencilElement commonText = new TextStencilElement(minecraft.font, new TextComponent(commonTile)).centered(true, true); - widgets.add(commonConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15, 200, 16).showingElement(commonText)); + addRenderableWidget(commonConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15, 200, 16).showingElement(commonText)); if (commonSpec != null) { commonConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.COMMON, commonSpec))); @@ -171,13 +169,13 @@ public class BaseConfigScreen extends ConfigScreen { } TextStencilElement serverText = new TextStencilElement(minecraft.font, new TextComponent(serverTile)).centered(true, true); - widgets.add(serverConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 + 30, 200, 16).showingElement(serverText)); + addRenderableWidget(serverConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 + 30, 200, 16).showingElement(serverText)); if (serverSpec == null) { serverConfigWidget.active = false; serverConfigWidget.updateColorsFromState(); serverText.withElementRenderer(DISABLED_RENDERER); - } else if (Minecraft.getInstance().level == null) { + } else if (minecraft.level == null) { serverText.withElementRenderer(DISABLED_RENDERER); serverConfigWidget.getToolTip() .add(new TextComponent("Stored individually per World")); @@ -208,7 +206,7 @@ public class BaseConfigScreen extends ConfigScreen { .showingElement(titleText.at(0, 7)); title.active = false; - widgets.add(title); + addRenderableWidget(title); ConfigScreen.modID = this.modID; @@ -219,13 +217,13 @@ public class BaseConfigScreen extends ConfigScreen { .withElementRenderer(BoxWidget.gradientFactory.apply(goBack))); goBack.getToolTip() .add(new TextComponent("Go Back")); - widgets.add(goBack); + addRenderableWidget(goBack); TextStencilElement othersText = new TextStencilElement(minecraft.font, new TextComponent("Access Configs of other Mods")).centered(true, true); others = new BoxWidget(width / 2 - 100, height / 2 - 15 + 90, 200, 16).showingElement(othersText); othersText.withElementRenderer(BoxWidget.gradientFactory.apply(others)); others.withCallback(() -> linkTo(new ConfigModListScreen(this))); - widgets.add(others); + addRenderableWidget(others); } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigModListScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigModListScreen.java index 3e0e52e5a..fc9df4af3 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigModListScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigModListScreen.java @@ -6,10 +6,10 @@ import java.util.Locale; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.DelegatedStencilElement; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.Theme; -import com.simibubi.create.foundation.gui.widgets.BoxWidget; +import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; +import com.simibubi.create.foundation.gui.widget.BoxWidget; import com.simibubi.create.foundation.item.TooltipHelper; import net.minecraft.ChatFormatting; @@ -29,22 +29,15 @@ public class ConfigModListScreen extends ConfigScreen { super(parent); } - @Override - public void tick() { - super.tick(); - list.tick(); - } - @Override protected void init() { - widgets.clear(); super.init(); int listWidth = Math.min(width - 80, 300); list = new ConfigScreenList(minecraft, listWidth, height - 60, 15, height - 45, 40); list.setLeftPos(this.width / 2 - list.getWidth() / 2); - addWidget(list); + addRenderableWidget(list); allEntries = new ArrayList<>(); ModList.get().getMods().stream().map(IModInfo::getModId).forEach(id -> allEntries.add(new ModEntry(id, this))); @@ -64,20 +57,13 @@ public class ConfigModListScreen extends ConfigScreen { .withElementRenderer(BoxWidget.gradientFactory.apply(goBack))); goBack.getToolTip() .add(new TextComponent("Go Back")); - widgets.add(goBack); + addRenderableWidget(goBack); search = new HintableTextFieldWidget(font, width / 2 - listWidth / 2, height - 35, listWidth, 20); search.setResponder(this::updateFilter); search.setHint("Search.."); search.moveCursorToStart(); - widgets.add(search); - - } - - @Override - protected void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks) { - - list.render(ms, mouseX, mouseY, partialTicks); + addRenderableWidget(search); } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java index 36cd12ff4..d2e89b952 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java @@ -9,7 +9,6 @@ import javax.annotation.Nonnull; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.util.TriConsumer; -import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; @@ -23,10 +22,10 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.gui.AbstractSimiScreen; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.StencilElement; +import com.simibubi.create.foundation.gui.CreateMainMenuScreen; import com.simibubi.create.foundation.gui.UIRenderHelper; -import com.simibubi.create.foundation.gui.mainMenu.CreateMainMenuScreen; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.element.StencilElement; import com.simibubi.create.foundation.utility.animation.Force; import com.simibubi.create.foundation.utility.animation.PhysicalFloat; @@ -99,7 +98,7 @@ public abstract class ConfigScreen extends AbstractSimiScreen { @Override protected void prepareFrame() { RenderTarget thisBuffer = UIRenderHelper.framebuffer; - RenderTarget mainBuffer = Minecraft.getInstance().getMainRenderTarget(); + RenderTarget mainBuffer = minecraft.getMainRenderTarget(); GlCompat functions = Backend.getInstance().compat; functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, mainBuffer.frameBufferId); @@ -107,15 +106,13 @@ public abstract class ConfigScreen extends AbstractSimiScreen { functions.blit.blitFramebuffer(0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, 0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR); functions.fbo.bindFramebuffer(GlConst.GL_FRAMEBUFFER, thisBuffer.frameBufferId); - GL11.glClear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT); - + RenderSystem.clear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); } @Override protected void endFrame() { - RenderTarget thisBuffer = UIRenderHelper.framebuffer; - RenderTarget mainBuffer = Minecraft.getInstance().getMainRenderTarget(); + RenderTarget mainBuffer = minecraft.getMainRenderTarget(); GlCompat functions = Backend.getInstance().compat; functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, thisBuffer.frameBufferId); diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java index 7625042a8..e7843e290 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java @@ -7,15 +7,15 @@ import java.util.Locale; import java.util.Map; import java.util.Optional; -import org.lwjgl.opengl.GL11; - +import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.config.ui.entries.NumberEntry; -import com.simibubi.create.foundation.gui.TextStencilElement; import com.simibubi.create.foundation.gui.Theme; +import com.simibubi.create.foundation.gui.TickableGuiEventListener; import com.simibubi.create.foundation.gui.UIRenderHelper; +import com.simibubi.create.foundation.gui.element.TextStencilElement; import com.simibubi.create.foundation.utility.Color; import com.simibubi.create.foundation.utility.animation.LerpedFloat; @@ -30,7 +30,7 @@ import net.minecraft.network.chat.MutableComponent; import net.minecraft.network.chat.TextComponent; import net.minecraftforge.fmlclient.gui.GuiUtils; -public class ConfigScreenList extends ObjectSelectionList { +public class ConfigScreenList extends ObjectSelectionList implements TickableGuiEventListener { public static EditBox currentText; @@ -56,7 +56,7 @@ public class ConfigScreenList extends ObjectSelectionList { + public static abstract class Entry extends ObjectSelectionList.Entry implements TickableGuiEventListener { protected List listeners; protected Map annotations; protected String path; @@ -147,6 +148,7 @@ public class ConfigScreenList extends ObjectSelectionList l.charTyped(ch, code)); } + @Override public void tick() {} public List getGuiListeners() { @@ -249,13 +251,13 @@ public class ConfigScreenList extends ObjectSelectionList ((ValueEntry) e).onValueChange()); } - @Override - public void tick() { - super.tick(); - list.tick(); - } - @Override protected void init() { - widgets.clear(); super.init(); listWidth = Math.min(width - 80, 300); @@ -242,21 +235,21 @@ public class SubMenuConfigScreen extends ConfigScreen { goBack.showingElement(AllIcons.I_CONFIG_BACK.asStencil().withElementRenderer(BoxWidget.gradientFactory.apply(goBack))); goBack.getToolTip().add(new TextComponent("Go Back")); - widgets.add(resetAll); - widgets.add(saveChanges); - widgets.add(discardChanges); - widgets.add(goBack); + addRenderableWidget(resetAll); + addRenderableWidget(saveChanges); + addRenderableWidget(discardChanges); + addRenderableWidget(goBack); list = new ConfigScreenList(minecraft, listWidth, height - 80, 35, height - 45, 40); list.setLeftPos(this.width / 2 - list.getWidth() / 2); - addWidget(list); + addRenderableWidget(list); search = new ConfigTextField(font, width / 2 - listWidth / 2, height - 35, listWidth, 20); search.setResponder(this::updateFilter); search.setHint("Search.."); search.moveCursorToStart(); - widgets.add(search); + addRenderableWidget(search); configGroup.valueMap().forEach((key, obj) -> { String humanKey = toHumanReadable(key); @@ -331,20 +324,20 @@ public class SubMenuConfigScreen extends ConfigScreen { if (!canEdit) { list.children().forEach(e -> e.setEditable(false)); resetAll.active = false; - stencil.withStencilRenderer((ms, w, h, alpha) -> AllIcons.I_CONFIG_LOCKED.draw(ms, 0, 0)); + stencil.withStencilRenderer((ms, w, h, alpha) -> AllIcons.I_CONFIG_LOCKED.render(ms, 0, 0)); stencil.withElementRenderer((ms, w, h, alpha) -> UIRenderHelper.angledGradient(ms, 90, 8, 0, 16, 16, red)); serverLocked.withBorderColors(red); serverLocked.getToolTip().add(new TextComponent("Locked").withStyle(ChatFormatting.BOLD)); serverLocked.getToolTip().addAll(TooltipHelper.cutStringTextComponent("You do not have enough permissions to edit the server config. You can still look at the current values here though.", ChatFormatting.GRAY, ChatFormatting.GRAY)); } else { - stencil.withStencilRenderer((ms, w, h, alpha) -> AllIcons.I_CONFIG_UNLOCKED.draw(ms, 0, 0)); + stencil.withStencilRenderer((ms, w, h, alpha) -> AllIcons.I_CONFIG_UNLOCKED.render(ms, 0, 0)); stencil.withElementRenderer((ms, w, h, alpha) -> UIRenderHelper.angledGradient(ms, 90, 8, 0, 16, 16, green)); serverLocked.withBorderColors(green); serverLocked.getToolTip().add(new TextComponent("Unlocked").withStyle(ChatFormatting.BOLD)); serverLocked.getToolTip().addAll(TooltipHelper.cutStringTextComponent("You have enough permissions to edit the server config. Changes you make here will be synced with the server when you save them.", ChatFormatting.GRAY, ChatFormatting.GRAY)); } - widgets.add(serverLocked); + addRenderableWidget(serverLocked); } @Override @@ -353,8 +346,6 @@ public class SubMenuConfigScreen extends ConfigScreen { int x = width / 2; drawCenteredString(ms, minecraft.font, ConfigScreen.modID + " > " + type.toString().toLowerCase(Locale.ROOT) + " > " + title, x, 15, Theme.i(Theme.Key.TEXT)); - - list.render(ms, mouseX, mouseY, partialTicks); } @Override diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java index 06fa1b0b1..371100441 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java @@ -2,10 +2,10 @@ package com.simibubi.create.foundation.config.ui.entries; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.RenderElement; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; -import com.simibubi.create.foundation.gui.widgets.BoxWidget; +import com.simibubi.create.foundation.gui.element.RenderElement; +import com.simibubi.create.foundation.gui.widget.BoxWidget; import net.minecraftforge.common.ForgeConfigSpec; diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java index df1e22d99..cc70e436f 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java @@ -5,12 +5,12 @@ import java.util.Locale; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.config.ui.ConfigScreen; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.BoxElement; -import com.simibubi.create.foundation.gui.DelegatedStencilElement; -import com.simibubi.create.foundation.gui.TextStencilElement; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; -import com.simibubi.create.foundation.gui.widgets.BoxWidget; +import com.simibubi.create.foundation.gui.element.BoxElement; +import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; +import com.simibubi.create.foundation.gui.element.TextStencilElement; +import com.simibubi.create.foundation.gui.widget.BoxWidget; import net.minecraft.client.Minecraft; import net.minecraftforge.common.ForgeConfigSpec; diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java index 6fc3f8cc5..e90668608 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java @@ -8,9 +8,9 @@ import javax.annotation.Nullable; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.config.ui.ConfigTextField; -import com.simibubi.create.foundation.gui.TextStencilElement; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; +import com.simibubi.create.foundation.gui.element.TextStencilElement; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java index 9b7c46470..d86f98aaa 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java @@ -5,9 +5,9 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.config.ui.ConfigScreenList; import com.simibubi.create.foundation.config.ui.SubMenuConfigScreen; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.DelegatedStencilElement; import com.simibubi.create.foundation.gui.ScreenOpener; -import com.simibubi.create.foundation.gui.widgets.BoxWidget; +import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; +import com.simibubi.create.foundation.gui.widget.BoxWidget; import net.minecraftforge.common.ForgeConfigSpec; diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java index f3cc74f3b..1d3d89d3b 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java @@ -15,8 +15,8 @@ import com.simibubi.create.foundation.config.ui.ConfigHelper; import com.simibubi.create.foundation.config.ui.ConfigScreen; import com.simibubi.create.foundation.config.ui.ConfigScreenList; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.DelegatedStencilElement; -import com.simibubi.create.foundation.gui.widgets.BoxWidget; +import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; +import com.simibubi.create.foundation.gui.widget.BoxWidget; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.utility.Pair; diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java b/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java index 398ce6358..1b047f821 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateEntityBuilder.java @@ -34,7 +34,7 @@ public class CreateEntityBuilder extends EntityBuilder instance(NonNullSupplier> instanceFactory) { if (this.instanceFactory == null) { - DistExecutor.runWhenOn(Dist.CLIENT, () -> this::registerInstance); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::registerInstance); } this.instanceFactory = instanceFactory; @@ -46,7 +46,9 @@ public class CreateEntityBuilder extends EntityBuilder { NonNullSupplier> instanceFactory = this.instanceFactory; if (instanceFactory != null) { - InstancedRenderRegistry.getInstance().register(getEntry(), instanceFactory.get()); + InstancedRenderRegistry.getInstance() + .entity(getEntry()) + .factory(instanceFactory.get()); } }); diff --git a/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java b/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java index 0c275c180..179af9f0d 100644 --- a/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/data/CreateTileEntityBuilder.java @@ -32,7 +32,7 @@ public class CreateTileEntityBuilder extends TileEntit public CreateTileEntityBuilder instance(NonNullSupplier> instanceFactory) { if (this.instanceFactory == null) { - DistExecutor.runWhenOn(Dist.CLIENT, () -> this::registerInstance); + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> this::registerInstance); } this.instanceFactory = instanceFactory; @@ -45,7 +45,8 @@ public class CreateTileEntityBuilder extends TileEntit NonNullSupplier> instanceFactory = this.instanceFactory; if (instanceFactory != null) { InstancedRenderRegistry.getInstance() - .register(getEntry(), instanceFactory.get()); + .tile(getEntry()) + .factory(instanceFactory.get()); } }); } diff --git a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java deleted file mode 100644 index 09af199bd..000000000 --- a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiContainerScreen.java +++ /dev/null @@ -1,208 +0,0 @@ -package com.simibubi.create.foundation.gui; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.annotation.ParametersAreNonnullByDefault; - -import com.mojang.blaze3d.platform.InputConstants; -import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.AbstractWidget; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.gui.screens.inventory.ContainerScreen; -import net.minecraft.client.renderer.Rect2i; -import net.minecraft.network.chat.Component; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -@OnlyIn(Dist.CLIENT) -@ParametersAreNonnullByDefault -public abstract class AbstractSimiContainerScreen extends AbstractContainerScreen { - - protected List widgets; - protected int windowXOffset; - protected int windowYOffset; - - public AbstractSimiContainerScreen(T container, Inventory inv, Component title) { - super(container, inv, title); - widgets = new ArrayList<>(); - } - - protected void setWindowSize(int width, int height) { - this.imageWidth = width; - this.imageHeight = height; - } - - protected void setWindowOffset(int xOffset, int yOffset) { - windowXOffset = xOffset; - windowYOffset = yOffset; - } - - @Override - protected void init() { - super.init(); - leftPos += windowXOffset; - topPos += windowYOffset; - } - - @Override - protected void renderLabels(PoseStack p_230451_1_, int p_230451_2_, int p_230451_3_) { - // no-op to prevent screen- and inventory-title from being rendered at incorrect location - // could also set this.titleX/Y and this.playerInventoryTitleX/Y to the proper values instead - } - - @Override - public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { - partialTicks = Minecraft.getInstance() - .getFrameTime(); - renderBackground(matrixStack); - renderWindow(matrixStack, mouseX, mouseY, partialTicks); - - for (AbstractWidget widget : widgets) - widget.render(matrixStack, mouseX, mouseY, partialTicks); - - super.render(matrixStack, mouseX, mouseY, partialTicks); - - renderWindowForeground(matrixStack, mouseX, mouseY, partialTicks); - } - - @Override - public boolean mouseClicked(double x, double y, int button) { - boolean result = false; - for (AbstractWidget widget : widgets) { - if (widget.mouseClicked(x, y, button)) - result = true; - } - return result || super.mouseClicked(x, y, button); - } - - @Override - public boolean keyPressed(int code, int p_keyPressed_2_, int p_keyPressed_3_) { - for (AbstractWidget widget : widgets) { - if (widget.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_)) - return true; - } - - if (super.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_)) - return true; - - InputConstants.Key mouseKey = InputConstants.getKey(code, p_keyPressed_2_); - if (this.minecraft.options.keyInventory.isActiveAndMatches(mouseKey)) { - this.onClose(); - return true; - } - return false; - } - - @Override - public boolean charTyped(char character, int code) { - for (AbstractWidget widget : widgets) { - if (widget.charTyped(character, code)) - return true; - } - return super.charTyped(character, code); - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double delta) { - for (AbstractWidget widget : widgets) { - if (widget.mouseScrolled(mouseX, mouseY, delta)) - return true; - } - return super.mouseScrolled(mouseX, mouseY, delta); - } - - @Override - public boolean mouseReleased(double x, double y, int button) { - boolean result = false; - for (AbstractWidget widget : widgets) { - if (widget.mouseReleased(x, y, button)) - result = true; - } - return result | super.mouseReleased(x, y, button); - } - - protected abstract void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks); - - @Override - protected void renderBg(PoseStack p_230450_1_, float p_230450_2_, int p_230450_3_, int p_230450_4_) { - } - - protected void renderWindowForeground(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { - renderTooltip(matrixStack, mouseX, mouseY); - for (AbstractWidget widget : widgets) { - if (!widget.isHovered()) - continue; - - if (widget instanceof AbstractSimiWidget) { - if (!((AbstractSimiWidget) widget).getToolTip().isEmpty()) - renderComponentTooltip(matrixStack, ((AbstractSimiWidget) widget).getToolTip(), mouseX, mouseY); - - } else { - widget.renderToolTip(matrixStack, mouseX, mouseY); - } - } - } - - public double getItemCountTextScale() { - int guiScaleFactor = (int) minecraft.getWindow() - .getGuiScale(); - double scale = 1; - switch (guiScaleFactor) { - case 1: - scale = 2060 / 2048d; - break; - case 2: - scale = .5; - break; - case 3: - scale = .675; - break; - case 4: - scale = .75; - break; - default: - scale = ((float) guiScaleFactor - 1) / guiScaleFactor; - } - return scale; - } - - public int getLeftOfCentered(int textureWidth) { - return (width - textureWidth) / 2; - } - - public void renderPlayerInventory(PoseStack ms, int x, int y) { - AllGuiTextures.PLAYER_INVENTORY.draw(ms, this, x, y); - font.draw(ms, playerInventoryTitle, x + 8, y + 6, 0x404040); - } - - /** - * Used for moving JEI out of the way of extra things like Flexcrate renders. - * - *

This screen class must be bound to a SlotMover instance for this method to work. - * - * @return the space that the gui takes up besides the normal rectangle defined by {@link ContainerScreen}. - */ - public List getExtraAreas() { - return Collections.emptyList(); - } - - @Deprecated - protected void debugWindowArea(PoseStack matrixStack) { - fill(matrixStack, leftPos + imageWidth, topPos + imageHeight, leftPos, topPos, 0xD3D3D3D3); - } - - @Deprecated - protected void debugExtraAreas(PoseStack matrixStack) { - for (Rect2i area : getExtraAreas()) { - fill(matrixStack, area.getX() + area.getWidth(), area.getY() + area.getHeight(), area.getX(), area.getY(), 0xd3d3d3d3); - } - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java index 24854fc88..e0e423bac 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AbstractSimiScreen.java @@ -1,14 +1,14 @@ package com.simibubi.create.foundation.gui; -import java.util.ArrayList; +import java.util.Collection; import java.util.List; -import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; +import com.simibubi.create.foundation.gui.widget.AbstractSimiWidget; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.Widget; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; @@ -21,22 +21,26 @@ public abstract class AbstractSimiScreen extends Screen { protected int windowWidth, windowHeight; protected int windowXOffset, windowYOffset; protected int guiLeft, guiTop; - protected List widgets; protected AbstractSimiScreen(Component title) { super(title); - widgets = new ArrayList<>(); } protected AbstractSimiScreen() { - this(new TextComponent("")); + this(TextComponent.EMPTY); } + /** + * This method must be called before {@code super.init()}! + */ protected void setWindowSize(int width, int height) { windowWidth = width; windowHeight = height; } + /** + * This method must be called before {@code super.init()}! + */ protected void setWindowOffset(int xOffset, int yOffset) { windowXOffset = xOffset; windowYOffset = yOffset; @@ -44,7 +48,6 @@ public abstract class AbstractSimiScreen extends Screen { @Override protected void init() { - super.init(); guiLeft = (width - windowWidth) / 2; guiTop = (height - windowHeight) / 2; guiLeft += windowXOffset; @@ -53,16 +56,46 @@ public abstract class AbstractSimiScreen extends Screen { @Override public void tick() { - super.tick(); + for (GuiEventListener listener : children()) { + if (listener instanceof TickableGuiEventListener tickable) { + tickable.tick(); + } + } + } - widgets.stream().filter(w -> w instanceof AbstractSimiWidget).forEach(w -> ((AbstractSimiWidget) w).tick()); + @Override + public boolean isPauseScreen() { + return false; + } + + @SuppressWarnings("unchecked") + protected void addRenderableWidgets(W... widgets) { + for (W widget : widgets) { + addRenderableWidget(widget); + } + } + + protected void addRenderableWidgets(Collection widgets) { + for (W widget : widgets) { + addRenderableWidget(widget); + } + } + + protected void removeWidgets(GuiEventListener... widgets) { + for (GuiEventListener widget : widgets) { + removeWidget(widget); + } + } + + protected void removeWidgets(Collection widgets) { + for (GuiEventListener widget : widgets) { + removeWidget(widget); + } } @Override public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) { - partialTicks = partialTicks == 10 ? 0 - : Minecraft.getInstance() - .getFrameTime(); + partialTicks = minecraft.getFrameTime(); ms.pushPose(); @@ -70,8 +103,7 @@ public abstract class AbstractSimiScreen extends Screen { renderWindowBackground(ms, mouseX, mouseY, partialTicks); renderWindow(ms, mouseX, mouseY, partialTicks); - for (AbstractWidget widget : widgets) - widget.render(ms, mouseX, mouseY, partialTicks); + super.render(ms, mouseX, mouseY, partialTicks); renderWindowForeground(ms, mouseX, mouseY, partialTicks); endFrame(); @@ -82,105 +114,28 @@ public abstract class AbstractSimiScreen extends Screen { protected void prepareFrame() { } - protected void endFrame() { - } - protected void renderWindowBackground(PoseStack ms, int mouseX, int mouseY, float partialTicks) { renderBackground(ms); } - @Override - public boolean mouseClicked(double x, double y, int button) { - boolean result = false; - for (AbstractWidget widget : widgets) - if (widget.mouseClicked(x, y, button)) - result = true; - - if (!result) { - result = super.mouseClicked(x, y, button); - } - return result; - } - - @Override - public boolean keyPressed(int code, int p_keyPressed_2_, int p_keyPressed_3_) { - for (AbstractWidget widget : widgets) - if (widget.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_)) - return true; - - if (super.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_)) - return true; - - InputConstants.Key mouseKey = InputConstants.getKey(code, p_keyPressed_2_); - if (this.minecraft.options.keyInventory.isActiveAndMatches(mouseKey)) { - this.onClose(); - return true; - } - return false; - } - - @Override - public boolean charTyped(char character, int code) { - for (AbstractWidget widget : widgets) { - if (widget.charTyped(character, code)) - return true; - } - return super.charTyped(character, code); - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double delta) { - for (AbstractWidget widget : widgets) { - if (widget.mouseScrolled(mouseX, mouseY, delta)) - return true; - } - return super.mouseScrolled(mouseX, mouseY, delta); - } - - @Override - public boolean mouseReleased(double x, double y, int button) { - boolean result = false; - for (AbstractWidget widget : widgets) { - if (widget.mouseReleased(x, y, button)) - result = true; - } - return result | super.mouseReleased(x, y, button); - } - - @Override - public boolean shouldCloseOnEsc() { - return true; - } - - @Override - public boolean isPauseScreen() { - return false; - } - protected abstract void renderWindow(PoseStack ms, int mouseX, int mouseY, float partialTicks); protected void renderWindowForeground(PoseStack ms, int mouseX, int mouseY, float partialTicks) { - for (AbstractWidget widget : widgets) { - if (!widget.isHovered()) - continue; - - if (widget instanceof AbstractSimiWidget) { - if (!((AbstractSimiWidget) widget).getToolTip().isEmpty()) - renderComponentTooltip(ms, ((AbstractSimiWidget) widget).getToolTip(), mouseX, mouseY); - - } else { - widget.renderToolTip(ms, mouseX, mouseY); + for (Widget widget : renderables) { + if (widget instanceof AbstractSimiWidget simiWidget && simiWidget.isHovered()) { + List tooltip = simiWidget.getToolTip(); + if (!tooltip.isEmpty()) + renderComponentTooltip(ms, tooltip, mouseX, mouseY); } } } + protected void endFrame() { + } + @Deprecated protected void debugWindowArea(PoseStack matrixStack) { fill(matrixStack, guiLeft + windowWidth, guiTop + windowHeight, guiLeft, guiTop, 0xD3D3D3D3); } - - public List getWidgets() { - return widgets; - } } diff --git a/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java b/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java index 617aa1a5c..7bc493b5a 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AllGuiTextures.java @@ -3,6 +3,7 @@ package com.simibubi.create.foundation.gui; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.Create; +import com.simibubi.create.foundation.gui.element.ScreenElement; import com.simibubi.create.foundation.utility.Color; import net.minecraft.client.gui.GuiComponent; @@ -10,110 +11,110 @@ import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public enum AllGuiTextures implements IScreenRenderable { +public enum AllGuiTextures implements ScreenElement { // Inventories - PLAYER_INVENTORY("player_inventory.png", 176, 108), - WAND_OF_SYMMETRY("curiosities.png", 0, 131, 188, 101), - BLOCKZAPPER("curiosities.png", 0, 99, 214, 97), - TERRAINZAPPER("curiosities.png", 234, 103), - TERRAINZAPPER_INACTIVE_PARAM("curiosities.png", 238, 0, 18, 18), + PLAYER_INVENTORY("player_inventory", 176, 108), + WAND_OF_SYMMETRY("curiosities", 0, 131, 188, 101), + BLOCKZAPPER("curiosities", 0, 99, 214, 97), + TERRAINZAPPER("curiosities", 234, 103), + TERRAINZAPPER_INACTIVE_PARAM("curiosities", 238, 0, 18, 18), - LOGO("logo.png", 256, 256), + LOGO("logo", 256, 256), - SCHEMATIC("schematics.png", 192, 121), - SCHEMATIC_SLOT("widgets.png", 54, 0, 16, 16), - SCHEMATIC_PROMPT("schematics_2.png", 213, 77), - HUD_BACKGROUND("overlay.png", 0, 0, 16, 16), + SCHEMATIC("schematics", 192, 121), + SCHEMATIC_SLOT("widgets", 54, 0, 16, 16), + SCHEMATIC_PROMPT("schematics_2", 213, 77), + HUD_BACKGROUND("overlay", 0, 0, 16, 16), - SCHEMATIC_TABLE("schematics.png", 0, 121, 214, 83), - SCHEMATIC_TABLE_PROGRESS("schematics.png", 0, 204, 84, 16), + SCHEMATIC_TABLE("schematics", 0, 121, 214, 83), + SCHEMATIC_TABLE_PROGRESS("schematics", 0, 204, 84, 16), - SCHEMATICANNON_TOP("schematics_2.png", 0, 77, 213, 42), - SCHEMATICANNON_BOTTOM("schematics_2.png", 0, 119, 213, 99), - SCHEMATICANNON_PROGRESS("schematics_2.png", 76, 239, 114, 16), - SCHEMATICANNON_CHECKLIST_PROGRESS("schematics_2.png", 191, 240, 16, 14), - SCHEMATICANNON_HIGHLIGHT("schematics_2.png", 1, 229, 26, 26), - SCHEMATICANNON_FUEL("schematics_2.png", 28, 222, 47, 16), - SCHEMATICANNON_FUEL_CREATIVE("schematics_2.png", 28, 239, 47, 16), + SCHEMATICANNON_TOP("schematics_2", 0, 77, 213, 42), + SCHEMATICANNON_BOTTOM("schematics_2", 0, 119, 213, 99), + SCHEMATICANNON_PROGRESS("schematics_2", 76, 239, 114, 16), + SCHEMATICANNON_CHECKLIST_PROGRESS("schematics_2", 191, 240, 16, 14), + SCHEMATICANNON_HIGHLIGHT("schematics_2", 1, 229, 26, 26), + SCHEMATICANNON_FUEL("schematics_2", 28, 222, 47, 16), + SCHEMATICANNON_FUEL_CREATIVE("schematics_2", 28, 239, 47, 16), - STOCKSWITCH("logistics.png", 182, 93), - STOCKSWITCH_ARROW_UP("logistics.png", 191, 0, 7, 24), - STOCKSWITCH_ARROW_DOWN("logistics.png", 198, 0, 7, 24), - STOCKSWITCH_CURSOR("logistics.png", 206, 0, 7, 16), - STOCKSWITCH_INTERVAL("logistics.png", 0, 93, 100, 18), - STOCKSWITCH_UNPOWERED_LANE("logistics.png", 36, 18, 102, 18), - STOCKSWITCH_POWERED_LANE("logistics.png", 36, 40, 102, 18), + STOCKSWITCH("logistics", 182, 93), + STOCKSWITCH_ARROW_UP("logistics", 191, 0, 7, 24), + STOCKSWITCH_ARROW_DOWN("logistics", 198, 0, 7, 24), + STOCKSWITCH_CURSOR("logistics", 206, 0, 7, 16), + STOCKSWITCH_INTERVAL("logistics", 0, 93, 100, 18), + STOCKSWITCH_UNPOWERED_LANE("logistics", 36, 18, 102, 18), + STOCKSWITCH_POWERED_LANE("logistics", 36, 40, 102, 18), - ADJUSTABLE_CRATE("logistics_2.png", 124, 127), - ADJUSTABLE_DOUBLE_CRATE("logistics_2.png", 0, 127, 196, 127), - ADJUSTABLE_CRATE_LOCKED_SLOT("logistics_2.png", 125, 109, 18, 18), + ADJUSTABLE_CRATE("logistics_2", 124, 127), + ADJUSTABLE_DOUBLE_CRATE("logistics_2", 0, 127, 196, 127), + ADJUSTABLE_CRATE_LOCKED_SLOT("logistics_2", 125, 109, 18, 18), - FILTER("filters.png", 214, 97), - ATTRIBUTE_FILTER("filters.png", 0, 97, 241, 83), + FILTER("filters", 214, 97), + ATTRIBUTE_FILTER("filters", 0, 97, 241, 83), - TOOLBOX("toolbox.png", 188, 171), - TOOLBELT_SLOT("minecraft", "widgets.png", 24, 23, 22, 22), - TOOLBELT_SLOT_HIGHLIGHT("minecraft", "widgets.png", 0, 22, 24, 24), - TOOLBELT_MAIN_SLOT("widgets.png", 0, 97, 24, 24), - TOOLBELT_EMPTY_SLOT("widgets.png", 27, 98, 22, 22), - TOOLBELT_INACTIVE_SLOT("widgets.png", 52, 98, 22, 22), + TOOLBOX("toolbox", 188, 171), + TOOLBELT_SLOT("minecraft", "widgets", 24, 23, 22, 22), + TOOLBELT_SLOT_HIGHLIGHT("minecraft", "widgets", 0, 22, 24, 24), + TOOLBELT_MAIN_SLOT("widgets", 0, 97, 24, 24), + TOOLBELT_EMPTY_SLOT("widgets", 27, 98, 22, 22), + TOOLBELT_INACTIVE_SLOT("widgets", 52, 98, 22, 22), - TOOLBELT_HOTBAR_OFF("widgets.png", 0, 130, 20, 24), - TOOLBELT_HOTBAR_ON("widgets.png", 20, 130, 20, 24), - TOOLBELT_SELECTED_OFF("widgets.png", 0, 155, 22, 22), - TOOLBELT_SELECTED_ON("widgets.png", 22, 155, 22, 22), + TOOLBELT_HOTBAR_OFF("widgets", 0, 130, 20, 24), + TOOLBELT_HOTBAR_ON("widgets", 20, 130, 20, 24), + TOOLBELT_SELECTED_OFF("widgets", 0, 155, 22, 22), + TOOLBELT_SELECTED_ON("widgets", 22, 155, 22, 22), - SEQUENCER("sequencer.png", 173, 159), - SEQUENCER_INSTRUCTION("sequencer.png", 0, 14, 162, 22), - SEQUENCER_DELAY("sequencer.png", 0, 58, 162, 22), - SEQUENCER_END("sequencer.png", 0, 80, 162, 22), - SEQUENCER_EMPTY("sequencer.png", 0, 102, 162, 22), - SEQUENCER_AWAIT("sequencer.png", 0, 160, 162, 22), + SEQUENCER("sequencer", 173, 159), + SEQUENCER_INSTRUCTION("sequencer", 0, 14, 162, 22), + SEQUENCER_DELAY("sequencer", 0, 58, 162, 22), + SEQUENCER_END("sequencer", 0, 80, 162, 22), + SEQUENCER_EMPTY("sequencer", 0, 102, 162, 22), + SEQUENCER_AWAIT("sequencer", 0, 160, 162, 22), - LINKED_CONTROLLER("curiosities_2.png", 179, 109), - BLUEPRINT("curiosities_2.png", 0, 109, 179, 109), + LINKED_CONTROLLER("curiosities_2", 179, 109), + BLUEPRINT("curiosities_2", 0, 109, 179, 109), - PROJECTOR("projector.png", 235, 185), - PROJECTOR_FILTER_STRENGTH("projector.png", 0, 14, 162, 22), - PROJECTOR_FILTER("projector.png", 0, 36, 162, 22), - PROJECTOR_END("projector.png", 0, 58, 162, 22), - PROJECTOR_EMPTY("projector.png", 0, 80, 162, 22), + PROJECTOR("projector", 235, 185), + PROJECTOR_FILTER_STRENGTH("projector", 0, 14, 162, 22), + PROJECTOR_FILTER("projector", 0, 36, 162, 22), + PROJECTOR_END("projector", 0, 58, 162, 22), + PROJECTOR_EMPTY("projector", 0, 80, 162, 22), // JEI - JEI_SLOT("jei/widgets.png", 18, 18), - JEI_CHANCE_SLOT("jei/widgets.png", 20, 156, 18, 18), - JEI_CATALYST_SLOT("jei/widgets.png", 0, 156, 18, 18), - JEI_ARROW("jei/widgets.png", 19, 10, 42, 10), - JEI_LONG_ARROW("jei/widgets.png", 19, 0, 71, 10), - JEI_DOWN_ARROW("jei/widgets.png", 0, 21, 18, 14), - JEI_LIGHT("jei/widgets.png", 0, 42, 52, 11), - JEI_QUESTION_MARK("jei/widgets.png", 0, 178, 12, 16), - JEI_SHADOW("jei/widgets.png", 0, 56, 52, 11), - BLOCKZAPPER_UPGRADE_RECIPE("jei/widgets.png", 0, 75, 144, 66), - JEI_HEAT_BAR("jei/widgets.png", 0, 201, 169, 19), - JEI_NO_HEAT_BAR("jei/widgets.png", 0, 221, 169, 19), + JEI_SLOT("jei/widgets", 18, 18), + JEI_CHANCE_SLOT("jei/widgets", 20, 156, 18, 18), + JEI_CATALYST_SLOT("jei/widgets", 0, 156, 18, 18), + JEI_ARROW("jei/widgets", 19, 10, 42, 10), + JEI_LONG_ARROW("jei/widgets", 19, 0, 71, 10), + JEI_DOWN_ARROW("jei/widgets", 0, 21, 18, 14), + JEI_LIGHT("jei/widgets", 0, 42, 52, 11), + JEI_QUESTION_MARK("jei/widgets", 0, 178, 12, 16), + JEI_SHADOW("jei/widgets", 0, 56, 52, 11), + BLOCKZAPPER_UPGRADE_RECIPE("jei/widgets", 0, 75, 144, 66), + JEI_HEAT_BAR("jei/widgets", 0, 201, 169, 19), + JEI_NO_HEAT_BAR("jei/widgets", 0, 221, 169, 19), // Widgets - BUTTON("widgets.png", 18, 18), - BUTTON_HOVER("widgets.png", 18, 0, 18, 18), - BUTTON_DOWN("widgets.png", 36, 0, 18, 18), - INDICATOR("widgets.png", 0, 18, 18, 6), - INDICATOR_WHITE("widgets.png", 18, 18, 18, 6), - INDICATOR_GREEN("widgets.png", 36, 18, 18, 6), - INDICATOR_YELLOW("widgets.png", 54, 18, 18, 6), - INDICATOR_RED("widgets.png", 72, 18, 18, 6), + BUTTON("widgets", 18, 18), + BUTTON_HOVER("widgets", 18, 0, 18, 18), + BUTTON_DOWN("widgets", 36, 0, 18, 18), + INDICATOR("widgets", 0, 18, 18, 6), + INDICATOR_WHITE("widgets", 18, 18, 18, 6), + INDICATOR_GREEN("widgets", 36, 18, 18, 6), + INDICATOR_YELLOW("widgets", 54, 18, 18, 6), + INDICATOR_RED("widgets", 72, 18, 18, 6), - HOTSLOT_ARROW("widgets.png", 24, 51, 20, 12), - HOTSLOT("widgets.png", 0, 68, 22, 22), - HOTSLOT_ACTIVE("widgets.png", 0, 46, 22, 22), - HOTSLOT_SUPER_ACTIVE("widgets.png", 27, 67, 24, 24), + HOTSLOT_ARROW("widgets", 24, 51, 20, 12), + HOTSLOT("widgets", 0, 68, 22, 22), + HOTSLOT_ACTIVE("widgets", 0, 46, 22, 22), + HOTSLOT_SUPER_ACTIVE("widgets", 27, 67, 24, 24), - SPEECH_TOOLTIP_BACKGROUND("widgets.png", 0, 24, 8, 8), - SPEECH_TOOLTIP_COLOR("widgets.png", 8, 24, 8, 8), + SPEECH_TOOLTIP_BACKGROUND("widgets", 0, 24, 8, 8), + SPEECH_TOOLTIP_COLOR("widgets", 8, 24, 8, 8), // PlacementIndicator - PLACEMENT_INDICATOR_SHEET("placement_indicator.png", 0, 0, 16, 256); + PLACEMENT_INDICATOR_SHEET("placement_indicator", 0, 0, 16, 256); ; @@ -128,7 +129,7 @@ public enum AllGuiTextures implements IScreenRenderable { } private AllGuiTextures(int startX, int startY) { - this("icons.png", startX * 16, startY * 16, 16, 16); + this("icons", startX * 16, startY * 16, 16, 16); } private AllGuiTextures(String location, int startX, int startY, int width, int height) { @@ -136,7 +137,7 @@ public enum AllGuiTextures implements IScreenRenderable { } private AllGuiTextures(String namespace, String location, int startX, int startY, int width, int height) { - this.location = new ResourceLocation(namespace, "textures/gui/" + location); + this.location = new ResourceLocation(namespace, "textures/gui/" + location + ".png"); this.width = width; this.height = height; this.startX = startX; @@ -148,14 +149,21 @@ public enum AllGuiTextures implements IScreenRenderable { RenderSystem.setShaderTexture(0, location); } - @Override @OnlyIn(Dist.CLIENT) - public void draw(PoseStack ms, GuiComponent screen, int x, int y) { + @Override + public void render(PoseStack ms, int x, int y) { bind(); - screen.blit(ms, x, y, startX, startY, width, height); + GuiComponent.blit(ms, x, y, 0, startX, startY, width, height, 256, 256); } - public void draw(PoseStack ms, int x, int y, Color c) { + @OnlyIn(Dist.CLIENT) + public void render(PoseStack ms, int x, int y, GuiComponent component) { + bind(); + component.blit(ms, x, y, startX, startY, width, height); + } + + @OnlyIn(Dist.CLIENT) + public void render(PoseStack ms, int x, int y, Color c) { bind(); UIRenderHelper.drawColoredTexture(ms, c, x, y, startX, startY, width, height); } diff --git a/src/main/java/com/simibubi/create/foundation/gui/AllIcons.java b/src/main/java/com/simibubi/create/foundation/gui/AllIcons.java index 19daafa78..e29562c4a 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/AllIcons.java +++ b/src/main/java/com/simibubi/create/foundation/gui/AllIcons.java @@ -2,12 +2,15 @@ package com.simibubi.create.foundation.gui; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.blaze3d.vertex.PoseStack.Pose; import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix4f; import com.simibubi.create.Create; +import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; +import com.simibubi.create.foundation.gui.element.ScreenElement; import com.simibubi.create.foundation.utility.Color; import net.minecraft.client.gui.GuiComponent; +import net.minecraft.client.renderer.LightTexture; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; import net.minecraft.resources.ResourceLocation; @@ -15,9 +18,11 @@ import net.minecraft.world.phys.Vec3; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public class AllIcons implements IScreenRenderable { +public class AllIcons implements ScreenElement { public static final ResourceLocation ICON_ATLAS = Create.asResource("textures/gui/icons.png"); + public static final int ICON_ATLAS_SIZE = 256; + private static int x = 0, y = -1; private int iconX; private int iconY; @@ -166,51 +171,54 @@ public class AllIcons implements IScreenRenderable { RenderSystem.setShaderTexture(0, ICON_ATLAS); } - @Override @OnlyIn(Dist.CLIENT) - public void draw(PoseStack matrixStack, GuiComponent screen, int x, int y) { + @Override + public void render(PoseStack matrixStack, int x, int y) { bind(); - screen.blit(matrixStack, x, y, iconX, iconY, 16, 16); + GuiComponent.blit(matrixStack, x, y, 0, iconX, iconY, 16, 16, 256, 256); } @OnlyIn(Dist.CLIENT) - public void draw(PoseStack ms, MultiBufferSource buffer, int color) { + public void render(PoseStack matrixStack, int x, int y, GuiComponent component) { + bind(); + component.blit(matrixStack, x, y, iconX, iconY, 16, 16); + } + + @OnlyIn(Dist.CLIENT) + public void render(PoseStack ms, MultiBufferSource buffer, int color) { VertexConsumer builder = buffer.getBuffer(RenderType.textSeeThrough(ICON_ATLAS)); - float sheetSize = 256; - int i = 15 << 20 | 15 << 4; - int j = i >> 16 & '\uffff'; - int k = i & '\uffff'; - Pose peek = ms.last(); - Vec3 rgb = Color.vectorFromRGB(color); + Matrix4f matrix = ms.last().pose(); + Color rgb = new Color(color); + int light = LightTexture.FULL_BRIGHT; - Vec3 vec4 = new Vec3(1, 1, 0); - Vec3 vec3 = new Vec3(0, 1, 0); - Vec3 vec2 = new Vec3(0, 0, 0); - Vec3 vec1 = new Vec3(1, 0, 0); + Vec3 vec1 = new Vec3(0, 0, 0); + Vec3 vec2 = new Vec3(0, 1, 0); + Vec3 vec3 = new Vec3(1, 1, 0); + Vec3 vec4 = new Vec3(1, 0, 0); - float u1 = (iconX + 16) / sheetSize; - float u2 = iconX / sheetSize; - float v1 = iconY / sheetSize; - float v2 = (iconY + 16) / sheetSize; + float u1 = iconX / ICON_ATLAS_SIZE; + float u2 = (iconX + 16) / ICON_ATLAS_SIZE; + float v1 = iconY / ICON_ATLAS_SIZE; + float v2 = (iconY + 16) / ICON_ATLAS_SIZE; - vertex(peek, builder, j, k, rgb, vec1, u1, v1); - vertex(peek, builder, j, k, rgb, vec2, u2, v1); - vertex(peek, builder, j, k, rgb, vec3, u2, v2); - vertex(peek, builder, j, k, rgb, vec4, u1, v2); + vertex(builder, matrix, vec1, rgb, u1, v1, light); + vertex(builder, matrix, vec2, rgb, u1, v2, light); + vertex(builder, matrix, vec3, rgb, u2, v2, light); + vertex(builder, matrix, vec4, rgb, u2, v1, light); + } + + @OnlyIn(Dist.CLIENT) + private void vertex(VertexConsumer builder, Matrix4f matrix, Vec3 vec, Color rgb, float u, float v, int light) { + builder.vertex(matrix, (float) vec.x, (float) vec.y, (float) vec.z) + .color(rgb.getRed(), rgb.getGreen(), rgb.getBlue(), 255) + .uv(u, v) + .uv2(light) + .endVertex(); } @OnlyIn(Dist.CLIENT) public DelegatedStencilElement asStencil() { - return new DelegatedStencilElement().withStencilRenderer((ms, w, h, alpha) -> this.draw(ms, 0, 0)).withBounds(16, 16); - } - - @OnlyIn(Dist.CLIENT) - private void vertex(Pose peek, VertexConsumer builder, int j, int k, Vec3 rgb, Vec3 vec, float u, float v) { - builder.vertex(peek.pose(), (float) vec.x, (float) vec.y, (float) vec.z) - .color((float) rgb.x, (float) rgb.y, (float) rgb.z, 1) - .uv(u, v) - .uv2(j, k) - .endVertex(); + return new DelegatedStencilElement().withStencilRenderer((ms, w, h, alpha) -> this.render(ms, 0, 0)).withBounds(16, 16); } } diff --git a/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java b/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java index f6a80f6a4..51912d733 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java @@ -6,7 +6,6 @@ import java.util.function.Consumer; import javax.annotation.Nonnull; -import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; @@ -14,8 +13,11 @@ import com.jozufozu.flywheel.backend.Backend; import com.jozufozu.flywheel.backend.gl.versioned.GlCompat; import com.mojang.blaze3d.pipeline.RenderTarget; import com.mojang.blaze3d.platform.GlConst; +import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.widgets.BoxWidget; +import com.simibubi.create.foundation.gui.element.BoxElement; +import com.simibubi.create.foundation.gui.element.TextStencilElement; +import com.simibubi.create.foundation.gui.widget.BoxWidget; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; @@ -108,7 +110,7 @@ public class ConfirmationScreen extends AbstractSimiScreen { @Override protected void init() { - widgets.clear(); + super.init(); ArrayList copy = new ArrayList<>(text); text.clear(); @@ -139,7 +141,7 @@ public class ConfirmationScreen extends AbstractSimiScreen { new TextStencilElement(minecraft.font, tristate ? "Save" : "Confirm").centered(true, true); confirm = new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.Confirm)); confirm.showingElement(confirmText.withElementRenderer(BoxWidget.gradientFactory.apply(confirm))); - widgets.add(confirm); + addRenderableWidget(confirm); buttonX += 12 + 70; @@ -150,7 +152,7 @@ public class ConfirmationScreen extends AbstractSimiScreen { new BoxWidget(buttonX, y + textHeight + 6, 70, 16).withCallback(() -> accept(Response.ConfirmDontSave)); confirmDontSave.showingElement( confirmDontSaveText.withElementRenderer(BoxWidget.gradientFactory.apply(confirmDontSave))); - widgets.add(confirmDontSave); + addRenderableWidget(confirmDontSave); buttonX += 12 + 70; } @@ -158,7 +160,7 @@ public class ConfirmationScreen extends AbstractSimiScreen { cancel = new BoxWidget(buttonX, y + textHeight + 6, 70, 16) .withCallback(() -> accept(Response.Cancel)); cancel.showingElement(cancelText.withElementRenderer(BoxWidget.gradientFactory.apply(cancel))); - widgets.add(cancel); + addRenderableWidget(cancel); textBackground = new BoxElement() .gradientBorder(Theme.p(Theme.Key.BUTTON_DISABLE)) @@ -215,7 +217,7 @@ public class ConfirmationScreen extends AbstractSimiScreen { @Override protected void prepareFrame() { RenderTarget thisBuffer = UIRenderHelper.framebuffer; - RenderTarget mainBuffer = Minecraft.getInstance().getMainRenderTarget(); + RenderTarget mainBuffer = minecraft.getMainRenderTarget(); GlCompat functions = Backend.getInstance().compat; functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, mainBuffer.frameBufferId); @@ -223,15 +225,13 @@ public class ConfirmationScreen extends AbstractSimiScreen { functions.blit.blitFramebuffer(0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, 0, 0, mainBuffer.viewWidth, mainBuffer.viewHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR); functions.fbo.bindFramebuffer(GlConst.GL_FRAMEBUFFER, thisBuffer.frameBufferId); - GL11.glClear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT); - + RenderSystem.clear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT, Minecraft.ON_OSX); } @Override protected void endFrame() { - RenderTarget thisBuffer = UIRenderHelper.framebuffer; - RenderTarget mainBuffer = Minecraft.getInstance().getMainRenderTarget(); + RenderTarget mainBuffer = minecraft.getMainRenderTarget(); GlCompat functions = Backend.getInstance().compat; functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, thisBuffer.frameBufferId); diff --git a/src/main/java/com/simibubi/create/foundation/gui/mainMenu/CreateMainMenuScreen.java b/src/main/java/com/simibubi/create/foundation/gui/CreateMainMenuScreen.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/gui/mainMenu/CreateMainMenuScreen.java rename to src/main/java/com/simibubi/create/foundation/gui/CreateMainMenuScreen.java index fd8353f43..c2631f48b 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/mainMenu/CreateMainMenuScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/CreateMainMenuScreen.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui.mainMenu; +package com.simibubi.create.foundation.gui; import com.jozufozu.flywheel.util.transform.MatrixTransformStack; import com.mojang.blaze3d.platform.GlStateManager; @@ -7,11 +7,8 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.Create; import com.simibubi.create.foundation.config.ui.BaseConfigScreen; -import com.simibubi.create.foundation.gui.AbstractSimiScreen; -import com.simibubi.create.foundation.gui.AllGuiTextures; -import com.simibubi.create.foundation.gui.BoxElement; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.ScreenOpener; +import com.simibubi.create.foundation.gui.element.BoxElement; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.ponder.content.PonderTagIndexScreen; import com.simibubi.create.foundation.utility.Color; @@ -104,7 +101,7 @@ public class CreateMainMenuScreen extends AbstractSimiScreen { ms.translate(width / 2 - 32, 32, -10); ms.pushPose(); ms.scale(0.25f, 0.25f, 0.25f); - AllGuiTextures.LOGO.draw(ms, 0, 0); + AllGuiTextures.LOGO.render(ms, 0, 0, this); ms.popPose(); new BoxElement().withBackground(0x88_000000) .flatBorder(new Color(0x01_000000)) diff --git a/src/main/java/com/simibubi/create/foundation/gui/IScreenRenderable.java b/src/main/java/com/simibubi/create/foundation/gui/IScreenRenderable.java deleted file mode 100644 index 2ed4f9707..000000000 --- a/src/main/java/com/simibubi/create/foundation/gui/IScreenRenderable.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.simibubi.create.foundation.gui; - -import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.CreateClient; - -import net.minecraft.client.gui.GuiComponent; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; - -public interface IScreenRenderable { - - @OnlyIn(Dist.CLIENT) - void draw(PoseStack ms, GuiComponent screen, int x, int y); - - @OnlyIn(Dist.CLIENT) - default void draw(PoseStack ms, int x, int y) { - draw(ms, CreateClient.EMPTY_SCREEN, x, y); - } - -} diff --git a/src/main/java/com/simibubi/create/foundation/gui/Theme.java b/src/main/java/com/simibubi/create/foundation/gui/Theme.java index e61872984..01bbb8c98 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/Theme.java +++ b/src/main/java/com/simibubi/create/foundation/gui/Theme.java @@ -15,25 +15,25 @@ import com.simibubi.create.foundation.utility.Couple; public class Theme { - private static final List themes = new ArrayList<>(); - private static final Theme base = addTheme(new Theme()); + private static final List THEMES = new ArrayList<>(); + private static final Theme BASE = addTheme(new Theme()); public static Theme addTheme(@Nonnull Theme theme) { - themes.add(theme); - themes.sort(Comparator.comparingInt(Theme::getPriority).reversed()); + THEMES.add(theme); + THEMES.sort(Comparator.comparingInt(Theme::getPriority).reversed()); return theme; } public static void removeTheme(Theme theme) { - themes.remove(theme); + THEMES.remove(theme); } public static void reload() { - themes.forEach(Theme::init); + THEMES.forEach(Theme::init); } private static ColorHolder resolve(String key) { - return themes + return THEMES .stream() .map(theme -> theme.get(key)) .filter(Objects::nonNull) diff --git a/src/main/java/com/simibubi/create/foundation/gui/TickableGuiEventListener.java b/src/main/java/com/simibubi/create/foundation/gui/TickableGuiEventListener.java new file mode 100644 index 000000000..898760fb2 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/gui/TickableGuiEventListener.java @@ -0,0 +1,7 @@ +package com.simibubi.create.foundation.gui; + +import net.minecraft.client.gui.components.events.GuiEventListener; + +public interface TickableGuiEventListener extends GuiEventListener { + void tick(); +} diff --git a/src/main/java/com/simibubi/create/foundation/gui/ToolSelectionScreen.java b/src/main/java/com/simibubi/create/foundation/gui/ToolSelectionScreen.java index 245abd3e6..f2930002b 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ToolSelectionScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/ToolSelectionScreen.java @@ -59,10 +59,9 @@ public class ToolSelectionScreen extends Screen { } private void draw(PoseStack matrixStack, float partialTicks) { - Minecraft mc = Minecraft.getInstance(); - Window mainWindow = mc.getWindow(); + Window mainWindow = minecraft.getWindow(); if (!initialized) - init(mc, mainWindow.getGuiScaledWidth(), mainWindow.getGuiScaledHeight()); + init(minecraft, mainWindow.getGuiScaledWidth(), mainWindow.getGuiScaledHeight()); int x = (mainWindow.getGuiScaledWidth() - w) / 2 + 15; int y = mainWindow.getGuiScaledHeight() - h - 75; @@ -125,11 +124,11 @@ public class ToolSelectionScreen extends Screen { RenderSystem.setShaderColor(0, 0, 0, alpha); tools.get(i) .getIcon() - .draw(matrixStack, this, x + i * 50 + 16, y + 12); + .render(matrixStack, x + i * 50 + 16, y + 12, this); RenderSystem.setShaderColor(1, 1, 1, alpha); tools.get(i) .getIcon() - .draw(matrixStack, this, x + i * 50 + 16, y + 11); + .render(matrixStack, x + i * 50 + 16, y + 11, this); matrixStack.popPose(); } diff --git a/src/main/java/com/simibubi/create/foundation/gui/container/AbstractSimiContainerScreen.java b/src/main/java/com/simibubi/create/foundation/gui/container/AbstractSimiContainerScreen.java new file mode 100644 index 000000000..05197dd55 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/gui/container/AbstractSimiContainerScreen.java @@ -0,0 +1,151 @@ +package com.simibubi.create.foundation.gui.container; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import javax.annotation.ParametersAreNonnullByDefault; + +import com.mojang.blaze3d.vertex.PoseStack; +import com.simibubi.create.foundation.gui.AllGuiTextures; +import com.simibubi.create.foundation.gui.TickableGuiEventListener; +import com.simibubi.create.foundation.gui.widget.AbstractSimiWidget; + +import net.minecraft.client.gui.components.Widget; +import net.minecraft.client.gui.components.events.GuiEventListener; +import net.minecraft.client.gui.narration.NarratableEntry; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.client.gui.screens.inventory.ContainerScreen; +import net.minecraft.client.renderer.Rect2i; +import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +@OnlyIn(Dist.CLIENT) +@ParametersAreNonnullByDefault +public abstract class AbstractSimiContainerScreen extends AbstractContainerScreen { + + protected int windowXOffset, windowYOffset; + + public AbstractSimiContainerScreen(T container, Inventory inv, Component title) { + super(container, inv, title); + } + + /** + * This method must be called before {@code super.init()}! + */ + protected void setWindowSize(int width, int height) { + imageWidth = width; + imageHeight = height; + } + + /** + * This method must be called before {@code super.init()}! + */ + protected void setWindowOffset(int xOffset, int yOffset) { + windowXOffset = xOffset; + windowYOffset = yOffset; + } + + @Override + protected void init() { + super.init(); + leftPos += windowXOffset; + topPos += windowYOffset; + } + + @Override + protected void containerTick() { + for (GuiEventListener listener : children()) { + if (listener instanceof TickableGuiEventListener tickable) { + tickable.tick(); + } + } + } + + @SuppressWarnings("unchecked") + protected void addRenderableWidgets(W... widgets) { + for (W widget : widgets) { + addRenderableWidget(widget); + } + } + + protected void addRenderableWidgets(Collection widgets) { + for (W widget : widgets) { + addRenderableWidget(widget); + } + } + + protected void removeWidgets(GuiEventListener... widgets) { + for (GuiEventListener widget : widgets) { + removeWidget(widget); + } + } + + protected void removeWidgets(Collection widgets) { + for (GuiEventListener widget : widgets) { + removeWidget(widget); + } + } + + @Override + public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { + partialTicks = minecraft.getFrameTime(); + + renderBackground(matrixStack); + + super.render(matrixStack, mouseX, mouseY, partialTicks); + + renderForeground(matrixStack, mouseX, mouseY, partialTicks); + } + + @Override + protected void renderLabels(PoseStack poseStack, int mouseX, int mouseY) { + // no-op to prevent screen- and inventory-title from being rendered at incorrect location + // could also set this.titleX/Y and this.playerInventoryTitleX/Y to the proper values instead + } + + protected void renderForeground(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { + renderTooltip(matrixStack, mouseX, mouseY); + for (Widget widget : renderables) { + if (widget instanceof AbstractSimiWidget simiWidget && simiWidget.isHovered()) { + List tooltip = simiWidget.getToolTip(); + if (!tooltip.isEmpty()) + renderComponentTooltip(matrixStack, tooltip, mouseX, mouseY); + } + } + } + + public int getLeftOfCentered(int textureWidth) { + return leftPos - windowXOffset + (imageWidth - textureWidth) / 2; + } + + public void renderPlayerInventory(PoseStack ms, int x, int y) { + AllGuiTextures.PLAYER_INVENTORY.render(ms, x, y, this); + font.draw(ms, playerInventoryTitle, x + 8, y + 6, 0x404040); + } + + /** + * Used for moving JEI out of the way of extra things like block renders. + * + * @return the space that the GUI takes up outside the normal rectangle defined by {@link ContainerScreen}. + */ + public List getExtraAreas() { + return Collections.emptyList(); + } + + @Deprecated + protected void debugWindowArea(PoseStack matrixStack) { + fill(matrixStack, leftPos + imageWidth, topPos + imageHeight, leftPos, topPos, 0xD3D3D3D3); + } + + @Deprecated + protected void debugExtraAreas(PoseStack matrixStack) { + for (Rect2i area : getExtraAreas()) { + fill(matrixStack, area.getX() + area.getWidth(), area.getY() + area.getHeight(), area.getX(), area.getY(), 0xD3D3D3D3); + } + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/gui/ClearContainerPacket.java b/src/main/java/com/simibubi/create/foundation/gui/container/ClearContainerPacket.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/gui/ClearContainerPacket.java rename to src/main/java/com/simibubi/create/foundation/gui/container/ClearContainerPacket.java index 2d288b5f3..6d5f4ef41 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ClearContainerPacket.java +++ b/src/main/java/com/simibubi/create/foundation/gui/container/ClearContainerPacket.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.container; import java.util.function.Supplier; diff --git a/src/main/java/com/simibubi/create/foundation/gui/ContainerBase.java b/src/main/java/com/simibubi/create/foundation/gui/container/ContainerBase.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/gui/ContainerBase.java rename to src/main/java/com/simibubi/create/foundation/gui/container/ContainerBase.java index 66f355d69..f3632f10e 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ContainerBase.java +++ b/src/main/java/com/simibubi/create/foundation/gui/container/ContainerBase.java @@ -1,4 +1,6 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.container; + +import com.simibubi.create.foundation.utility.IInteractionChecker; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; @@ -37,10 +39,10 @@ public abstract class ContainerBase extends AbstractContainerMenu { @OnlyIn(Dist.CLIENT) protected abstract T createOnClient(FriendlyByteBuf extraData); - protected abstract void addSlots(); - protected abstract void initAndReadInventory(T contentHolder); + protected abstract void addSlots(); + protected abstract void saveData(T contentHolder); protected void addPlayerSlots(int x, int y) { diff --git a/src/main/java/com/simibubi/create/foundation/gui/GhostItemContainer.java b/src/main/java/com/simibubi/create/foundation/gui/container/GhostItemContainer.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/gui/GhostItemContainer.java rename to src/main/java/com/simibubi/create/foundation/gui/container/GhostItemContainer.java index 07c258105..bb42dfd2a 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/GhostItemContainer.java +++ b/src/main/java/com/simibubi/create/foundation/gui/container/GhostItemContainer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.container; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.entity.player.Inventory; @@ -51,7 +51,6 @@ public abstract class GhostItemContainer extends ContainerBase implements @Override public void clicked(int slotId, int dragType, ClickType clickTypeIn, Player player) { - ItemStack held = getCarried(); if (slotId < 36) { super.clicked(slotId, dragType, clickTypeIn, player); return; @@ -59,6 +58,7 @@ public abstract class GhostItemContainer extends ContainerBase implements if (clickTypeIn == ClickType.THROW) return; + ItemStack held = getCarried(); int slot = slotId - 36; if (clickTypeIn == ClickType.CLONE) { if (player.isCreative() && held.isEmpty()) { @@ -71,17 +71,15 @@ public abstract class GhostItemContainer extends ContainerBase implements return; } + ItemStack insert; if (held.isEmpty()) { - ghostInventory.setStackInSlot(slot, ItemStack.EMPTY); - getSlot(slotId).setChanged(); - return; + insert = ItemStack.EMPTY; + } else { + insert = held.copy(); + insert.setCount(1); } - - ItemStack insert = held.copy(); - insert.setCount(1); ghostInventory.setStackInSlot(slot, insert); getSlot(slotId).setChanged(); - setCarried(held); } @Override @@ -107,6 +105,4 @@ public abstract class GhostItemContainer extends ContainerBase implements return ItemStack.EMPTY; } - - } diff --git a/src/main/java/com/simibubi/create/foundation/gui/GhostItemSubmitPacket.java b/src/main/java/com/simibubi/create/foundation/gui/container/GhostItemSubmitPacket.java similarity index 95% rename from src/main/java/com/simibubi/create/foundation/gui/GhostItemSubmitPacket.java rename to src/main/java/com/simibubi/create/foundation/gui/container/GhostItemSubmitPacket.java index cbed78114..32b0d1378 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/GhostItemSubmitPacket.java +++ b/src/main/java/com/simibubi/create/foundation/gui/container/GhostItemSubmitPacket.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.container; import java.util.function.Supplier; diff --git a/src/main/java/com/simibubi/create/foundation/gui/IClearableContainer.java b/src/main/java/com/simibubi/create/foundation/gui/container/IClearableContainer.java similarity index 81% rename from src/main/java/com/simibubi/create/foundation/gui/IClearableContainer.java rename to src/main/java/com/simibubi/create/foundation/gui/container/IClearableContainer.java index eea746881..d0d0da14e 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/IClearableContainer.java +++ b/src/main/java/com/simibubi/create/foundation/gui/container/IClearableContainer.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.container; import com.simibubi.create.foundation.networking.AllPackets; diff --git a/src/main/java/com/simibubi/create/foundation/gui/BoxElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/BoxElement.java similarity index 99% rename from src/main/java/com/simibubi/create/foundation/gui/BoxElement.java rename to src/main/java/com/simibubi/create/foundation/gui/element/BoxElement.java index de333b49b..4196dd7e0 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/BoxElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/element/BoxElement.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.element; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.BufferBuilder; diff --git a/src/main/java/com/simibubi/create/foundation/gui/CombinedStencilElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/CombinedStencilElement.java similarity index 97% rename from src/main/java/com/simibubi/create/foundation/gui/CombinedStencilElement.java rename to src/main/java/com/simibubi/create/foundation/gui/element/CombinedStencilElement.java index f042e264e..6096f8427 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/CombinedStencilElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/element/CombinedStencilElement.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.element; import javax.annotation.Nonnull; diff --git a/src/main/java/com/simibubi/create/foundation/gui/DelegatedStencilElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/DelegatedStencilElement.java similarity index 93% rename from src/main/java/com/simibubi/create/foundation/gui/DelegatedStencilElement.java rename to src/main/java/com/simibubi/create/foundation/gui/element/DelegatedStencilElement.java index 5b87d81ff..4ca427a4d 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/DelegatedStencilElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/element/DelegatedStencilElement.java @@ -1,6 +1,7 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.element; import com.mojang.blaze3d.vertex.PoseStack; +import com.simibubi.create.foundation.gui.UIRenderHelper; import com.simibubi.create.foundation.utility.Color; public class DelegatedStencilElement extends StencilElement { diff --git a/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/GuiGameElement.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java rename to src/main/java/com/simibubi/create/foundation/gui/element/GuiGameElement.java index 8db001422..10e00f6d8 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/GuiGameElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/element/GuiGameElement.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.element; import javax.annotation.Nullable; @@ -13,6 +13,8 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.math.Vector3f; import com.simibubi.create.foundation.fluid.FluidRenderer; +import com.simibubi.create.foundation.gui.ILightingSettings; +import com.simibubi.create.foundation.gui.UIRenderHelper; import com.simibubi.create.foundation.utility.Color; import com.simibubi.create.foundation.utility.VecHelper; @@ -187,9 +189,9 @@ public class GuiGameElement { int color = Minecraft.getInstance() .getBlockColors() .getColor(blockState, null, null, 0); - Vec3 rgb = Color.vectorFromRGB(color == -1 ? this.color : color); + Color rgb = new Color(color == -1 ? this.color : color); blockRenderer.getModelRenderer() - .renderModel(ms.last(), vb, blockState, blockModel, (float) rgb.x, (float) rgb.y, (float) rgb.z, + .renderModel(ms.last(), vb, blockState, blockModel, rgb.getRedAsFloat(), rgb.getGreenAsFloat(), rgb.getBlueAsFloat(), LightTexture.FULL_BRIGHT, OverlayTexture.NO_OVERLAY, VirtualEmptyModelData.INSTANCE); buffer.endBatch(); } diff --git a/src/main/java/com/simibubi/create/foundation/gui/RenderElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/RenderElement.java similarity index 66% rename from src/main/java/com/simibubi/create/foundation/gui/RenderElement.java rename to src/main/java/com/simibubi/create/foundation/gui/element/RenderElement.java index 55b0eb1c1..444c03b5d 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/RenderElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/element/RenderElement.java @@ -1,14 +1,16 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.element; import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.gui.GuiComponent; +public abstract class RenderElement implements ScreenElement { -public abstract class RenderElement implements IScreenRenderable { + public static final RenderElement EMPTY = new RenderElement() { + @Override + public void render(PoseStack ms) { + } + }; - public static RenderElement EMPTY = new RenderElement() {@Override public void render(PoseStack ms) {}}; - - public static RenderElement of(IScreenRenderable renderable) { + public static RenderElement of(ScreenElement renderable) { return new SimpleRenderElement(renderable); } @@ -67,26 +69,21 @@ public abstract class RenderElement implements IScreenRenderable { public abstract void render(PoseStack ms); @Override - public void draw(PoseStack ms, GuiComponent screen, int x, int y) { - this.at(x, y).render(ms); - } - - @Override - public void draw(PoseStack ms, int x, int y) { + public void render(PoseStack ms, int x, int y) { this.at(x, y).render(ms); } public static class SimpleRenderElement extends RenderElement { - private IScreenRenderable renderable; + private ScreenElement renderable; - public SimpleRenderElement(IScreenRenderable renderable) { + public SimpleRenderElement(ScreenElement renderable) { this.renderable = renderable; } @Override public void render(PoseStack ms) { - renderable.draw(ms, (int) x, (int) y); + renderable.render(ms, (int) x, (int) y); } } } diff --git a/src/main/java/com/simibubi/create/foundation/gui/element/ScreenElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/ScreenElement.java new file mode 100644 index 000000000..9fa0f28c9 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/gui/element/ScreenElement.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.gui.element; + +import com.mojang.blaze3d.vertex.PoseStack; + +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +public interface ScreenElement { + + @OnlyIn(Dist.CLIENT) + void render(PoseStack ms, int x, int y); + +} diff --git a/src/main/java/com/simibubi/create/foundation/gui/StencilElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/StencilElement.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/gui/StencilElement.java rename to src/main/java/com/simibubi/create/foundation/gui/element/StencilElement.java index c69042004..dbe8fce56 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/StencilElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/element/StencilElement.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.element; import org.lwjgl.opengl.GL11; diff --git a/src/main/java/com/simibubi/create/foundation/gui/TextStencilElement.java b/src/main/java/com/simibubi/create/foundation/gui/element/TextStencilElement.java similarity index 97% rename from src/main/java/com/simibubi/create/foundation/gui/TextStencilElement.java rename to src/main/java/com/simibubi/create/foundation/gui/element/TextStencilElement.java index add2c71bc..d735a33aa 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/TextStencilElement.java +++ b/src/main/java/com/simibubi/create/foundation/gui/element/TextStencilElement.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.gui.element; import com.mojang.blaze3d.vertex.PoseStack; diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/AbstractSimiWidget.java b/src/main/java/com/simibubi/create/foundation/gui/widget/AbstractSimiWidget.java similarity index 83% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/AbstractSimiWidget.java rename to src/main/java/com/simibubi/create/foundation/gui/widget/AbstractSimiWidget.java index 99b6df5b3..146a476ef 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/AbstractSimiWidget.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widget/AbstractSimiWidget.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.gui.widget; import java.util.LinkedList; import java.util.List; @@ -7,29 +7,30 @@ import java.util.function.BiConsumer; import javax.annotation.Nonnull; import com.mojang.blaze3d.vertex.PoseStack; +import com.simibubi.create.foundation.gui.TickableGuiEventListener; import net.minecraft.client.gui.components.AbstractWidget; import net.minecraft.client.gui.narration.NarrationElementOutput; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; -public abstract class AbstractSimiWidget extends AbstractWidget { +public abstract class AbstractSimiWidget extends AbstractWidget implements TickableGuiEventListener { protected float z; protected boolean wasHovered = false; protected List toolTip = new LinkedList<>(); protected BiConsumer onClick = (_$, _$$) -> {}; - protected AbstractSimiWidget() { - this(0, 0); - } - protected AbstractSimiWidget(int x, int y) { this(x, y, 16, 16); } protected AbstractSimiWidget(int x, int y, int width, int height) { - super(x, y, width, height, TextComponent.EMPTY); + this(x, y, width, height, TextComponent.EMPTY); + } + + protected AbstractSimiWidget(int x, int y, int width, int height, Component message) { + super(x, y, width, height, message); } public T withCallback(BiConsumer cb) { @@ -52,12 +53,13 @@ public abstract class AbstractSimiWidget extends AbstractWidget { return toolTip; } + @Override public void tick() {} @Override public void render(@Nonnull PoseStack ms, int mouseX, int mouseY, float partialTicks) { if (visible) { - isHovered = isMouseOver(mouseX, mouseY); + isHovered = mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height; beforeRender(ms, mouseX, mouseY, partialTicks); renderButton(ms, mouseX, mouseY, partialTicks); afterRender(ms, mouseX, mouseY, partialTicks); @@ -65,18 +67,14 @@ public abstract class AbstractSimiWidget extends AbstractWidget { } } - @Override - public void renderButton(@Nonnull PoseStack ms, int mouseX, int mouseY, float partialTicks) {} - - @Override - protected boolean clicked(double mouseX, double mouseY) { - return active && visible && isMouseOver(mouseX, mouseY); - } - protected void beforeRender(@Nonnull PoseStack ms, int mouseX, int mouseY, float partialTicks) { ms.pushPose(); } + @Override + public void renderButton(@Nonnull PoseStack ms, int mouseX, int mouseY, float partialTicks) { + } + protected void afterRender(@Nonnull PoseStack ms, int mouseX, int mouseY, float partialTicks) { ms.popPose(); } diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/BoxWidget.java b/src/main/java/com/simibubi/create/foundation/gui/widget/BoxWidget.java similarity index 96% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/BoxWidget.java rename to src/main/java/com/simibubi/create/foundation/gui/widget/BoxWidget.java index 980d55250..424a9009a 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/BoxWidget.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widget/BoxWidget.java @@ -1,15 +1,15 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.gui.widget; import java.util.function.Function; import javax.annotation.Nonnull; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.BoxElement; -import com.simibubi.create.foundation.gui.DelegatedStencilElement; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.Theme.Key; import com.simibubi.create.foundation.gui.UIRenderHelper; +import com.simibubi.create.foundation.gui.element.BoxElement; +import com.simibubi.create.foundation.gui.element.DelegatedStencilElement; import com.simibubi.create.foundation.utility.Color; import com.simibubi.create.foundation.utility.Couple; import com.simibubi.create.foundation.utility.animation.LerpedFloat; diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/ElementWidget.java b/src/main/java/com/simibubi/create/foundation/gui/widget/ElementWidget.java similarity index 94% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/ElementWidget.java rename to src/main/java/com/simibubi/create/foundation/gui/widget/ElementWidget.java index 09c63de85..1642ab097 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/ElementWidget.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widget/ElementWidget.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.gui.widget; import java.util.function.Consumer; import java.util.function.UnaryOperator; @@ -6,8 +6,8 @@ import java.util.function.UnaryOperator; import javax.annotation.Nonnull; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.IScreenRenderable; -import com.simibubi.create.foundation.gui.RenderElement; +import com.simibubi.create.foundation.gui.element.RenderElement; +import com.simibubi.create.foundation.gui.element.ScreenElement; import com.simibubi.create.foundation.utility.animation.LerpedFloat; public class ElementWidget extends AbstractSimiWidget { @@ -40,7 +40,7 @@ public class ElementWidget extends AbstractSimiWidget { return (T) this; } - public T showing(IScreenRenderable renderable) { + public T showing(ScreenElement renderable) { return this.showingElement(RenderElement.of(renderable)); } diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/IconButton.java b/src/main/java/com/simibubi/create/foundation/gui/widget/IconButton.java similarity index 55% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/IconButton.java rename to src/main/java/com/simibubi/create/foundation/gui/widget/IconButton.java index 49eacc7cc..844a718a0 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/IconButton.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widget/IconButton.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.gui.widget; import javax.annotation.Nonnull; @@ -12,7 +12,6 @@ import net.minecraft.network.chat.Component; public class IconButton extends AbstractSimiWidget { private AllIcons icon; - protected boolean pressed; public IconButton(int x, int y, AllIcons icon) { super(x, y, 18, 18); @@ -21,32 +20,19 @@ public class IconButton extends AbstractSimiWidget { @Override public void renderButton(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { - if (this.visible) { - this.isHovered = - mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; + if (visible) { + isHovered = mouseX >= x && mouseY >= y && mouseX < x + width && mouseY < y + height; - AllGuiTextures button = (pressed || !active) ? button = AllGuiTextures.BUTTON_DOWN - : (isHovered) ? AllGuiTextures.BUTTON_HOVER : AllGuiTextures.BUTTON; + AllGuiTextures button = !active ? AllGuiTextures.BUTTON_DOWN + : isHovered() ? AllGuiTextures.BUTTON_HOVER : AllGuiTextures.BUTTON; RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); AllGuiTextures.BUTTON.bind(); blit(matrixStack, x, y, button.startX, button.startY, button.width, button.height); - icon.draw(matrixStack, this, x + 1, y + 1); + icon.render(matrixStack, x + 1, y + 1, this); } } - @Override - public void onClick(double p_onClick_1_, double p_onClick_3_) { - super.onClick(p_onClick_1_, p_onClick_3_); - this.pressed = true; - } - - @Override - public void onRelease(double p_onRelease_1_, double p_onRelease_3_) { - super.onRelease(p_onRelease_1_, p_onRelease_3_); - this.pressed = false; - } - public void setToolTip(Component text) { toolTip.clear(); toolTip.add(text); diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/Indicator.java b/src/main/java/com/simibubi/create/foundation/gui/widget/Indicator.java similarity index 89% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/Indicator.java rename to src/main/java/com/simibubi/create/foundation/gui/widget/Indicator.java index 739e7a6f8..a285379db 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/Indicator.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widget/Indicator.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.gui.widget; import javax.annotation.Nonnull; @@ -9,24 +9,19 @@ import com.simibubi.create.foundation.gui.AllGuiTextures; import net.minecraft.network.chat.Component; public class Indicator extends AbstractSimiWidget { - - public enum State { - OFF, ON, - RED, YELLOW, GREEN; - } - + public State state; - + public Indicator(int x, int y, Component tooltip) { super(x, y, AllGuiTextures.INDICATOR.width, AllGuiTextures.INDICATOR.height); this.toolTip = ImmutableList.of(tooltip); this.state = State.OFF; } - + @Override public void render(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks ) { AllGuiTextures toDraw; - switch(state) { + switch (state) { case ON: toDraw = AllGuiTextures.INDICATOR_WHITE; break; case OFF: toDraw = AllGuiTextures.INDICATOR; break; case RED: toDraw = AllGuiTextures.INDICATOR_RED; break; @@ -34,7 +29,12 @@ public class Indicator extends AbstractSimiWidget { case GREEN: toDraw = AllGuiTextures.INDICATOR_GREEN; break; default: toDraw = AllGuiTextures.INDICATOR; break; } - toDraw.draw(matrixStack, this, x, y); + toDraw.render(matrixStack, x, y, this); } - + + public enum State { + OFF, ON, + RED, YELLOW, GREEN; + } + } diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java b/src/main/java/com/simibubi/create/foundation/gui/widget/Label.java similarity index 92% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java rename to src/main/java/com/simibubi/create/foundation/gui/widget/Label.java index 30e92182b..414f5ab5b 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/Label.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widget/Label.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.gui.widget; import javax.annotation.Nonnull; @@ -71,9 +71,7 @@ public class Label extends AbstractSimiWidget { } @Override - public void render(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { - if (!visible) - return; + public void renderButton(@Nonnull PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { if (text == null || text.getString().isEmpty()) return; diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/ScrollInput.java b/src/main/java/com/simibubi/create/foundation/gui/widget/ScrollInput.java similarity index 97% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/ScrollInput.java rename to src/main/java/com/simibubi/create/foundation/gui/widget/ScrollInput.java index d5e78ec6f..8517da162 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/ScrollInput.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widget/ScrollInput.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.gui.widget; import java.util.function.Consumer; import java.util.function.Function; @@ -91,9 +91,6 @@ public class ScrollInput extends AbstractSimiWidget { @Override public boolean mouseScrolled(double mouseX, double mouseY, double delta) { - if (!isHovered) - return false; - StepContext context = new StepContext(); context.control = AllKeys.ctrlDown(); context.shift = AllKeys.shiftDown(); diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/SelectionScrollInput.java b/src/main/java/com/simibubi/create/foundation/gui/widget/SelectionScrollInput.java similarity index 97% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/SelectionScrollInput.java rename to src/main/java/com/simibubi/create/foundation/gui/widget/SelectionScrollInput.java index a6288c073..d7091ca7e 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/SelectionScrollInput.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widget/SelectionScrollInput.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.gui.widget; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java b/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java index 629510b67..260a4cb4b 100644 --- a/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java +++ b/src/main/java/com/simibubi/create/foundation/networking/AllPackets.java @@ -52,8 +52,8 @@ import com.simibubi.create.content.schematics.packet.SchematicUploadPacket; import com.simibubi.create.foundation.command.HighlightPacket; import com.simibubi.create.foundation.command.SConfigureConfigPacket; import com.simibubi.create.foundation.config.ui.CConfigureConfigPacket; -import com.simibubi.create.foundation.gui.ClearContainerPacket; -import com.simibubi.create.foundation.gui.GhostItemSubmitPacket; +import com.simibubi.create.foundation.gui.container.ClearContainerPacket; +import com.simibubi.create.foundation.gui.container.GhostItemSubmitPacket; import com.simibubi.create.foundation.tileEntity.behaviour.filtering.FilteringCountUpdatePacket; import com.simibubi.create.foundation.tileEntity.behaviour.scrollvalue.ScrollValueUpdatePacket; import com.simibubi.create.foundation.utility.ServerSpeedProvider; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/NavigatableSimiScreen.java b/src/main/java/com/simibubi/create/foundation/ponder/NavigatableSimiScreen.java index b0d1ba1ea..b1cc3a9e8 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/NavigatableSimiScreen.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/NavigatableSimiScreen.java @@ -11,14 +11,10 @@ import org.lwjgl.glfw.GLFW; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.AllItems; import com.simibubi.create.foundation.gui.AbstractSimiScreen; -import com.simibubi.create.foundation.gui.IScreenRenderable; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; -import com.simibubi.create.foundation.ponder.content.PonderTagIndexScreen; -import com.simibubi.create.foundation.ponder.content.PonderTagScreen; import com.simibubi.create.foundation.ponder.ui.PonderButton; import com.simibubi.create.foundation.utility.Color; import com.simibubi.create.foundation.utility.Lang; @@ -28,7 +24,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.Mth; -import net.minecraft.world.item.ItemStack; public abstract class NavigatableSimiScreen extends AbstractSimiScreen { @@ -44,8 +39,7 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { protected PonderButton backTrack; public NavigatableSimiScreen() { - Window window = Minecraft.getInstance() - .getWindow(); + Window window = Minecraft.getInstance().getWindow(); depthPointX = window.getGuiScaledWidth() / 2; depthPointY = window.getGuiScaledHeight() / 2; } @@ -66,6 +60,7 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { @Override protected void init() { super.init(); + backTrack = null; List screenHistory = ScreenOpener.getScreenHistory(); if (screenHistory.isEmpty()) @@ -73,27 +68,23 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { if (!(screenHistory.get(0) instanceof NavigatableSimiScreen)) return; - Screen screen = screenHistory.get(0); - IScreenRenderable icon = null; - ItemStack altIcon = null; + NavigatableSimiScreen screen = (NavigatableSimiScreen) screenHistory.get(0); - if (screen instanceof PonderTagIndexScreen) - altIcon = AllItems.WRENCH.asStack(); - if (screen instanceof PonderUI) - altIcon = ((PonderUI) screen).stack; - if (screen instanceof PonderTagScreen) - icon = ((PonderTagScreen) screen).getTag(); - - widgets.add(backTrack = new PonderButton(31, height - 31 - 20).enableFade(0, 5) + addRenderableWidget(backTrack = new PonderButton(31, height - 31 - 20).enableFade(0, 5) .withCallback(() -> ScreenOpener.openPreviousScreen(this, Optional.empty()))); backTrack.fade(1); - if (icon != null) - backTrack.showing(icon); - if (altIcon != null) - backTrack.showing(altIcon); + screen.initBackTrackIcon(backTrack); } + /** + * Called when {@code this} represents the previous screen to + * initialize the {@code backTrack} icon of the current screen. + * + * @param backTrack The backTrack button of the current screen. + */ + protected abstract void initBackTrackIcon(PonderButton backTrack); + @Override public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) { super.render(ms, mouseX, mouseY, partialTicks); @@ -156,12 +147,10 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { ms.pushPose(); // use the buffer texture - Minecraft.getInstance() - .getMainRenderTarget() + minecraft.getMainRenderTarget() .bindWrite(true); - Window window = Minecraft.getInstance() - .getWindow(); + Window window = minecraft.getWindow(); int dpx = window.getGuiScaledWidth() / 2; int dpy = window.getGuiScaledHeight() / 2; if (lastScreen instanceof AbstractSimiScreen) { @@ -218,7 +207,7 @@ public abstract class NavigatableSimiScreen extends AbstractSimiScreen { if (history.isEmpty()) return; - history.add(0, Minecraft.getInstance().screen); + history.add(0, minecraft.screen); int spacing = 20; List names = history.stream() diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderProgressBar.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderProgressBar.java index 0c589da24..a438e9a44 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderProgressBar.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderProgressBar.java @@ -3,9 +3,9 @@ package com.simibubi.create.foundation.ponder; import javax.annotation.Nonnull; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.BoxElement; import com.simibubi.create.foundation.gui.Theme; -import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; +import com.simibubi.create.foundation.gui.element.BoxElement; +import com.simibubi.create.foundation.gui.widget.AbstractSimiWidget; import com.simibubi.create.foundation.utility.animation.LerpedFloat; import it.unimi.dsi.fastutil.ints.IntList; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java b/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java index 8ca1ac4e5..b7ee89ab2 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/PonderUI.java @@ -8,8 +8,6 @@ import java.util.List; import java.util.Random; import java.util.stream.IntStream; -import org.lwjgl.opengl.GL11; - import com.mojang.blaze3d.platform.ClipboardManager; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; @@ -19,11 +17,11 @@ import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.gui.AllGuiTextures; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.BoxElement; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; +import com.simibubi.create.foundation.gui.element.BoxElement; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.ponder.PonderScene.SceneTransform; import com.simibubi.create.foundation.ponder.content.DebugScenes; import com.simibubi.create.foundation.ponder.content.PonderChapter; @@ -47,7 +45,7 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.Options; import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.MutableComponent; @@ -158,7 +156,6 @@ public class PonderUI extends NavigatableSimiScreen { @Override protected void init() { - widgets.clear(); super.init(); tagButtons = new ArrayList<>(); @@ -176,7 +173,7 @@ public class PonderUI extends NavigatableSimiScreen { ScreenOpener.transitionTo(new PonderTagScreen(t)); }); - widgets.add(b2); + addRenderableWidget(b2); tagButtons.add(b2); LerpedFloat chase = LerpedFloat.linear() @@ -200,10 +197,10 @@ public class PonderUI extends NavigatableSimiScreen { int pX = (width / 2) - 110; int pY = bY + 20 + 4; int pW = width - 2 * pX; - widgets.add(progressBar = new PonderProgressBar(this, pX, pY, pW, 1)); + addRenderableWidget(progressBar = new PonderProgressBar(this, pX, pY, pW, 1)); } - widgets.add(scan = new PonderButton(bX, bY) + addRenderableWidget(scan = new PonderButton(bX, bY) .withShortcut(bindings.keyDrop) .showing(AllIcons.I_MTD_SCAN) .enableFade(0, 5) @@ -216,47 +213,52 @@ public class PonderUI extends NavigatableSimiScreen { ponderPartialTicksPaused = minecraft.getFrameTime(); })); - widgets.add(slowMode = new PonderButton(width - 20 - 31, bY) + addRenderableWidget(slowMode = new PonderButton(width - 20 - 31, bY) .showing(AllIcons.I_MTD_SLOW_MODE) .enableFade(0, 5) .withCallback(() -> setComfyReadingEnabled(!isComfyReadingEnabled()))); if (PonderIndex.EDITOR_MODE) { - widgets.add(userMode = new PonderButton(width - 50 - 31, bY) + addRenderableWidget(userMode = new PonderButton(width - 50 - 31, bY) .showing(AllIcons.I_MTD_USER_MODE) .enableFade(0, 5) .withCallback(() -> userViewMode = !userViewMode)); } bX += 50 + spacing; - widgets.add(left = new PonderButton(bX, bY) + addRenderableWidget(left = new PonderButton(bX, bY) .withShortcut(bindings.keyLeft) .showing(AllIcons.I_MTD_LEFT) .enableFade(0, 5) .withCallback(() -> this.scroll(false))); bX += 20 + spacing; - widgets.add(close = new PonderButton(bX, bY) + addRenderableWidget(close = new PonderButton(bX, bY) .withShortcut(bindings.keyInventory) .showing(AllIcons.I_MTD_CLOSE) .enableFade(0, 5) .withCallback(this::onClose)); bX += 20 + spacing; - widgets.add(right = new PonderButton(bX, bY) + addRenderableWidget(right = new PonderButton(bX, bY) .withShortcut(bindings.keyRight) .showing(AllIcons.I_MTD_RIGHT) .enableFade(0, 5) .withCallback(() -> this.scroll(true))); bX += 50 + spacing; - widgets.add(replay = new PonderButton(bX, bY) + addRenderableWidget(replay = new PonderButton(bX, bY) .withShortcut(bindings.keyDown) .showing(AllIcons.I_MTD_REPLAY) .enableFade(0, 5) .withCallback(this::replay)); } + @Override + protected void initBackTrackIcon(PonderButton backTrack) { + backTrack.showing(stack); + } + @Override public void tick() { super.tick(); @@ -309,8 +311,6 @@ public class PonderUI extends NavigatableSimiScreen { } else extendedTickTimer--; - progressBar.tick(); - if (activeScene.currentTime == activeScene.totalTime - 1) finishingFlashWarmup = 30; if (finishingFlashWarmup > 0) { @@ -544,8 +544,8 @@ public class PonderUI extends NavigatableSimiScreen { PonderScene activeScene = scenes.get(index); boolean noWidgetsHovered = true; - for (AbstractWidget widget : widgets) - noWidgetsHovered &= !widget.isMouseOver(mouseX, mouseY); + for (GuiEventListener child : children()) + noWidgetsHovered &= !child.isMouseOver(mouseX, mouseY); int tooltipColor = Theme.i(Theme.Key.TEXT_DARKER); { @@ -662,9 +662,9 @@ public class PonderUI extends NavigatableSimiScreen { } // Widgets - widgets.forEach(w -> { - if (w instanceof PonderButton) { - ((PonderButton) w).fade().startWithValue(fade); + renderables.forEach(w -> { + if (w instanceof PonderButton button) { + button.fade().startWithValue(fade); } }); @@ -709,14 +709,13 @@ public class PonderUI extends NavigatableSimiScreen { float fadedWidth = 200 * chase.getValue(partialTicks); UIRenderHelper.streak(ms, 0, 0, 12, 26, (int) fadedWidth); - GL11.glScissor((int) (x * s), 0, (int) (fadedWidth * s), (int) (height * s)); - GL11.glEnable(GL11.GL_SCISSOR_TEST); + RenderSystem.enableScissor((int) (x * s), 0, (int) (fadedWidth * s), (int) (height * s)); String tagName = this.tags.get(i) .getTitle(); font.draw(ms, tagName, 3, 8, Theme.i(Theme.Key.TEXT_ACCENT_SLIGHT)); - GL11.glDisable(GL11.GL_SCISSOR_TEST); + RenderSystem.disableScissor(); ms.popPose(); }); @@ -900,8 +899,8 @@ public class PonderUI extends NavigatableSimiScreen { ms.translate(divotX + divotRadius, divotY + divotRadius, 10); ms.mulPose(Vector3f.ZP.rotationDegrees(divotRotation)); ms.translate(-divotRadius, -divotRadius, 0); - AllGuiTextures.SPEECH_TOOLTIP_BACKGROUND.draw(ms, 0, 0); - AllGuiTextures.SPEECH_TOOLTIP_COLOR.draw(ms, 0, 0, c); + AllGuiTextures.SPEECH_TOOLTIP_BACKGROUND.render(ms, 0, 0); + AllGuiTextures.SPEECH_TOOLTIP_COLOR.render(ms, 0, 0, c); ms.popPose(); if (returnWithLocalTransform) { diff --git a/src/main/java/com/simibubi/create/foundation/ponder/SceneBuilder.java b/src/main/java/com/simibubi/create/foundation/ponder/SceneBuilder.java index f7dce25d1..391c7efbd 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/SceneBuilder.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/SceneBuilder.java @@ -328,9 +328,9 @@ public class SceneBuilder { } public void createRedstoneParticles(BlockPos pos, int color, int amount) { - Vec3 rgb = Color.vectorFromRGB(color); + Vector3f rgb = new Color(color).asVectorF(); addInstruction(new EmitParticlesInstruction(VecHelper.getCenterOf(pos), Emitter.withinBlockSpace( - new DustParticleOptions(new Vector3f(rgb), 1), Vec3.ZERO), amount, 2)); + new DustParticleOptions(rgb, 1), Vec3.ZERO), amount, 2)); } } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderChapter.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderChapter.java index 820e99cf1..feb8cac9b 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderChapter.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderChapter.java @@ -4,14 +4,14 @@ import javax.annotation.Nonnull; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.IScreenRenderable; +import com.simibubi.create.foundation.gui.element.ScreenElement; import com.simibubi.create.foundation.ponder.PonderLocalization; import com.simibubi.create.foundation.ponder.PonderRegistry; import net.minecraft.client.gui.GuiComponent; import net.minecraft.resources.ResourceLocation; -public class PonderChapter implements IScreenRenderable { +public class PonderChapter implements ScreenElement { private final ResourceLocation id; private final ResourceLocation icon; @@ -36,7 +36,7 @@ public class PonderChapter implements IScreenRenderable { } @Override - public void draw(PoseStack ms, GuiComponent screen, int x, int y) { + public void render(PoseStack ms, int x, int y) { ms.pushPose(); RenderSystem.setShaderTexture(0, icon); ms.scale(0.25f, 0.25f, 1); diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndexScreen.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndexScreen.java index a89e2bf4a..8a9c43503 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndexScreen.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderIndexScreen.java @@ -7,6 +7,7 @@ import java.util.Objects; import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllItems; import com.simibubi.create.content.contraptions.components.crank.ValveHandleBlock; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.Theme; @@ -18,7 +19,7 @@ import com.simibubi.create.foundation.ponder.ui.ChapterLabel; import com.simibubi.create.foundation.ponder.ui.LayoutHelper; import com.simibubi.create.foundation.ponder.ui.PonderButton; -import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.renderer.Rect2i; import net.minecraft.util.Mth; import net.minecraft.world.item.BlockItem; @@ -48,7 +49,6 @@ public class PonderIndexScreen extends NavigatableSimiScreen { @Override protected void init() { - widgets.clear(); super.init(); chapters.clear(); @@ -88,7 +88,7 @@ public class PonderIndexScreen extends NavigatableSimiScreen { ScreenOpener.transitionTo(PonderUI.of(chapter)); }); - widgets.add(label); + addRenderableWidget(label); layout.next(); } @@ -115,12 +115,17 @@ public class PonderIndexScreen extends NavigatableSimiScreen { ScreenOpener.transitionTo(PonderUI.of(new ItemStack(item))); }); - widgets.add(b); + addRenderableWidget(b); layout.next(); } } + @Override + protected void initBackTrackIcon(PonderButton backTrack) { + backTrack.showing(AllItems.WRENCH.asStack()); + } + private static boolean exclusions(Item item) { if (item instanceof BlockItem) { Block block = ((BlockItem) item).getBlock(); @@ -140,11 +145,12 @@ public class PonderIndexScreen extends NavigatableSimiScreen { Window w = minecraft.getWindow(); double mouseX = minecraft.mouseHandler.xpos() * w.getGuiScaledWidth() / w.getScreenWidth(); double mouseY = minecraft.mouseHandler.ypos() * w.getGuiScaledHeight() / w.getScreenHeight(); - for (AbstractWidget widget : widgets) { - if (widget instanceof PonderButton) - if (widget.isMouseOver(mouseX, mouseY)) { - hoveredItem = ((PonderButton) widget).getItem(); + for (GuiEventListener child : children()) { + if (child instanceof PonderButton button) { + if (button.isMouseOver(mouseX, mouseY)) { + hoveredItem = button.getItem(); } + } } } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTag.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTag.java index 6a3c11525..bae29b999 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTag.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTag.java @@ -5,8 +5,8 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.Create; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.IScreenRenderable; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.element.ScreenElement; import com.simibubi.create.foundation.ponder.PonderLocalization; import com.simibubi.create.foundation.ponder.PonderRegistry; @@ -19,7 +19,7 @@ import net.minecraft.world.level.block.Blocks; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public class PonderTag implements IScreenRenderable { +public class PonderTag implements ScreenElement { public static final PonderTag @@ -146,7 +146,7 @@ public class PonderTag implements IScreenRenderable { @Override @OnlyIn(Dist.CLIENT) - public void draw(PoseStack ms, GuiComponent screen, int x, int y) { + public void render(PoseStack ms, int x, int y) { ms.pushPose(); ms.translate(x, y, 0); if (icon != null) { diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagIndexScreen.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagIndexScreen.java index be34a64f3..1419479ec 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagIndexScreen.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagIndexScreen.java @@ -8,11 +8,11 @@ import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.BoxElement; -import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; +import com.simibubi.create.foundation.gui.element.BoxElement; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.item.TooltipHelper; import com.simibubi.create.foundation.ponder.NavigatableSimiScreen; import com.simibubi.create.foundation.ponder.PonderLocalization; @@ -24,7 +24,7 @@ import com.simibubi.create.foundation.utility.FontHelper; import com.simibubi.create.foundation.utility.Lang; import net.minecraft.ChatFormatting; -import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.renderer.Rect2i; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; @@ -51,7 +51,6 @@ public class PonderTagIndexScreen extends NavigatableSimiScreen { @Override protected void init() { - widgets.clear(); super.init(); List tags = PonderRegistry.TAGS.getListedTags(); @@ -68,16 +67,21 @@ public class PonderTagIndexScreen extends NavigatableSimiScreen { centerScalingOn(mouseX, mouseY); ScreenOpener.transitionTo(new PonderTagScreen(i)); }); - widgets.add(b); + addRenderableWidget(b); layout.next(); } - widgets.add(backTrack = new PonderButton(31, height - 31 - 20).enableFade(0, 5) + addRenderableWidget(backTrack = new PonderButton(31, height - 31 - 20).enableFade(0, 5) .showing(AllIcons.I_MTD_CLOSE) .withCallback(() -> ScreenOpener.openPreviousScreen(this, Optional.empty()))); backTrack.fade(1); } + @Override + protected void initBackTrackIcon(PonderButton backTrack) { + backTrack.showing(AllItems.WRENCH.asStack()); + } + @Override public void tick() { super.tick(); @@ -87,12 +91,12 @@ public class PonderTagIndexScreen extends NavigatableSimiScreen { Window w = minecraft.getWindow(); double mouseX = minecraft.mouseHandler.xpos() * w.getGuiScaledWidth() / w.getScreenWidth(); double mouseY = minecraft.mouseHandler.ypos() * w.getGuiScaledHeight() / w.getScreenHeight(); - for (AbstractWidget widget : widgets) { - if (widget == backTrack) + for (GuiEventListener child : children()) { + if (child == backTrack) continue; - if (widget instanceof PonderButton) - if (widget.isMouseOver(mouseX, mouseY)) - hoveredItem = ((PonderButton) widget).getTag(); + if (child instanceof PonderButton button) + if (button.isMouseOver(mouseX, mouseY)) + hoveredItem = button.getTag(); } } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java index 4e5e52e4e..ea24bf7bb 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/content/PonderTagScreen.java @@ -8,10 +8,10 @@ import com.mojang.blaze3d.platform.Window; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.Create; -import com.simibubi.create.foundation.gui.BoxElement; import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; +import com.simibubi.create.foundation.gui.element.BoxElement; import com.simibubi.create.foundation.ponder.NavigatableSimiScreen; import com.simibubi.create.foundation.ponder.PonderLocalization; import com.simibubi.create.foundation.ponder.PonderRegistry; @@ -22,7 +22,7 @@ import com.simibubi.create.foundation.ponder.ui.PonderButton; import com.simibubi.create.foundation.utility.FontHelper; import com.simibubi.create.foundation.utility.Lang; -import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.client.renderer.Rect2i; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -55,7 +55,6 @@ public class PonderTagScreen extends NavigatableSimiScreen { @Override protected void init() { - widgets.clear(); super.init(); // items @@ -103,7 +102,7 @@ public class PonderTagScreen extends NavigatableSimiScreen { .animateColors(false); } - widgets.add(b); + addRenderableWidget(b); layout.next(); } @@ -130,7 +129,7 @@ public class PonderTagScreen extends NavigatableSimiScreen { .animateColors(false); } - widgets.add(b); + addRenderableWidget(b); } // chapters @@ -150,12 +149,17 @@ public class PonderTagScreen extends NavigatableSimiScreen { ScreenOpener.transitionTo(PonderUI.of(chapter)); }); - widgets.add(label); + addRenderableWidget(label); layout.next(); } } + @Override + protected void initBackTrackIcon(PonderButton backTrack) { + backTrack.showing(tag); + } + @Override public void tick() { super.tick(); @@ -165,12 +169,12 @@ public class PonderTagScreen extends NavigatableSimiScreen { Window w = minecraft.getWindow(); double mouseX = minecraft.mouseHandler.xpos() * w.getGuiScaledWidth() / w.getScreenWidth(); double mouseY = minecraft.mouseHandler.ypos() * w.getGuiScaledHeight() / w.getScreenHeight(); - for (AbstractWidget widget : widgets) { - if (widget == backTrack) + for (GuiEventListener child : children()) { + if (child == backTrack) continue; - if (widget instanceof PonderButton) - if (widget.isMouseOver(mouseX, mouseY)) { - hoveredItem = ((PonderButton) widget).getItem(); + if (child instanceof PonderButton button) + if (button.isMouseOver(mouseX, mouseY)) { + hoveredItem = button.getItem(); } } } @@ -212,7 +216,7 @@ public class PonderTagScreen extends NavigatableSimiScreen { ms.pushPose(); ms.translate(23, 23, 10); ms.scale(1.66f, 1.66f, 1.66f); - tag.draw(ms, this, 0, 0); + tag.render(ms, 0, 0); ms.popPose(); ms.popPose(); diff --git a/src/main/java/com/simibubi/create/foundation/ponder/elements/InputWindowElement.java b/src/main/java/com/simibubi/create/foundation/ponder/elements/InputWindowElement.java index 61f9fad3d..3f1fb07da 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/elements/InputWindowElement.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/elements/InputWindowElement.java @@ -5,7 +5,7 @@ import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllItems; import com.simibubi.create.Create; import com.simibubi.create.foundation.gui.AllIcons; -import com.simibubi.create.foundation.gui.GuiGameElement; +import com.simibubi.create.foundation.gui.element.GuiGameElement; import com.simibubi.create.foundation.ponder.PonderLocalization; import com.simibubi.create.foundation.ponder.PonderScene; import com.simibubi.create.foundation.ponder.PonderUI; @@ -131,7 +131,7 @@ public class InputWindowElement extends AnimatedOverlayElement { ms.pushPose(); ms.translate(keyWidth, 0, 0); ms.scale(1.5f, 1.5f, 1.5f); - icon.draw(ms, screen, 0, 0); + icon.render(ms, 0, 0, screen); ms.popPose(); } diff --git a/src/main/java/com/simibubi/create/foundation/ponder/elements/TextWindowElement.java b/src/main/java/com/simibubi/create/foundation/ponder/elements/TextWindowElement.java index 30fe98762..437f71e21 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/elements/TextWindowElement.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/elements/TextWindowElement.java @@ -5,8 +5,8 @@ import java.util.function.Supplier; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Matrix4f; -import com.simibubi.create.foundation.gui.BoxElement; import com.simibubi.create.foundation.gui.Theme; +import com.simibubi.create.foundation.gui.element.BoxElement; import com.simibubi.create.foundation.ponder.PonderLocalization; import com.simibubi.create.foundation.ponder.PonderScene; import com.simibubi.create.foundation.ponder.PonderUI; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/ui/ChapterLabel.java b/src/main/java/com/simibubi/create/foundation/ponder/ui/ChapterLabel.java index d5e9e9d3c..1429bd876 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/ui/ChapterLabel.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/ui/ChapterLabel.java @@ -7,7 +7,7 @@ import javax.annotation.Nonnull; import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.UIRenderHelper; -import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget; +import com.simibubi.create.foundation.gui.widget.AbstractSimiWidget; import com.simibubi.create.foundation.ponder.content.PonderChapter; import net.minecraft.client.Minecraft; diff --git a/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java b/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java index ac2ba0dd1..e5e700afa 100644 --- a/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java +++ b/src/main/java/com/simibubi/create/foundation/ponder/ui/PonderButton.java @@ -3,12 +3,12 @@ package com.simibubi.create.foundation.ponder.ui; import javax.annotation.Nonnull; import com.mojang.blaze3d.vertex.PoseStack; -import com.simibubi.create.foundation.gui.GuiGameElement; -import com.simibubi.create.foundation.gui.RenderElement; import com.simibubi.create.foundation.gui.Theme; import com.simibubi.create.foundation.gui.Theme.Key; -import com.simibubi.create.foundation.gui.widgets.BoxWidget; -import com.simibubi.create.foundation.gui.widgets.ElementWidget; +import com.simibubi.create.foundation.gui.element.GuiGameElement; +import com.simibubi.create.foundation.gui.element.RenderElement; +import com.simibubi.create.foundation.gui.widget.BoxWidget; +import com.simibubi.create.foundation.gui.widget.ElementWidget; import com.simibubi.create.foundation.ponder.content.PonderTag; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Color; diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java index 294e91205..0059fec11 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/SmartTileEntity.java @@ -8,8 +8,8 @@ import java.util.function.Consumer; import com.simibubi.create.api.event.TileEntityBehaviourEvent; import com.simibubi.create.content.schematics.ItemRequirement; -import com.simibubi.create.foundation.gui.IInteractionChecker; import com.simibubi.create.foundation.tileEntity.behaviour.BehaviourType; +import com.simibubi.create.foundation.utility.IInteractionChecker; import com.simibubi.create.foundation.utility.IPartialSafeNBT; import net.minecraft.core.BlockPos; diff --git a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBox.java b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBox.java index 94e4309d1..a19af026b 100644 --- a/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBox.java +++ b/src/main/java/com/simibubi/create/foundation/tileEntity/behaviour/ValueBox.java @@ -208,7 +208,7 @@ public class ValueBox extends ChasingAABBOutline { float scale = 4 * 16; ms.scale(scale, scale, scale); ms.translate(-.5f, -.5f, 1 / 32f); - icon.draw(ms, buffer, 0xFFFFFF); + icon.render(ms, buffer, 0xFFFFFF); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/Color.java b/src/main/java/com/simibubi/create/foundation/utility/Color.java index aa2b9a5c0..aa4e32f9b 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/Color.java +++ b/src/main/java/com/simibubi/create/foundation/utility/Color.java @@ -5,6 +5,7 @@ import java.util.function.UnaryOperator; import javax.annotation.Nonnull; import com.google.common.hash.Hashing; +import com.mojang.math.Vector3f; import net.minecraft.util.Mth; import net.minecraft.world.phys.Vec3; @@ -146,6 +147,10 @@ public class Color { return new Vec3(getRedAsFloat(), getGreenAsFloat(), getBlueAsFloat()); } + public Vector3f asVectorF() { + return new Vector3f(getRedAsFloat(), getGreenAsFloat(), getBlueAsFloat()); + } + public Color setRed(int r) { return ensureMutable().setRedUnchecked(r); } @@ -182,14 +187,6 @@ public class Color { return ensureMutable().setAlphaUnchecked((int) (getAlpha() * Mth.clamp(factor, 0, 1))); } - @Deprecated - public Color applyAlpha(float alpha) { - if (getAlpha() == 0) - return setAlpha(alpha); - else - return scaleAlpha(alpha); - } - public Color mixWith(Color other, float weight) { return ensureMutable() .setRedUnchecked((int) (getRed() + (other.getRed() - getRed()) * weight)) @@ -313,15 +310,4 @@ public class Color { .mixWith(WHITE, 0.5f); } - /** - * Try not to introduce new usages of this method and instead use Color instances directly - */ - @Deprecated - public static Vec3 vectorFromRGB(int color) { - int r = (color >> 16) & 0xFF; - int g = (color >> 8) & 0xFF; - int b = color & 0xFF; - return new Vec3(r, g, b).scale(1 / 255d); - } - } diff --git a/src/main/java/com/simibubi/create/foundation/gui/IInteractionChecker.java b/src/main/java/com/simibubi/create/foundation/utility/IInteractionChecker.java similarity index 73% rename from src/main/java/com/simibubi/create/foundation/gui/IInteractionChecker.java rename to src/main/java/com/simibubi/create/foundation/utility/IInteractionChecker.java index 1c7c2498f..86d52d34e 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/IInteractionChecker.java +++ b/src/main/java/com/simibubi/create/foundation/utility/IInteractionChecker.java @@ -1,4 +1,4 @@ -package com.simibubi.create.foundation.gui; +package com.simibubi.create.foundation.utility; import net.minecraft.world.entity.player.Player; diff --git a/src/main/java/com/simibubi/create/foundation/utility/ServerSpeedProvider.java b/src/main/java/com/simibubi/create/foundation/utility/ServerSpeedProvider.java index a1d2e68ab..350c6d5dd 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/ServerSpeedProvider.java +++ b/src/main/java/com/simibubi/create/foundation/utility/ServerSpeedProvider.java @@ -3,9 +3,9 @@ package com.simibubi.create.foundation.utility; import java.util.function.Supplier; import com.simibubi.create.foundation.config.AllConfigs; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.networking.AllPackets; import com.simibubi.create.foundation.networking.SimplePacketBase; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedAngle.java b/src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedAngle.java similarity index 67% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedAngle.java rename to src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedAngle.java index d8dd660e8..ccdd17b68 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedAngle.java +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedAngle.java @@ -1,7 +1,11 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.utility.animation; import com.simibubi.create.foundation.utility.AngleHelper; +/** + * Use {@link LerpedFloat} instead. + */ +@Deprecated public class InterpolatedAngle extends InterpolatedValue { public float get(float partialTicks) { diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedChasingAngle.java b/src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedChasingAngle.java similarity index 75% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedChasingAngle.java rename to src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedChasingAngle.java index b9f4f1cc2..ef944296e 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedChasingAngle.java +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedChasingAngle.java @@ -1,7 +1,11 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.utility.animation; import com.simibubi.create.foundation.utility.AngleHelper; +/** + * Use {@link LerpedFloat} instead. + */ +@Deprecated public class InterpolatedChasingAngle extends InterpolatedChasingValue { public float get(float partialTicks) { diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedChasingValue.java b/src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedChasingValue.java similarity index 86% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedChasingValue.java rename to src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedChasingValue.java index 92a3efe88..099623ad6 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedChasingValue.java +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedChasingValue.java @@ -1,5 +1,9 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.utility.animation; +/** + * Use {@link LerpedFloat} instead. + */ +@Deprecated public class InterpolatedChasingValue extends InterpolatedValue { float speed = 0.5f; diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedValue.java b/src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedValue.java similarity index 81% rename from src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedValue.java rename to src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedValue.java index 3f4c193ab..0b8e1893f 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/InterpolatedValue.java +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/InterpolatedValue.java @@ -1,7 +1,11 @@ -package com.simibubi.create.foundation.gui.widgets; +package com.simibubi.create.foundation.utility.animation; import net.minecraft.util.Mth; +/** + * Use {@link LerpedFloat} instead. + */ +@Deprecated public class InterpolatedValue { public float value = 0; diff --git a/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java b/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java index 6c703caa3..b7d2a15ab 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/LerpedFloat.java @@ -9,15 +9,15 @@ import net.minecraft.util.Mth; // InterpolatedChasingValue, InterpolatedValue, InterpolatedChasingAngle, InterpolatedAngle public class LerpedFloat { - Interpolater interpolater; - float previousValue; - float value; + protected Interpolater interpolater; + protected float previousValue; + protected float value; - Chaser chaseFunction; - float chaseTarget; - float chaseSpeed; + protected Chaser chaseFunction; + protected float chaseTarget; + protected float chaseSpeed; - boolean forcedSync; + protected boolean forcedSync; public LerpedFloat(Interpolater interpolater) { this.interpolater = interpolater; @@ -111,7 +111,7 @@ public class LerpedFloat { readChaser(compoundNBT); } - private void readChaser(CompoundTag compoundNBT) { + protected void readChaser(CompoundTag compoundNBT) { chaseSpeed = compoundNBT.getFloat("Speed"); chaseTarget = compoundNBT.getFloat("Target"); } @@ -124,11 +124,11 @@ public class LerpedFloat { @FunctionalInterface public interface Chaser { - public static final Chaser IDLE = (c, s, t) -> (float) c; - public static final Chaser EXP = exp(Double.MAX_VALUE); - public static final Chaser LINEAR = (c, s, t) -> (float) (c + Mth.clamp(t - c, -s, s)); + Chaser IDLE = (c, s, t) -> (float) c; + Chaser EXP = exp(Double.MAX_VALUE); + Chaser LINEAR = (c, s, t) -> (float) (c + Mth.clamp(t - c, -s, s)); - public static Chaser exp(double maxEffectiveSpeed) { + static Chaser exp(double maxEffectiveSpeed) { return (c, s, t) -> (float) (c + Mth.clamp((t - c) * s, -maxEffectiveSpeed, maxEffectiveSpeed)); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementHelpers.java b/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementHelpers.java index 4dd1e9302..afe1b427f 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementHelpers.java +++ b/src/main/java/com/simibubi/create/foundation/utility/placement/PlacementHelpers.java @@ -16,10 +16,10 @@ import com.mojang.math.Vector3f; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.CClient; import com.simibubi.create.foundation.gui.AllGuiTextures; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingAngle; -import com.simibubi.create.foundation.gui.widgets.InterpolatedChasingValue; import com.simibubi.create.foundation.utility.AngleHelper; import com.simibubi.create.foundation.utility.VecHelper; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingAngle; +import com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel;