Skip to content

Commit

Permalink
Tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuqi154 committed Oct 19, 2024
1 parent 785a314 commit c8d6e82
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 52 deletions.
37 changes: 11 additions & 26 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,18 @@ configurations {
}

dependencies {
// Example optional mod dependency with JEI
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly "mezz.jei:jei-${mc_version}-common-api:${jei_version}"
// compileOnly "mezz.jei:jei-${mc_version}-neoforge-api:${jei_version}"
// We add the full version to localRuntime, not runtimeOnly, so that we do not publish a dependency on it
// localRuntime "mezz.jei:jei-${mc_version}-neoforge:${jei_version}"

// Example mod dependency using a mod jar from ./libs with a flat dir repository
// This maps to ./libs/coolmod-${mc_version}-${coolmod_version}.jar
// The group id is ignored when searching -- in this case, it is "blank"
// implementation "blank:coolmod-${mc_version}:${coolmod_version}"

jarJar(group: 'dev.xkmc', name: 'l2tabs', version: '[3.0.5+7,)')
implementation "dev.xkmc:l2tabs:3.0.5+7"
jarJar(group: 'dev.xkmc', name: 'l2menustacker', version: '[3.0.9,)')
implementation "dev.xkmc:l2menustacker:3.0.9"
jarJar(group: 'dev.xkmc', name: 'l2serial', version: '[3.0.9+5,)')
implementation "dev.xkmc:l2serial:3.0.9+5"
jarJar(group: 'dev.xkmc', name: 'l2library', version: '[3.0.2+7,)')
implementation "dev.xkmc:l2library:3.0.2+7"
jarJar(group: 'dev.xkmc', name: 'l2core', version: '[3.0.7+45,)')
implementation "dev.xkmc:l2core:3.0.7+45"
implementation files("libs/EclipticSeasons-1.21-neoforge-0.4.1-beta.jar")

//implementation "com.tterrag.registrate:Registrate:MC1.21-1.3.0+50"

//jarJar(group: 'com.tterrag.registrate', name: 'Registrate', version: "[MC1.21,MC1.22)")

// Example mod dependency using a file as dependency
// implementation files("libs/coolmod-${mc_version}-${coolmod_version}.jar")

// Example project dependency using a sister or child project:
// implementation project(":myproject")

// For more info:
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
implementation "com.tterrag.registrate:Registrate:MC1.21-1.3.0+55"
}

// This block of code expands all declared replace properties in the specified resource targets.
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ parchment_mappings_version=2024.07.07
# Environment Properties
# You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge
# The Minecraft version must agree with the Neo version to get a valid artifact
minecraft_version=1.21
minecraft_version=1.21.1
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.21,1.21.2)
minecraft_version_range=[1.21.1,1.21.2)
# The Neo version must agree with the Minecraft version to get a valid artifact
neo_version=21.0.114-beta
neo_version=21.1.24
# The Neo version range can use any version of Neo as bounds
neo_version_range=[21.0.0-beta,)
neo_version_range=[21.1.0-beta,)
# The loader version range can only use the major version of FML as bounds
loader_version_range=[4,)

Expand Down
Binary file added libs/l2core-3.0.7+45.jar
Binary file not shown.
Binary file added libs/l2library-3.0.2+7.jar
Binary file not shown.
Binary file added libs/l2menustacker-3.0.9.jar
Binary file not shown.
Binary file added libs/l2serial-3.0.9+5.jar
Binary file not shown.
Binary file added libs/l2tabs-3.0.5+7.jar
Binary file not shown.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.hiedacamellia.whispergrove.content.client.tab;

import com.mojang.datafixers.util.Pair;
import dev.xkmc.l2library.util.TextWrapper;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import org.hiedacamellia.whispergrove.WhisperGrove;
import org.hiedacamellia.whispergrove.api.viscera.VisceraHolder;
import org.hiedacamellia.whispergrove.content.viscera.*;

import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;

