Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] GCAPI Integration #127

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c36d9a4
First version of tool items update
mineLdiver May 2, 2024
433fa82
Mining levels graph
mineLdiver May 7, 2024
a6dfbdc
Fix a bad mixin declaration in lifecycle events
calmilamsy Jul 8, 2024
6a63f39
Add RegistriesFrozenEvent
calmilamsy Jul 9, 2024
8f1edb9
Add station-api-config module
calmilamsy Jul 10, 2024
509d529
Loading screen config entry (not implemented, still reverse engineeri…
calmilamsy Jul 10, 2024
7bbf1e4
Update to GCAPI 3-beta.1
calmilamsy Jul 10, 2024
d2eb933
Why
calmilamsy Jul 10, 2024
ae72efb
Changes
calmilamsy Jul 11, 2024
ce4c7a7
Fuck you reloadscreen
calmilamsy Jul 11, 2024
b7c658f
Merge branch 'refs/heads/master' into 2.0-alpha.3
mineLdiver Jul 13, 2024
2114188
GRADLE LET THE PROJECT GET REPLACED BY A TRANSITIVE DEPENDENCY?!
calmilamsy Jul 11, 2024
1c126d0
Revert "Fuck you reloadscreen"
calmilamsy Jul 11, 2024
50434b4
Why does the bar go backwards
calmilamsy Jul 11, 2024
546a38d
Wip code or something
calmilamsy Jul 16, 2024
6cb3460
Latest boom
calmilamsy Jul 18, 2024
fab448c
Merge branch 'master' into 2.0-alpha.3
calmilamsy Aug 16, 2024
1db84ab
Yeet deprecated code
calmilamsy Aug 16, 2024
450432c
Merge branch 'master' into 2.0-alpha.3
calmilamsy Aug 16, 2024
150d672
Merge branch 'master' into 2.0-alpha.3
mineLdiver Sep 4, 2024
25fc29f
Merge branch 'master' into 2.0-alpha.3
mineLdiver Sep 6, 2024
bf4e97e
*actually* remove deprecated stuff
mineLdiver Sep 6, 2024
c20f126
Update to use an actually good inveditor
calmilamsy Sep 11, 2024
a8abb7b
Well, the bar no longer goes backwards, but the stapi logo is now inv…
calmilamsy Sep 11, 2024
6b2d36e
Fix launching
calmilamsy Sep 12, 2024
07ff383
Merge branch '2.0-alpha.3' into gcapi
calmilamsy Sep 12, 2024
24bb2fc
Update CustomTooltipRendererImpl.java
calmilamsy Sep 12, 2024
631122c
Goddammit I did it again
calmilamsy Sep 12, 2024
35db488
AMI will have to wait until a3 hits main
calmilamsy Sep 12, 2024
8754750
Fix
calmilamsy Sep 12, 2024
163ff3d
Stapi logo rendering is broken, but somehow forge one works, what the…
calmilamsy Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ bin/
# fabric

run/
!/run
15 changes: 9 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,20 @@ allprojects {
// adds some useful annotations for miscellaneous uses. does not add any dependencies, though people without the lib will be missing some useful context hints.
implementation("org.jetbrains:annotations:23.0.0")

modLocalRuntime("com.github.calmilamsy:ModMenu:${project.properties["modmenu_version"]}") {
modLocalRuntime("net.glasslauncher.mods:ModMenu:${project.properties["modmenu_version"]}") {
isTransitive = false
}

implementation("blue.endless:jankson:1.2.1")
modLocalRuntime("net.glasslauncher.mods:GlassConfigAPI:${project.properties["gcapi_version"]}") {
isTransitive = false
}
modLocalRuntime("net.glasslauncher:HowManyItems-Fabric-Unofficial:${project.properties["hmi_version"]}") {

implementation("me.carleslc:Simple-Yaml:1.8.4")
modImplementation("net.glasslauncher.mods:glass-networking:1.0.2")
modImplementation("net.glasslauncher.mods:GlassConfigAPI:${project.properties["gcapi_version"]}") {
isTransitive = false
}
// Requires gcapi
// modLocalRuntime("net.glasslauncher.mods:AlwaysMoreItems:${project.properties["ami_version"]}") {
// isTransitive = false
// }
// Optional bugfix mod for testing qol. Remove the // to enable.
//modLocalRuntime "maven.modrinth:mojangfix:${project.properties["mojangfix_version"]}"
}
Expand Down
7 changes: 3 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ fabric.loom.multiProjectOptimisation=true
archives_base_name = StationAPI

# Test properties
gcapi_version = 1.3.1
hmi_version = 5.1.1
modmenu_version = v1.8.5-beta.3
mojangfix_version = 0.5.2
gcapi_version = 3.0.0
ami_version = 1.0.2
modmenu_version = 1.8.5-beta.9
10 changes: 10 additions & 0 deletions run/config/fabric_loader_dependencies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 1,
"overrides": {
"alwaysmoreitems": {
"-depends": {
"stationapi": "IGNORED"
}
}
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ include(":station-gui-api-v0")
include(":station-transitive-access-wideners-v0")
include(":station-maths-v0")
include(":station-worldgen-api-v0")
include(":station-api-configuration")
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public enum Blocks {

TEST_BLOCK("test_block", "testBlock", id -> new TemplateBlock(id, Material.CLAY).setHardness(1)),
TEST_BLOCK("test_block", "testBlock", id -> new TemplateBlock(id, Material.STONE).setHardness(1)),
TEST_ANIMATED_BLOCK("test_animated_block", "testAnimatedBlock", id -> new ModdedMetaBlock(id, Material.NETHER_PORTAL)),
CUSTOM_MODEL_BLOCK("farlands_block", "farlands_block", id -> new ModdedModelBlock(id, Material.SOIL).setHardness(1)),
FREEZER("freezer", "freezer", id -> new BlockFreezer(id).setHardness(2.5F).setSoundGroup(TemplateBlock.DEFAULT_SOUND_GROUP)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
import net.modificationstation.sltest.block.Blocks;
import net.modificationstation.sltest.block.VariationBlock;
import net.modificationstation.stationapi.api.event.registry.ItemRegistryEvent;
import net.modificationstation.stationapi.api.item.tool.MiningLevelManager;
import net.modificationstation.stationapi.api.item.tool.ToolMaterialFactory;
import net.modificationstation.stationapi.api.registry.BlockRegistry;
import net.modificationstation.stationapi.api.registry.ItemRegistry;
import net.modificationstation.stationapi.api.registry.Registry;
import net.modificationstation.stationapi.api.tag.TagKey;
import net.modificationstation.stationapi.api.template.item.BlockStateItem;

import static net.modificationstation.sltest.SLTest.NAMESPACE;
Expand All @@ -17,8 +20,13 @@ public class ItemListener {

@EventListener
public void registerItems(ItemRegistryEvent event) {
MiningLevelManager.LevelNode moddedNode = new MiningLevelManager.LevelNode(TagKey.of(BlockRegistry.KEY, NAMESPACE.id("needs_tool_level_modded")));
MiningLevelManager.GRAPH.putEdge(ToolMaterial.STONE.getMiningLevelNode(), moddedNode);
MiningLevelManager.GRAPH.putEdge(moddedNode, ToolMaterial.IRON.getMiningLevelNode());
MiningLevelManager.invalidateCache();

testItem = new ModdedItem(NAMESPACE.id("test_item")).setTranslationKey(NAMESPACE, "testItem"); //8475
testMaterial = ToolMaterialFactory.create("testMaterial", 3, Integer.MAX_VALUE, Float.MAX_VALUE, Integer.MAX_VALUE - 2);
testMaterial = ToolMaterialFactory.create("testMaterial", 3, Integer.MAX_VALUE, Float.MAX_VALUE, Integer.MAX_VALUE - 2).miningLevelNode(moddedNode);
testPickaxe = new ModdedPickaxeItem(NAMESPACE.id("test_pickaxe"), testMaterial).setTranslationKey(NAMESPACE, "testPickaxe"); //8476
testNBTItem = new NBTItem(NAMESPACE.id("nbt_item")).setTranslationKey(NAMESPACE, "nbt_item"); //8477
testModelItem = new ModelItem(NAMESPACE.id("model_item")).setMaxCount(1).setTranslationKey(NAMESPACE, "idkSomething");
Expand All @@ -30,6 +38,8 @@ public void registerItems(ItemRegistryEvent event) {
testShears = new TestShearsItem(NAMESPACE.id("test_shears")).setTranslationKey(NAMESPACE, "test_shears");
pacifistSword = new PacifistSwordItem(NAMESPACE.id("pacifist_sword")).setTranslationKey(NAMESPACE, "pacifist_sword");
dullPickaxe = new DullPickaxeItem(NAMESPACE.id("dull_pickaxe")).setTranslationKey(NAMESPACE, "dull_pickaxe");


}

public static Item testItem;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"sltest:test_block"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"sltest:test_block"
]
}
4 changes: 4 additions & 0 deletions station-api-configuration/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import net.modificationstation.stationapi.gradle.SubprojectHelpers.getSubprojectVersion

base.archivesName.set("station-api-config")
version = getSubprojectVersion(project, "1.0.0")
3 changes: 3 additions & 0 deletions station-api-configuration/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is a specialized module that appears in ModMenu for easy config editing.
# !!DO NOT USE THIS MODULE FOR ANYTHING OTHER THAN CONFIG!!
Also don't refer to values from this for your mods, changes here will not be as thoroughly documented as the rest of the API.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package net.modificationstation.stationapi.config;

import com.google.common.collect.ImmutableMap;
import net.glasslauncher.mods.gcapi3.api.ConfigEntry;
import net.glasslauncher.mods.gcapi3.api.ConfigFactoryProvider;
import net.glasslauncher.mods.gcapi3.impl.SeptFunction;
import net.glasslauncher.mods.gcapi3.impl.factory.DefaultFactoryProvider;
import net.glasslauncher.mods.gcapi3.impl.object.ConfigEntryHandler;
import net.glasslauncher.mods.gcapi3.impl.object.entry.EnumConfigEntryHandler;

import java.lang.reflect.*;
import java.util.function.*;

public class FactoryProvider implements ConfigFactoryProvider {
@Override
public void provideLoadFactories(ImmutableMap.Builder<Type, SeptFunction<String, ConfigEntry, Field, Object, Boolean, Object, Object, ConfigEntryHandler<?>>> immutableBuilder) {
immutableBuilder.put(LoadingScreenOption.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, enumOrOrdinal, defaultEnum) ->
new EnumConfigEntryHandler<LoadingScreenOption>(id, configEntry, parentField, parentObject, isMultiplayerSynced, DefaultFactoryProvider.enumOrOrdinalToOrdinal(enumOrOrdinal), ((LoadingScreenOption) defaultEnum).ordinal(), LoadingScreenOption.class)));
}

@Override
public void provideSaveFactories(ImmutableMap.Builder<Type, Function<Object, Object>> immutableBuilder) {
immutableBuilder.put(LoadingScreenOption.class, enumEntry -> enumEntry);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package net.modificationstation.stationapi.config;

public enum LoadingScreenOption {
SHOW("gui.config.stationapi.loadingscreen.show"),
NO_ANIMATE("gui.config.stationapi.loadingscreen.no_animate"),
NO_RECOLOR("gui.config.stationapi.loadingscreen.no_recolor"),
FORGE("gui.config.stationapi.loadingscreen.forge"),
HIDE("gui.config.stationapi.loadingscreen.hide");

public final String translationKey;

LoadingScreenOption(String translationKey) {
this.translationKey = translationKey;
}

@Override
public String toString() {
return translationKey;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.modificationstation.stationapi.config;

import net.glasslauncher.mods.gcapi3.api.ConfigRoot;

public class StationConfig {

@ConfigRoot(
value = "config",
visibleName = "gui.config.stationapi.main"
)
public static StationConfigData stationConfigData = new StationConfigData();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package net.modificationstation.stationapi.config;

import net.glasslauncher.mods.gcapi3.api.ConfigEntry;

public class StationConfigData {

@ConfigEntry(
name = "gui.config.stationapi.main.loading_screen_option"
)
public LoadingScreenOption loadingScreenOption = LoadingScreenOption.SHOW;
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Config Entries
gui.config.stationapi.main=StationAPI Configuration
gui.config.stationapi.main.loading_screen_option=Loading Screen Style


gui.config.stationapi.loadingscreen.show=Show
gui.config.stationapi.loadingscreen.no_animate=Don't Animate
gui.config.stationapi.loadingscreen.no_recolor=Don't Recolor
gui.config.stationapi.loadingscreen.forge=Forge-Like
gui.config.stationapi.loadingscreen.hide=Hide (Vanilla)
38 changes: 38 additions & 0 deletions station-api-configuration/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"schemaVersion": 1,
"id": "station-api-configuration",
"version": "${version}",

"name": "Station API Configuration",
"description": "Configuration package for StationAPI.",
"authors": [
"Modification Station"
],
"contact": {
"homepage": "https://glass-launcher.net/repo/mod/stationapi",
"sources": "https://github.com/ModificationStation/StationAPI",
"issues": "https://github.com/ModificationStation/StationAPI/issues"
},

"license": "MIT",
"icon": "assets/station-api-configuration/icon.png",

"environment": "*",
"entrypoints": {
"gcapi3": [
"net.modificationstation.stationapi.config.StationConfig"
],
"gcapi3:factory_provider": [
"net.modificationstation.stationapi.config.FactoryProvider"
]
},

"depends": {
"fabricloader": "*",
"minecraft": "1.0.0-beta.7.3"
},

"custom": {
"modmenu:showIfContained": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ public class TooltipRenderEvent extends ItemStackEvent {
public final HandledScreen container;
public final TextRenderer textManager;
public final PlayerInventory inventory;
/**
* These will be removed in a3, due to the fact the container var already exists.
*/
@Deprecated(forRemoval = true)
public final int
containerX,
containerY;
public final int
mouseX,
mouseY;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
package net.modificationstation.stationapi.impl.client.gui.screen.container;

import net.mine_diver.unsafeevents.listener.EventListener;
import net.minecraft.client.gui.DrawContext;
import net.modificationstation.stationapi.api.StationAPI;
import net.modificationstation.stationapi.api.client.TooltipHelper;
import net.modificationstation.stationapi.api.client.event.gui.screen.container.TooltipRenderEvent;
import net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint;
import net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy;
import net.modificationstation.stationapi.mixin.item.client.DrawContextAccessor;
import net.modificationstation.stationapi.mixin.item.client.HandledScreenAccessor;

import java.util.*;
import java.util.ArrayList;
import java.util.stream.IntStream;

@Entrypoint(eventBus = @EventBusPolicy(registerInstance = false))
@EventListener(phase = StationAPI.INTERNAL_PHASE)
public final class CustomTooltipRendererImpl {
private static final DrawContext CONTEXT = new DrawContext();

@EventListener
private static void renderCustomTooltips(TooltipRenderEvent event) {
if(event.isCanceled()) {
Expand All @@ -24,9 +28,9 @@ private static void renderCustomTooltips(TooltipRenderEvent event) {

if (!newTooltip.isEmpty()) {
newTooltip.stream().mapToInt(event.textManager::getWidth).max().ifPresent(tooltipWidth -> {
int tooltipX = event.mouseX - event.containerX + 12;
int tooltipY = event.mouseY - event.containerY - 12;
((DrawContextAccessor) event.container).invokeFillGradient(tooltipX - 3, tooltipY - 3, tooltipX + tooltipWidth + 3, tooltipY + (8 * newTooltip.size()) + (3 * newTooltip.size()), -1073741824, -1073741824);
int tooltipX = event.mouseX - (event.container == null ? 0 : ((event.container.width - ((HandledScreenAccessor) event.container).stationapi_getBackgroundWidth()) / 2)) + 12;
int tooltipY = event.mouseY - (event.container == null ? 0 : ((event.container.height - ((HandledScreenAccessor) event.container).stationapi_getBackgroundHeight()) / 2)) - 12;
((DrawContextAccessor) CONTEXT).invokeFill(tooltipX - 3, tooltipY - 3, tooltipX + tooltipWidth + 3, tooltipY + (8 * newTooltip.size()) + (3 * newTooltip.size()), -1073741824);
IntStream.range(0, newTooltip.size()).forEach(currentTooltip -> event.textManager.drawWithShadow(newTooltip.get(currentTooltip), tooltipX, tooltipY + (8 * currentTooltip) + (3 * currentTooltip), -1));
});
event.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ private void stationapi_renderTooltip(int mouseX, int mouseY, float delta, Callb
.container((HandledScreen) (Object) this)
.textManager(this.textRenderer)
.inventory(inventory)
.containerX(containerX).containerY(containerY)
.mouseX(mouseX).mouseY(mouseY)
.delta(delta)
.originalTooltip(originalTooltip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
@Mixin(DrawContext.class)
public interface DrawContextAccessor {
@Invoker
void invokeFillGradient(int x1, int y1, int x2, int y2, int startColour, int endColour);
void invokeFill(int x1, int y1, int x2, int y2, int color);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.modificationstation.stationapi.mixin.item.client;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(HandledScreen.class)
public interface HandledScreenAccessor {
@Accessor("backgroundWidth")
int stationapi_getBackgroundWidth();

@Accessor("backgroundHeight")
int stationapi_getBackgroundHeight();
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"client.ContainerScreenMixin",
"client.DrawContextAccessor",
"client.GameRendererMixin",
"client.HandledScreenAccessor",
"client.InteractionManagerMixin",
"client.ItemRendererMixin",
"client.MultiplayerInteractionManagerMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
"minVersion": "0.8",
"package": "net.modificationstation.stationapi.mixin.lifecycle",
"compatibilityLevel": "JAVA_17",
"mixins": [
"server.ServerPlayNetworkHandlerMixin"
],
"server": [
"server.MinecraftServerMixin",
"server.ServerLoginNetworkHandlerMixin"
"server.ServerLoginNetworkHandlerMixin",
"server.ServerPlayNetworkHandlerMixin"
],
"client": [
"client.ClientNetworkHandlerMixin",
Expand Down

This file was deleted.

Loading