Initial 1.19.3 Porting with new Creative Tab API
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package me.hypherionmc.craterlib.api.inventory;
|
||||
|
||||
import me.hypherionmc.craterlib.systems.internal.CreativeTabRegistry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.CreativeModeTabs;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CraterCreativeModeTab implements Supplier<CreativeModeTab> {
|
||||
|
||||
private final ResourceLocation resourceLocation;
|
||||
private final ItemStack icon;
|
||||
private final String backgroundSuffix;
|
||||
private CreativeModeTab tab;
|
||||
|
||||
protected CraterCreativeModeTab(Builder builder) {
|
||||
this.resourceLocation = builder.location;
|
||||
this.icon = builder.stack == null ? ItemStack.EMPTY : builder.stack;
|
||||
this.backgroundSuffix = builder.backgroundSuffix == null ? "" : builder.backgroundSuffix;
|
||||
|
||||
CreativeTabRegistry.registerTab(this);
|
||||
}
|
||||
|
||||
public ResourceLocation getResourceLocation() {
|
||||
return this.resourceLocation;
|
||||
}
|
||||
|
||||
public ItemStack getIcon() {
|
||||
return icon;
|
||||
}
|
||||
|
||||
public String getBackgroundSuffix() {
|
||||
return backgroundSuffix;
|
||||
}
|
||||
|
||||
public void setTab(CreativeModeTab tab) {
|
||||
this.tab = tab;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final ResourceLocation location;
|
||||
private ItemStack stack;
|
||||
private String backgroundSuffix;
|
||||
|
||||
public Builder(ResourceLocation location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public Builder setIcon(ItemStack icon) {
|
||||
stack = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder backgroundSuffix(String backgroundSuffix) {
|
||||
this.backgroundSuffix = backgroundSuffix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CraterCreativeModeTab build() {
|
||||
return new CraterCreativeModeTab(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public CreativeModeTab get() {
|
||||
return tab == null ? CreativeModeTabs.getDefaultTab() : tab;
|
||||
}
|
||||
}
|
@@ -2,7 +2,6 @@ package me.hypherionmc.craterlib.client.gui.config;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.*;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import me.hypherionmc.craterlib.CraterConstants;
|
||||
import me.hypherionmc.craterlib.client.gui.config.widgets.*;
|
||||
import me.hypherionmc.craterlib.common.config.ModuleConfig;
|
||||
@@ -17,6 +16,7 @@ import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import org.joml.Matrix4f;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.lang.reflect.Field;
|
||||
|
@@ -19,8 +19,8 @@ public class AbstractConfigWidget<T, W extends AbstractWidget> extends BaseWidge
|
||||
public void render(Minecraft minecraft, Font font, int x, int y, int width, int height, PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
super.render(minecraft, font, x, y, width, height, matrices, mouseX, mouseY, delta);
|
||||
int i = (widget instanceof EditBox ? 1 : 0);
|
||||
widget.x = x + width - 200 - resetButtonOffset + i;
|
||||
widget.y = y + i + 1;
|
||||
widget.setX(x + width - 200 - resetButtonOffset + i);
|
||||
widget.setY(y + i + 1);
|
||||
widget.render(matrices, mouseX, mouseY, delta);
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ import net.minecraft.network.chat.TextColor;
|
||||
public class BaseWidget<T> extends Option<T> {
|
||||
|
||||
public static final int resetButtonOffset = 48;
|
||||
private final Button resetButton = addChild(new Button(0, 0, 46, 20, Component.literal("Reset"), this::onResetPressed));
|
||||
private final Button resetButton = addChild(Button.builder(Component.literal("Reset"), this::onResetPressed).size(46, 20).build());
|
||||
private boolean hideReset = false;
|
||||
|
||||
private boolean isSubConfig = false;
|
||||
@@ -51,8 +51,8 @@ public class BaseWidget<T> extends Option<T> {
|
||||
text.withStyle(ChatFormatting.GRAY);
|
||||
}
|
||||
font.draw(matrices, text, x, y + 8, 0xFFFFFF);
|
||||
resetButton.x = x + width - 46;
|
||||
resetButton.y = y + 1;
|
||||
resetButton.setX(x + width - 46);
|
||||
resetButton.setY(y + 1);
|
||||
resetButton.active = isNotDefault();
|
||||
if (!hideReset) {
|
||||
resetButton.render(matrices, mouseX, mouseY, delta);
|
||||
|
@@ -30,6 +30,11 @@ public class InternalConfigButton extends AbstractButton {
|
||||
super.render(poseStack, i, j, f);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateWidgetNarration(NarrationElementOutput narrationElementOutput) {
|
||||
narrationElementOutput.add(NarratedElementType.USAGE, getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPress() {
|
||||
if (cancel) {
|
||||
@@ -39,9 +44,5 @@ public class InternalConfigButton extends AbstractButton {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNarration(NarrationElementOutput narrationElementOutput) {
|
||||
narrationElementOutput.add(NarratedElementType.USAGE, getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -19,7 +19,8 @@ public class SubConfigWidget<T> extends AbstractConfigWidget<T, Button> {
|
||||
this.config = config;
|
||||
this.subConfig = subConfig;
|
||||
this.screen = screen;
|
||||
this.widget = addChild(new Button(0, 0, 200, buttonHeight, Component.translatable("t.clc.opensubconfig"), this::openSubConfig));
|
||||
|
||||
this.widget = addChild(Button.builder(Component.translatable("t.clc.opensubconfig"), this::openSubConfig).size(200, buttonHeight).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -18,7 +18,7 @@ public class ToggleButton <T> extends AbstractConfigWidget<T, Button> {
|
||||
public ToggleButton(List<T> options, Function<T, Component> toComponent) {
|
||||
this.options = options;
|
||||
this.toComponent = toComponent;
|
||||
this.widget = addChild(new Button(0, 0, buttonWidth, buttonHeight, Component.empty(), this::switchNext));
|
||||
this.widget = addChild(Button.builder(Component.empty(), this::switchNext).size(buttonWidth, buttonHeight).build());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,48 +0,0 @@
|
||||
package me.hypherionmc.craterlib.client.gui.tabs;
|
||||
|
||||
import me.hypherionmc.craterlib.platform.Platform;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author HypherionSA
|
||||
* @date 16/06/2022
|
||||
* Provides a wrapper around Forge/Fabric to create a new Creative Tab
|
||||
*/
|
||||
public class CreativeTabBuilder {
|
||||
|
||||
public static Builder builder(String modid, String tabid) {
|
||||
return new Builder(modid, tabid);
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
private Supplier<ItemStack> tabIcon;
|
||||
private final String modid;
|
||||
private final String tabid;
|
||||
private String backgroundPrefix;
|
||||
|
||||
public Builder(String modid, String tabid) {
|
||||
this.modid = modid;
|
||||
this.tabid = tabid;
|
||||
}
|
||||
|
||||
public Builder setIcon(Supplier<ItemStack> stack) {
|
||||
this.tabIcon = stack;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBackgroundPrefix(String prefix) {
|
||||
this.backgroundPrefix = prefix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CreativeModeTab build() {
|
||||
return Platform.COMMON_HELPER.tabBuilder(this.modid, this.tabid, this.tabIcon, this.backgroundPrefix);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
package me.hypherionmc.craterlib.common.network;
|
||||
|
||||
// TODO: FINISH NETWORK IMPLEMENTATION
|
||||
public interface BaseNetworkPacket {
|
||||
|
||||
}
|
@@ -36,5 +36,4 @@ public interface LibCommonHelper {
|
||||
/* FABRIC ONLY */
|
||||
public void registerServerReceiver(ResourceLocation channelName, Function<FriendlyByteBuf, CraterPacket<?>> factory);
|
||||
|
||||
public CreativeModeTab tabBuilder(String modid, String tabid, Supplier<ItemStack> icon, String backgroundSuf);
|
||||
}
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package me.hypherionmc.craterlib.systems.internal;
|
||||
|
||||
import me.hypherionmc.craterlib.api.inventory.CraterCreativeModeTab;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public class CreativeTabRegistry {
|
||||
|
||||
private static final List<CraterCreativeModeTab> TABS = new ArrayList<>();
|
||||
public static void registerTab(CraterCreativeModeTab tab) {
|
||||
TABS.add(tab);
|
||||
}
|
||||
|
||||
public static List<CraterCreativeModeTab> getTABS() {
|
||||
return TABS;
|
||||
}
|
||||
|
||||
}
|
@@ -1,9 +1,9 @@
|
||||
package me.hypherionmc.craterlib.util;
|
||||
|
||||
import com.mojang.math.Vector4f;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import org.joml.Vector4f;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
|
Reference in New Issue
Block a user