Skip to content

Commit

Permalink
Merge branch 'master' into toolbelt
Browse files Browse the repository at this point in the history
  • Loading branch information
M-W-K authored Jan 6, 2025
2 parents 8561291 + 778dec6 commit 5bbb1c4
Show file tree
Hide file tree
Showing 61 changed files with 2,550 additions and 925 deletions.
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
dependencies {
// Published dependencies
api("codechicken:codechickenlib:3.2.3.358")
api("com.cleanroommc:modularui:2.5.0-rc1") { transitive = false }
api("com.cleanroommc:modularui:2.5.0-rc2") { transitive = false }
api("com.cleanroommc:groovyscript:1.2.0-hotfix1") { transitive = false }
api("CraftTweaker2:CraftTweaker2-MC1120-Main:1.12-4.1.20.700")
api("appeng:ae2-uel:v0.56.4") { transitive = false }
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/gregtech/api/cover/CoverWithUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.screen.ModularScreen;
import com.cleanroommc.modularui.utils.Alignment;
import com.cleanroommc.modularui.utils.Color;
import com.cleanroommc.modularui.utils.MouseData;
import com.cleanroommc.modularui.value.BoolValue;
import com.cleanroommc.modularui.value.sync.EnumSyncValue;
import com.cleanroommc.modularui.value.sync.IntSyncValue;
import com.cleanroommc.modularui.value.sync.PanelSyncManager;
import com.cleanroommc.modularui.widget.ParentWidget;
import com.cleanroommc.modularui.widgets.ToggleButton;
import com.cleanroommc.modularui.widgets.layout.Row;
import com.cleanroommc.modularui.widgets.layout.Flow;
import org.jetbrains.annotations.ApiStatus;

public interface CoverWithUI extends Cover, IUIHolder, IGuiHolder<SidedPosGuiData> {
Expand Down Expand Up @@ -98,12 +99,14 @@ default void markAsDirty() {
/**
* Create the Title bar widget for a Cover.
*/
static Row createTitleRow(ItemStack stack) {
return new Row()
static Flow createTitleRow(ItemStack stack) {
return Flow.row()
.pos(4, 4)
.height(16).coverChildrenWidth()
.child(new ItemDrawable(stack).asWidget().size(16).marginRight(4))
.child(IKey.str(stack.getDisplayName()).color(UI_TITLE_COLOR).asWidget().heightRel(1.0f));
.child(IKey.str(stack.getDisplayName())
.color(UI_TITLE_COLOR)
.asWidget().heightRel(1.0f));
}

/**
Expand Down Expand Up @@ -135,6 +138,7 @@ default IKey createAdjustOverlay(boolean increment) {
scale = 0.5f;
}
return IKey.str(builder.toString())
.color(Color.WHITE.main)
.scale(scale);
}

Expand Down Expand Up @@ -204,8 +208,8 @@ private BoolValue.Dynamic boolValueOf(EnumSyncValue<T> syncValue, T value) {
return new BoolValue.Dynamic(() -> syncValue.getValue() == value, $ -> syncValue.setValue(value));
}

public Row build() {
var row = new Row().marginBottom(2).coverChildrenHeight().widthRel(1f);
public Flow build() {
var row = Flow.row().marginBottom(2).coverChildrenHeight().widthRel(1f);
if (this.enumValue != null && this.syncValue != null) {
for (var enumVal : enumValue.getEnumConstants()) {
var button = new ToggleButton().size(18).marginRight(2)
Expand Down
57 changes: 55 additions & 2 deletions src/main/java/gregtech/api/metatileentity/MetaTileEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -166,6 +168,13 @@ public abstract class MetaTileEntity implements ISyncedTileEntity, CoverHolder,
@Nullable
private UUID owner = null;

private final Set<CreativeTabs> creativeTabs = new ObjectArraySet<>();

{
creativeTabs.add(CreativeTabs.SEARCH);
creativeTabs.add(GTCreativeTabs.TAB_GREGTECH_MACHINES);
}

protected MetaTileEntity(@NotNull ResourceLocation metaTileEntityId) {
this.metaTileEntityId = metaTileEntityId;
this.registry = GregTechAPI.mteManager.getRegistry(metaTileEntityId.getNamespace());
Expand Down Expand Up @@ -235,7 +244,10 @@ public void addDebugInfo(List<String> list) {}

@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World world, @NotNull List<String> tooltip,
boolean advanced) {}
boolean advanced) {
if (ConfigHolder.machines.doTerrainExplosion && getIsWeatherOrTerrainResistant())
tooltip.add(I18n.format("gregtech.universal.tooltip.terrain_resist"));
}

/**
* Override this to add extended tool information to the "Hold SHIFT to show Tool Info" tooltip section.
Expand Down Expand Up @@ -362,7 +374,7 @@ public void getSubItems(CreativeTabs creativeTab, NonNullList<ItemStack> subItem
* MachineItemBlock#addCreativeTab(CreativeTabs)
*/
public boolean isInCreativeTab(CreativeTabs creativeTab) {
return creativeTab == CreativeTabs.SEARCH || creativeTab == GTCreativeTabs.TAB_GREGTECH_MACHINES;
return creativeTabs.contains(creativeTab);
}

public String getItemSubTypeId(ItemStack itemStack) {
Expand Down Expand Up @@ -1661,4 +1673,45 @@ public AENetworkProxy getProxy() {

@Method(modid = Mods.Names.APPLIED_ENERGISTICS2)
public void gridChanged() {}

/**
* Add MTE to a creative tab. Ensure that the creative tab has been registered via
* {@link gregtech.api.block.machines.MachineItemBlock#addCreativeTab(CreativeTabs)
* MachineItemBlock#addCreativeTab(CreativeTabs)} beforehand.
*/
public void addAdditionalCreativeTabs(CreativeTabs creativeTab) {
Preconditions.checkNotNull(creativeTab, "creativeTab");
if (creativeTabs.contains(creativeTab)) {
GTLog.logger.error("{} is already in the creative tab {}.", this, creativeTab.tabLabel,
new IllegalArgumentException());
return;
}

creativeTabs.add(creativeTab);
}

public void removeFromCreativeTab(CreativeTabs creativeTab) {
Preconditions.checkNotNull(creativeTab, "creativeTab");
if (creativeTab == CreativeTabs.SEARCH) {
GTLog.logger.error("Cannot remove MTEs from the creative search tab.",
new IllegalArgumentException());
return;
}
if (creativeTab == GTCreativeTabs.TAB_GREGTECH_MACHINES &&
metaTileEntityId.getNamespace().equals(GTValues.MODID)) {
GTLog.logger.error("Cannot remove GT MTEs from the GT machines tab.", new IllegalArgumentException());
return;
}
if (!creativeTabs.contains(creativeTab)) {
GTLog.logger.error("{} is not in the creative tab {}.", this, creativeTab.tabLabel,
new IllegalArgumentException());
return;
}

creativeTabs.remove(creativeTab);
}

public Set<CreativeTabs> getCreativeTabs() {
return Collections.unmodifiableSet(creativeTabs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import gregtech.api.util.GTUtility;
import gregtech.client.renderer.texture.Textures;
import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer;
import gregtech.common.ConfigHolder;

import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand All @@ -23,10 +19,6 @@
import codechicken.lib.vec.Matrix4;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public abstract class TieredMetaTileEntity extends MetaTileEntity
implements IEnergyChangeListener, ITieredMetaTileEntity {
Expand Down Expand Up @@ -57,14 +49,6 @@ protected SimpleSidedCubeRenderer getBaseRenderer() {
return Textures.VOLTAGE_CASINGS[tier];
}

@Override
public void addInformation(ItemStack stack, @Nullable World player, @NotNull List<String> tooltip,
boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (ConfigHolder.machines.doTerrainExplosion && getIsWeatherOrTerrainResistant())
tooltip.add(I18n.format("gregtech.universal.tooltip.terrain_resist"));
}

@Override
@SideOnly(Side.CLIENT)
public Pair<TextureAtlasSprite, Integer> getParticleTexture() {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/mui/GTGuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public static class IDs {

public static final UITexture[] BUTTON_MATCH_ALL = slice("textures/gui/widget/ore_filter/button_match_all.png",
16, 32, 16, 16, true);
public static final UITexture BUTTON_LOCK = fullImage("textures/gui/widget/button_lock.png");

public static final UITexture OREDICT_ERROR = fullImage("textures/gui/widget/ore_filter/error.png");
public static final UITexture OREDICT_INFO = fullImage("textures/gui/widget/ore_filter/info.png");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gregtech/api/mui/GTGuiTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import com.cleanroommc.modularui.api.ITheme;
import com.cleanroommc.modularui.api.IThemeApi;
import com.cleanroommc.modularui.drawable.UITexture;
import com.cleanroommc.modularui.screen.Tooltip;
import com.cleanroommc.modularui.screen.RichTooltip;
import com.cleanroommc.modularui.theme.ReloadThemeEvent;
import com.cleanroommc.modularui.utils.JsonBuilder;
import org.jetbrains.annotations.Nullable;
Expand Down Expand Up @@ -108,7 +108,7 @@ public static void onReloadThemes(ReloadThemeEvent.Pre event) {
public static Builder templateBuilder(String themeId) {
Builder builder = new Builder(themeId);
builder.openCloseAnimation(0);
builder.tooltipPos(Tooltip.Pos.NEXT_TO_MOUSE);
builder.tooltipPos(RichTooltip.Pos.NEXT_TO_MOUSE);
builder.smoothProgressBar(true);
return builder;
}
Expand Down Expand Up @@ -163,7 +163,7 @@ public Builder smoothProgressBar(boolean smoothBar) {
}

/** Set the tooltip pos for this theme. Overrides global cfg. */
public Builder tooltipPos(Tooltip.Pos tooltipPos) {
public Builder tooltipPos(RichTooltip.Pos tooltipPos) {
theme.elementBuilder.add(b -> b.add("tooltipPos", tooltipPos.name()));
return this;
}
Expand Down
45 changes: 40 additions & 5 deletions src/main/java/gregtech/api/mui/GTGuis.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import net.minecraft.item.ItemStack;

import com.cleanroommc.modularui.api.widget.Interactable;
import com.cleanroommc.modularui.factory.GuiManager;
import com.cleanroommc.modularui.screen.ModularPanel;
import com.cleanroommc.modularui.utils.Alignment;
Expand All @@ -19,6 +18,8 @@

public class GTGuis {

public static final int DEFAULT_WIDTH = 176, DEFAULT_HIEGHT = 166;

@ApiStatus.Internal
public static void registerFactories() {
GuiManager.registerFactory(MetaTileEntityGuiFactory.INSTANCE);
Expand All @@ -39,9 +40,35 @@ public static ModularPanel createPanel(Cover cover, int width, int height) {
}

public static ModularPanel createPanel(ItemStack stack, int width, int height) {
MetaItem<?>.MetaValueItem valueItem = ((MetaItem<?>) stack.getItem()).getItem(stack);
if (valueItem == null) throw new IllegalArgumentException("Item must be a meta item!");
return createPanel(valueItem.unlocalizedName, width, height);
String locale;
if (stack.getItem() instanceof MetaItem<?>metaItem) {
var valueItem = metaItem.getItem(stack);
if (valueItem == null) throw new IllegalArgumentException("Item must be a meta item!");
locale = valueItem.unlocalizedName;
} else {
locale = stack.getTranslationKey();
}
return createPanel(locale, width, height);
}

public static ModularPanel createPanel(String name) {
return ModularPanel.defaultPanel(name, DEFAULT_WIDTH, DEFAULT_HIEGHT);
}

public static ModularPanel defaultPanel(MetaTileEntity mte) {
return createPanel(mte.metaTileEntityId.getPath());
}

public static ModularPanel defaultPanel(Cover cover) {
return createPanel(cover.getDefinition().getResourceLocation().getPath());
}

public static ModularPanel defaultPanel(ItemStack stack) {
return createPanel(stack, DEFAULT_WIDTH, DEFAULT_HIEGHT);
}

public static ModularPanel defaultPanel(MetaItem<?>.MetaValueItem valueItem) {
return createPanel(valueItem.unlocalizedName);
}

public static ModularPanel createPopupPanel(String name, int width, int height) {
Expand All @@ -53,6 +80,15 @@ public static ModularPanel createPopupPanel(String name, int width, int height,
return new PopupPanel(name, width, height, disableBelow, closeOnOutsideClick);
}

public static ModularPanel defaultPopupPanel(String name) {
return defaultPopupPanel(name, false, false);
}

public static ModularPanel defaultPopupPanel(String name, boolean disableBelow,
boolean closeOnOutsideClick) {
return new PopupPanel(name, DEFAULT_WIDTH, DEFAULT_HIEGHT, disableBelow, closeOnOutsideClick);
}

private static class PopupPanel extends ModularPanel {

private final boolean disableBelow;
Expand All @@ -67,7 +103,6 @@ public PopupPanel(@NotNull String name, int width, int height, boolean disableBe
.onMousePressed(mouseButton -> {
if (mouseButton == 0 || mouseButton == 1) {
this.closeIfOpen(true);
Interactable.playButtonClickSound();
return true;
}
return false;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/gregtech/api/mui/StateOverlay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package gregtech.api.mui;

import com.cleanroommc.modularui.api.drawable.IDrawable;
import com.cleanroommc.modularui.widgets.ToggleButton;

import java.util.function.Consumer;

public interface StateOverlay {

StateOverlay overlay(boolean selected, IDrawable... overlay);

StateOverlay hoverOverlay(boolean selected, IDrawable... overlay);

static ToggleButton cast(ToggleButton button, Consumer<StateOverlay> function) {
function.accept((StateOverlay) button);
return button;
}

static ToggleButton create(Consumer<StateOverlay> function) {
return cast(new ToggleButton(), function);
}
}
8 changes: 8 additions & 0 deletions src/main/java/gregtech/api/mui/UnboxFix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package gregtech.api.mui;

public interface UnboxFix {

void gregTech$useDefaultTextColor(boolean b);

void gregTech$useDefaultShadow(boolean b);
}
Loading

0 comments on commit 5bbb1c4

Please sign in to comment.