Skip to content

Commit 8ba5c60

Browse files
committed
1.18.1 update
update to 1.18.1 (+potential accidental disable of hotbar saving? dunno, and too scared to test)
1 parent f98296e commit 8ba5c60

File tree

14 files changed

+369
-63
lines changed

14 files changed

+369
-63
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# More Toolbars
22

3-
Fabric Mod which adds 18 more toolbars! This mod needs Fabric API to work properly. Current version is for Minecraft 1.15.2.
3+
Fabric Mod which adds 18 more toolbars! This mod needs Fabric API to work properly. Current version is for Minecraft 1.18.1.
44

55
# Compile
66

build.gradle

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,72 @@
11
plugins {
2-
id 'fabric-loom' version '0.4-SNAPSHOT'
2+
id 'fabric-loom' version '0.11-SNAPSHOT'
33
id 'maven-publish'
44
}
55

6-
sourceCompatibility = JavaVersion.VERSION_1_8
7-
targetCompatibility = JavaVersion.VERSION_1_8
6+
sourceCompatibility = JavaVersion.VERSION_17
7+
targetCompatibility = JavaVersion.VERSION_17
88

99
archivesBaseName = project.archives_base_name
1010
version = project.mod_version
1111
group = project.maven_group
1212

13+
repositories {
14+
// Add repositories to retrieve artifacts from in here.
15+
// You should only use this when depending on other mods because
16+
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
17+
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
18+
// for more information about repositories.
19+
}
20+
1321
dependencies {
14-
//to change the versions see the gradle.properties file
22+
// To change the versions see the gradle.properties file
1523
minecraft "com.mojang:minecraft:${project.minecraft_version}"
1624
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
1725
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
1826

1927
// Fabric API. This is technically optional, but you probably want it anyway.
2028
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
21-
22-
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
23-
// You may need to force-disable transitiveness on them.
2429
}
2530