public record ViscerEntry(
List<Component> hover,
Component content,
ResourceLocation icon
){

public static List<ViscerEntry> aggregate(@Nullable Player le) {
if (le == null) return List.of();
List<ViscerEntry> raw = new ArrayList<>();

raw.add(new ViscerEntry(HeartEvent.getHover(le), HeartEvent.getdesc(le),
WhisperGrove.prefix("textures/viscera/heart.png")));
raw.add(new ViscerEntry(KidneyEvent.getHover(le), KidneyEvent.getdesc(le),
WhisperGrove.prefix("textures/viscera/kidney.png")));
raw.add(new ViscerEntry(LiverEvent.getHover(le), LiverEvent.getdesc(le),
WhisperGrove.prefix("textures/viscera/liver.png")));
raw.add(new ViscerEntry(LungEvent.getHover(le), LungEvent.getdesc(le),
WhisperGrove.prefix("textures/viscera/lung.png")));
raw.add(new ViscerEntry(SpleenEvent.getHover(le), SpleenEvent.getdesc(le),
WhisperGrove.prefix("textures/viscera/spleen.png")));

return raw;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.hiedacamellia.whispergrove.content.client.tab;

import dev.xkmc.l2core.util.Proxy;
import dev.xkmc.l2tabs.tabs.contents.BaseTextScreen;
import dev.xkmc.l2tabs.tabs.core.TabManager;
import dev.xkmc.l2tabs.tabs.inventory.InvTabData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Player;
import org.hiedacamellia.whispergrove.core.debug.Debug;
import org.hiedacamellia.whispergrove.registers.WGTab;

import java.util.List;
import java.util.Optional;

public class VisceraScreen extends BaseTextScreen {

private final int page;

protected VisceraScreen(Component title) {
this(title, 0);
}

protected VisceraScreen(Component title, int page) {
super(title, ResourceLocation.fromNamespaceAndPath("l2tabs", "textures/gui/empty.png"));
this.page = page;
}

@Override
public void init() {
super.init();
new TabManager<>(this, new InvTabData()).init(this::addRenderableWidget, WGTab.TAB_VISCERA.get());
}


@Override
public void render(GuiGraphics g, int mx, int my, float ptick) {
super.render(g, mx, my, ptick);
Player player = Proxy.getClientPlayer();
int x = leftPos + 8;
int y = topPos + 6;
var all = ViscerEntry.aggregate(player);
//Debug.getLogger().debug("all: " + all);
List<Component> hover = null;
Font font = Minecraft.getInstance().font;
for (var pair : all) {
//Debug.getLogger().debug("pair: " + pair);
int index = all.indexOf(pair);
g.blit(pair.icon(), x , y+ index*32, 0, 0, 16, 16, 16, 16);
g.drawString(font, pair.content().getString(), x, y + index*32 +16, 0,false);

//Debug.getLogger().debug("pair: " + pair);
int row = y + index * 32 +16;
int column = x;
int rowAft = y + index * 32 + 26;
int columnAft = x + font.width(pair.content());
if (my >= row && my < rowAft && mx >= column && mx < columnAft) {
hover = pair.hover();
}

}
if (hover != null) {
g.renderTooltip(font, hover, Optional.empty(), mx, my);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.hiedacamellia.whispergrove.content.client.tab;

import dev.xkmc.l2tabs.init.L2Tabs;
import dev.xkmc.l2tabs.tabs.core.TabBase;
import dev.xkmc.l2tabs.tabs.core.TabManager;
import dev.xkmc.l2tabs.tabs.core.TabToken;
import dev.xkmc.l2tabs.tabs.inventory.InvTabData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
import org.hiedacamellia.whispergrove.registers.WGItem;

public class VisceraTab extends TabBase<InvTabData, VisceraTab> {
public VisceraTab(int index, TabToken<InvTabData, VisceraTab> token, TabManager<InvTabData> manager, Component title) {
super(index, token, manager, title);
}

@Override
public void onTabClicked() {
Minecraft.getInstance().setScreen(new VisceraScreen(this.getMessage()));
}

@Override
protected void renderIcon(GuiGraphics g) {
ItemStack stack = WGItem.BAMBOO_LEAF.toStack();
if (!stack.isEmpty()) {
this.token.getType().drawIcon(g, this.getX(), this.getY(), stack);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ItemStack getItem(int slot) {

@Override
public int size() {
return 10;
return 9;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import org.hiedacamellia.whispergrove.WhisperGrove;
import org.hiedacamellia.whispergrove.content.client.screen.SpringingScreen;
import org.hiedacamellia.whispergrove.content.client.screen.VisceraScreen;
import org.hiedacamellia.whispergrove.content.client.tab.VisceraScreen;

@EventBusSubscriber(modid = WhisperGrove.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class WGScreen {

@SubscribeEvent
public static void clientLoad(RegisterMenuScreensEvent event) {
event.register(WGMenu.VISCERA.get(), VisceraScreen::new);
event.register(WGMenu.SPRINGING.get(), SpringingScreen::new);
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/hiedacamellia/whispergrove/registers/WGTab.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package org.hiedacamellia.whispergrove.registers;

import dev.xkmc.l2core.init.reg.simple.Val;
import dev.xkmc.l2tabs.init.L2Tabs;
import dev.xkmc.l2tabs.tabs.core.TabToken;
import dev.xkmc.l2tabs.tabs.inventory.InvTabData;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.neoforged.neoforge.registries.DeferredHolder;
import net.neoforged.neoforge.registries.DeferredRegister;
import org.hiedacamellia.whispergrove.WhisperGrove;
import org.hiedacamellia.whispergrove.content.client.tab.VisceraTab;

import static dev.xkmc.l2tabs.init.L2Tabs.TAB_REG;

public class WGTab {

Expand All @@ -19,4 +26,7 @@ public class WGTab {
WGItem.ITEMS.getEntries().forEach(holder -> output.accept(holder.get()));
}).build());

public static Val<TabToken<InvTabData, VisceraTab>> TAB_VISCERA = TAB_REG.reg("viscera_tab",
() -> L2Tabs.GROUP.registerTab(() -> VisceraTab::new,
Component.translatable("menu.whispergrove.viscera_tab")));
}

0 comments on commit c8d6e82

Please sign in to comment.