2631
processResources {
2732
inputs.property "version", project.version
2833

29-
from(sourceSets.main.resources.srcDirs) {
30-
include "fabric.mod.json"
34+
filesMatching("fabric.mod.json") {
3135
expand "version": project.version
3236
}
33-
34-
from(sourceSets.main.resources.srcDirs) {
35-
exclude "fabric.mod.json"
36-
}
3737
}
3838

39-
// ensure that the encoding is set to UTF-8, no matter what the system default is
40-
// this fixes some edge cases with special characters not displaying correctly
41-
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
42-
tasks.withType(JavaCompile) {
43-
options.encoding = "UTF-8"
39+
tasks.withType(JavaCompile).configureEach {
40+
// Minecraft 1.18 (1.18-pre2) upwards uses Java 17.
41+
it.options.release = 17
4442
}
4543

46-
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
47-
// if it is present.
48-
// If you remove this task, sources will not be generated.
49-
task sourcesJar(type: Jar, dependsOn: classes) {
50-
classifier = "sources"
51-
from sourceSets.main.allSource
44+
java {
45+
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
46+
// if it is present.
47+
// If you remove this line, sources will not be generated.
48+
withSourcesJar()
5249
}
5350

5451
jar {
55-
from "LICENSE"
52+
from("LICENSE") {
53+
rename { "${it}_${project.archivesBaseName}"}
54+
}
5655
}
5756

5857
// configure the maven publication
5958
publishing {
6059
publications {
6160
mavenJava(MavenPublication) {
62-
// add all the jars that should be included when publishing to maven
63-
artifact(remapJar) {
64-
builtBy remapJar
65-
}
66-
artifact(sourcesJar) {
67-
builtBy remapSourcesJar
68-
}
61+
from components.java
6962
}
7063
}
7164

72-
// select the repositories you want to publish to
65+
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
7366
repositories {
74-
// uncomment to publish to the local maven
75-
// mavenLocal()
67+
// Add repositories to publish to here.
68+
// Notice: This block does NOT have the same function as the block in the top level.
69+
// The repositories here will be used for publishing your artifact, not for
70+
// retrieving dependencies.
7671
}
77-
}
72+
}

gradle.properties

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
5-
# check these on https://fabricmc.net/use
6-
minecraft_version=1.16.3
7-
yarn_mappings=1.16.3+build.11
8-
loader_version=0.9.3+build.207
5+
# check these on https://fabricmc.net/develop
6+
minecraft_version=1.18.1
7+
yarn_mappings=1.18.1+build.22
8+
loader_version=0.12.12
99

1010
# Mod Properties
1111
mod_version = 1.0.4
1212
maven_group = io.github.samipourquoi
1313
archives_base_name = more-toolbars
1414

1515
# Dependencies
16-
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
17-
fabric_version=0.21.0+build.407-1.16
16+
fabric_version=0.46.2+1.18
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Sun Sep 13 03:05:51 CEST 2020
2-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
31
distributionBase=GRADLE_USER_HOME
42
distributionPath=wrapper/dists
5-
zipStorePath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
64
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.github.samipourquoi.moretoolbars;
2+
3+
import net.fabricmc.api.EnvType;
4+
import net.fabricmc.api.Environment;
5+
import net.fabricmc.api.ModInitializer;
6+
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
7+
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
8+
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
9+
import net.minecraft.client.options.KeyBinding;
10+
import net.minecraft.client.util.InputUtil;
11+
import net.minecraft.util.Identifier;
12+
import org.lwjgl.glfw.GLFW;
13+
14+
/**
15+
* Adds the keybinds for the modifiers of each group.
16+
*
17+
* @author samipourquoi
18+
*/
19+
@Environment(EnvType.CLIENT)
20+
public class Keybinds implements ModInitializer {
21+
22+
public static KeyBinding group1;
23+
public static KeyBinding group2;
24+
public static KeyBinding group3;
25+
26+
@Override
27+
public void onInitialize() {
28+
29+
group1 = KeyBindingHelper.registerKeyBinding(new KeyBinding(
30+
"key.moretoolbars.group1",
31+
InputUtil.Type.KEYSYM,
32+
InputUtil.UNKNOWN_KEY.getCode(),
33+
"key.categories.creative"
34+
));
35+
36+
group2 = KeyBindingHelper.registerKeyBinding(new KeyBinding(
37+
"key.moretoolbars.group2",
38+
InputUtil.Type.KEYSYM,
39+
GLFW.GLFW_KEY_LEFT_ALT,
40+
"key.categories.creative"
41+
));
42+
43+
group3 = KeyBindingHelper.registerKeyBinding(new KeyBinding(
44+
"key.moretoolbars.group3",
45+
InputUtil.Type.KEYSYM,
46+
GLFW.GLFW_KEY_LEFT_SUPER,
47+
"key.categories.creative"
48+
));
49+
}
50+
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package io.github.samipourquoi.moretoolbars.mixin;
2+
3+
import io.github.samipourquoi.moretoolbars.Keybinds;
4+
import net.fabricmc.api.EnvType;
5+
import net.fabricmc.api.Environment;
6+
import net.minecraft.client.MinecraftClient;
7+
import net.minecraft.client.gui.screen.ingame.AbstractInventoryScreen;
8+
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
9+
import net.minecraft.client.network.ClientPlayerEntity;
10+
import net.minecraft.client.option.HotbarStorage;
11+
import net.minecraft.client.option.HotbarStorageEntry;
12+
import net.minecraft.client.option.KeyBinding;
13+
import net.minecraft.entity.player.PlayerInventory;
14+
import net.minecraft.item.Item;
15+
import net.minecraft.item.ItemGroup;
16+
import net.minecraft.item.ItemStack;
17+
import net.minecraft.item.Items;
18+
import net.minecraft.text.OrderedText;
19+
import net.minecraft.text.Text;
20+
import net.minecraft.text.TranslatableText;
21+
import org.spongepowered.asm.mixin.Mixin;
22+
import org.spongepowered.asm.mixin.Overwrite;
23+
import org.spongepowered.asm.mixin.injection.*;
24+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
25+
26+
@Environment(EnvType.CLIENT)
27+
@Mixin(CreativeInventoryScreen.class)
28+
public abstract class MixinCreativeInventoryScreen extends AbstractInventoryScreen<CreativeInventoryScreen.CreativeScreenHandler> {
29+
30+
public MixinCreativeInventoryScreen(CreativeInventoryScreen.CreativeScreenHandler container, PlayerInventory playerInventory, Text text) {
31+
super(container, playerInventory, text);
32+
}
33+
34+
/**
35+
* @author samipourquoi
36+
*/
37+
@Overwrite
38+
public static void onHotbarKeyPress(MinecraftClient client, int index, boolean restore, boolean save) {
39+
ClientPlayerEntity clientPlayerEntity = client.player;
40+
HotbarStorage hotbarStorage = client.getCreativeHotbarStorage();
41+
HotbarStorageEntry hotbarStorageEntry = hotbarStorage.getSavedHotbar(index);
42+
int j;
43+
if (clientPlayerEntity == null) return;
44+
if (restore) {
45+
for(j = 0; j < PlayerInventory.getHotbarSize(); j++) {
46+
ItemStack itemStack = ((ItemStack)hotbarStorageEntry.get(j)).copy();
47+
clientPlayerEntity.inventory.setStack(j, itemStack);
48+
client.interactionManager.clickCreativeStack(itemStack, 36 + j);
49+
}
50+
51+
clientPlayerEntity.playerScreenHandler.sendContentUpdates();
52+
} else if (save) {
53+
for(j = 0; j < PlayerInventory.getHotbarSize(); j++) {
54+
hotbarStorageEntry.set(j, clientPlayerEntity.inventory.getStack(j).copy());
55+
}
56+
57+
String hotbarKey = getTranslationName(client.options.keysHotbar[index % 9]);
58+
String restoreKey = getTranslationName(client.options.keyLoadToolbarActivator);
59+
String[] modifiers = {
60+
(Keybinds.group1.isUnbound()) ? "" : getTranslationName(Keybinds.group1) + "+",
61+
(Keybinds.group2.isUnbound()) ? "" : getTranslationName(Keybinds.group2) + "+",
62+
(Keybinds.group3.isUnbound()) ? "" : getTranslationName(Keybinds.group3) + "+",
63+
};
64+
65+
TranslatableText originalText = new TranslatableText("inventory.hotbarSaved", modifiers[index/9] + restoreKey, hotbarKey);
66+
67+
client.inGameHud.setOverlayMessage((Text) originalText, false);
68+
hotbarStorage.save();
69+
}
70+
}
71+
72+
private static String getTranslationName(KeyBinding key) {
73+
String a = new TranslatableText(key.getBoundKeyTranslationKey()).asString();
74+
String b = key.getBoundKeyLocalizedText().getString();
75+
return (b.equals("")) ? a : b;
76+
}
77+
78+
/**
79+
* Cancels the render of the saved toolbars.
80+
*/
81+
@ModifyConstant(
82+
method = "setSelectedTab",
83+
slice = @Slice(
84+
from = @At(
85+
value = "HEAD"
86+
),
87+
to = @At(
88+
value = "INVOKE",
89+
target = "Lnet/minecraft/client/options/HotbarStorage;getSavedHotbar(I)Lnet/minecraft/client/options/HotbarStorageEntry;"
90+
)
91+
),
92+
constant = @Constant(intValue = 9)
93+
)
94+
private int noOldRenderSavedToolbars(int number) {
95+
return 0;
96+
}
97+
98+
/**
99+
* "Overwrites" the render of the saved toolbars.
100+
*/
101+
@Inject(
102+
method = "setSelectedTab",
103+
at = @At(
104+
value = "INVOKE",
105+
target = "Lnet/minecraft/client/MinecraftClient;getCreativeHotbarStorage()Lnet/minecraft/client/options/HotbarStorage;"
106+
)
107+
)
108+
private void renderSavedToolbars(ItemGroup group, CallbackInfo info) {
109+
MinecraftClient client = MinecraftClient.getInstance();
110+
HotbarStorage hotbarStorage = client.getCreativeHotbarStorage();
111+
Item[] displayItems = {Items.PAPER, Items.MAP, Items.FILLED_MAP};
112+
int displayItemIndex = 0;
113+
String[] modifiers = {
114+
(Keybinds.group1.isUnbound()) ? "" : getTranslationName(Keybinds.group1) + "+",
115+
(Keybinds.group2.isUnbound()) ? "" : getTranslationName(Keybinds.group2) + "+",
116+
(Keybinds.group3.isUnbound()) ? "" : getTranslationName(Keybinds.group3) + "+",
117+
};
118+
119+
for(int i = 0; i < 27; i++) {
120+
HotbarStorageEntry hotbarStorageEntry = hotbarStorage.getSavedHotbar(i);
121+
String hotbarKey;
122+
String saveKey;
123+
124+
if ((i % 9 == 0) && i != 0) displayItemIndex++;
125+
if (hotbarStorageEntry.isEmpty()) {
126+
127+
for(int j = 0; j < 9; j++) {
128+
if (i % 9 == j) {
129+
ItemStack itemStack = new ItemStack(displayItems[displayItemIndex]);
130+
itemStack.getOrCreateSubTag("CustomCreativeLock");
131+
132+
hotbarKey = getTranslationName(client.options.keysHotbar[j]);
133+
saveKey = getTranslationName(client.options.keySaveToolbarActivator);
134+
itemStack.setCustomName(new TranslatableText(
135+
"inventory.hotbarInfo",
136+
modifiers[displayItemIndex]+saveKey,
137+
hotbarKey
138+
));
139+
this.getScreenHandler().itemList.add(itemStack);
140+
} else {
141+
this.getScreenHandler().itemList.add(ItemStack.EMPTY);
142+
}
143+
}
144+
} else {
145+
this.getScreenHandler().itemList.addAll(hotbarStorageEntry);
146+
}
147+
}
148+
}
149+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.github.samipourquoi.moretoolbars.mixin;
2+
3+
import net.fabricmc.api.EnvType;
4+
import net.fabricmc.api.Environment;
5+
import net.minecraft.client.options.HotbarStorage;
6+
import net.minecraft.client.options.HotbarStorageEntry;
7+
import org.spongepowered.asm.mixin.Final;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.Constant;
10+
import org.spongepowered.asm.mixin.injection.ModifyConstant;
11+
12+
/**
13+
* Changes some variables to make them compatible with 27 toolbars.
14+
*
15+
* @author samipourquoi
16+
*/
17+
@Environment(EnvType.CLIENT)
18+
@Mixin(HotbarStorage.class)
19+
public class MixinHotbarStorage {
20+
@Final public HotbarStorageEntry[] entries = new HotbarStorageEntry[27];
21+
22+
@ModifyConstant(method = "<init>", constant = @Constant(intValue = 9))
23+
private int constructor(int number) {
24+
return 27;
25+
}
26+
27+
@ModifyConstant(method = "load", constant = @Constant(intValue = 9))
28+
private int load(int number) {
29+
return 27;
30+
}
31+
32+
@ModifyConstant(method = "save", constant = @Constant(intValue = 9))
33+
private int save(int number) {
34+
return 27;
35+
}
36+
}

0 commit comments

Comments
 (0)