WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e74c172

Browse files
committed
backport to 1.20-1.20.4 and update to 1.21.6
1 parent 2dd44f9 commit e74c172

File tree

50 files changed

+2982
-36
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2982
-36
lines changed

build.gradle

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ plugins {
44
}
55

66
version = project.mod_version
7-
group = project.maven_group
7+
group = project.maven_group
88

99
base {
1010
archivesName = project.archives_base_name
1111
}
1212

1313
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.
1914
maven {
2015
name = "Fabric"
2116
url = "https://maven.fabricmc.net/"
@@ -35,81 +30,76 @@ repositories {
3530

3631
loom {
3732
splitEnvironmentSourceSets()
38-
3933
mods {
4034
"immersive-hotbar" {
4135
sourceSet sourceSets.main
4236
sourceSet sourceSets.client
4337
}
4438
}
45-
4639
}
4740

4841
fabricApi {
49-
configureDataGeneration {
50-
client = true
51-
}
42+
configureDataGeneration { client = true }
5243
}
44+
5345
loom {
5446
accessWidenerPath = file("src/main/resources/immersive-hotbar.accesswidener")
5547
}
48+
5649
dependencies {
5750
// To change the versions see the gradle.properties file
5851
minecraft "com.mojang:minecraft:${project.minecraft_version}"
5952
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
6053
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
6154

62-
modImplementation("com.terraformersmc:modmenu:${project.modmenu_version}")
55+
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
6356
modImplementation "dev.isxander:yet-another-config-lib:${project.yacl_version}"
64-
65-
// Fabric API. This is technically optional, but you probably want it anyway.
6657
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
67-
6858
}
59+
6960
processResources {
7061
inputs.property "version", project.version
71-
7262
filesMatching("fabric.mod.json") {
7363
expand "version": inputs.properties.version
7464
}
7565
}
7666

77-
tasks.withType(JavaCompile).configureEach {
78-
it.options.release = 21
79-
}
67+
// ─── Replace stonecutter.version.current with stonecutter.minecraftVersion ───
68+
69+
def isModernMc = stonecutter.eval(project.minecraft_version, ">=1.20.5")
8070

8171
java {
82-
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
83-
// if it is present.
84-
// If you remove this line, sources will not be generated.
85-
withSourcesJar()
72+
// if MC ≥1.20.5 → Java 21; else → Java 17
73+
sourceCompatibility = isModernMc ? JavaVersion.VERSION_21 : JavaVersion.VERSION_17
74+
targetCompatibility = isModernMc ? JavaVersion.VERSION_21 : JavaVersion.VERSION_17
8675

87-
sourceCompatibility = JavaVersion.VERSION_21
88-
targetCompatibility = JavaVersion.VERSION_21
76+
// (Optional) force Gradle to select the correct toolchain
77+
toolchain {
78+
languageVersion = JavaLanguageVersion.of(isModernMc ? 21 : 17)
79+
}
80+
}
81+
82+
tasks.withType(JavaCompile).configureEach {
83+
options.release = isModernMc ? 21 : 17
8984
}
9085

86+
// ───────────────────────────────────────────────────────────────────────────────
87+
9188
jar {
9289
inputs.property "archivesName", project.base.archivesName
93-
9490
from("LICENSE") {
95-
rename { "${it}_${inputs.properties.archivesName}"}
91+
rename { "${it}_${inputs.properties.archivesName}" }
9692
}
9793
}
9894

99-
// configure the maven publication
10095
publishing {
10196
publications {
10297
create("mavenJava", MavenPublication) {
10398
artifactId = project.archives_base_name
10499
from components.java
105100
}
106101
}
107-
108-
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
109102
repositories {
110-
// Add repositories to publish to here.
111-
// Notice: This block does NOT have the same function as the block in the top level.
112-
// The repositories here will be used for publishing your artifact, not for
113-
// retrieving dependencies.
103+
// …your publishing repositories…
114104
}
115-
}
105+
}

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ plugins {
1313
}
1414
stonecutter {
1515
create(rootProject) {
16-
versions "1.21.1", "1.21.2", "1.21.5"
16+
versions "1.20.1", "1.21.1", "1.21.2", "1.21.5", "1.21.6"
1717
vcsVersion = "1.21.1"
1818
}
1919
}

versions/1.20.1/gradle.properties

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Done to increase the memory available to gradle.
2+
org.gradle.jvmargs=-Xmx1G
3+
org.gradle.parallel=true
4+
5+
# Fabric Properties
6+
# check these on https://fabricmc.net/develop
7+
minecraft_version=1.20.1
8+
yarn_mappings=1.20.1+build.10
9+
loader_version=0.16.14
10+
11+
# Mod Properties
12+
mod_version=1.0.3-1.20-1.20.4
13+
maven_group=derp.immersive-hotbar
14+
archives_base_name=immersive-hotbar
15+
16+
# Dependencies
17+
fabric_version=0.92.5+1.20.1
18+
yacl_version=3.6.6+1.20.1-fabric
19+
modmenu_version=7.2.2
20+
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package derp.immersivehotbar;
2+
3+
import derp.immersivehotbar.config.ImmersiveHotbarConfigHandler;
4+
import derp.immersivehotbar.util.TooltipAnimationState;
5+
import net.fabricmc.api.ClientModInitializer;
6+
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
7+
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
8+
import net.fabricmc.loader.api.FabricLoader;
9+
import net.minecraft.item.*;
10+
import net.minecraft.util.hit.BlockHitResult;
11+
import net.minecraft.util.hit.HitResult;
12+
import net.minecraft.util.math.BlockPos;
13+
14+
import java.util.Arrays;
15+
import java.util.concurrent.atomic.AtomicReference;
16+
17+
import static derp.immersivehotbar.config.ImmersiveHotbarConfig.*;
18+
import static derp.immersivehotbar.util.SlotAnimationState.*;
19+
20+
public class ImmersiveHotbarClient implements ClientModInitializer {
21+
private boolean wasUsingItem = false;
22+
private ItemStack lastUsedItem = ItemStack.EMPTY;
23+
private boolean wasCrossbowChargedMainhand = false;
24+
private boolean wasCrossbowChargedOffhand = false;
25+
public static final boolean IS_DOUBLEHOTBAR_LOADED = FabricLoader.getInstance().isModLoaded("double_hotbar");
26+
27+
@Override
28+
public void onInitializeClient() {
29+
ImmersiveHotbarConfigHandler.load();
30+
31+
ClientPlayConnectionEvents.DISCONNECT.register((client, world) -> Arrays.fill(lastSlotStacks, ItemStack.EMPTY));
32+
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> TooltipAnimationState.reset());
33+
34+
ClientTickEvents.END_CLIENT_TICK.register(client -> {
35+
if (client.player == null) return;
36+
37+
boolean isUsing = client.player.isUsingItem();
38+
39+
// track bow usage
40+
if (isUsing) {
41+
lastUsedItem = client.player.getActiveItem();
42+
} else if (wasUsingItem && !lastUsedItem.isEmpty()) {
43+
Item item = lastUsedItem.getItem();
44+
45+
if (weaponAnimates && (item instanceof BowItem || item instanceof CrossbowItem)) {
46+
int slot = client.player.getMainHandStack() == lastUsedItem ? client.player.getInventory().selectedSlot : 9;
47+
triggerShrink(slot);
48+
}
49+
lastUsedItem = ItemStack.EMPTY;
50+
}
51+
52+
wasUsingItem = isUsing;
53+
54+
// crossbow mainhand
55+
ItemStack mainHandStack = client.player.getMainHandStack();
56+
if (mainHandStack.getItem() instanceof CrossbowItem) {
57+
boolean isCharged = CrossbowItem.isCharged(mainHandStack);
58+
if (wasCrossbowChargedMainhand && !isCharged && weaponAnimates) {
59+
int slot = client.player.getInventory().selectedSlot;
60+
triggerShrink(slot);
61+
}
62+
wasCrossbowChargedMainhand = isCharged;
63+
} else {
64+
wasCrossbowChargedMainhand = false;
65+
}
66+
67+
// crossbow offhand
68+
ItemStack offHandStack = client.player.getOffHandStack();
69+
if (offHandStack.getItem() instanceof CrossbowItem) {
70+
boolean isCharged = CrossbowItem.isCharged(offHandStack);
71+
if (wasCrossbowChargedOffhand && !isCharged && weaponAnimates) {
72+
triggerShrink(9);
73+
}
74+
wasCrossbowChargedOffhand = isCharged;
75+
} else {
76+
wasCrossbowChargedOffhand = false;
77+
}
78+
});
79+
// track block breaking to trigger tool animations
80+
AtomicReference<BlockPos> lastBreakingPos = new AtomicReference<>();
81+
82+
ClientTickEvents.END_CLIENT_TICK.register(client -> {
83+
if (client.world == null || client.player == null) return;
84+
85+
86+
HitResult r = client.crosshairTarget;
87+
if (r != null && r.getType() == HitResult.Type.BLOCK && client.options.attackKey.isPressed()) {
88+
BlockPos targetPos = ((BlockHitResult) r).getBlockPos();
89+
lastBreakingPos.set(targetPos);
90+
}
91+
92+
93+
BlockPos pending = lastBreakingPos.get();
94+
if (pending != null) {
95+
96+
if (client.world.getBlockState(pending).isAir()) {
97+
ItemStack stack = client.player.getMainHandStack();
98+
if (stack.getItem() instanceof ToolItem && toolAnimates) {
99+
int slot = client.player.getInventory().selectedSlot;
100+
triggerShrink(slot);
101+
}
102+
103+
lastBreakingPos.set(null);
104+
}
105+
}
106+
});
107+
}
108+
109+
110+
private void triggerShrink(int slot) {
111+
if (slot >= 0 && slot < 9) {
112+
wasUsed[slot] = true;
113+
slotScales[slot] = nonSelectedItemSize - (shouldItemGrowWhenSelected ? 0.03f : 0.2f);
114+
} else if (slot == 9) {
115+
wasUsed[slot] = true;
116+
slotScales[slot] = nonSelectedItemSize - 0.2f;
117+
}
118+
}
119+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package derp.immersivehotbar;
2+
3+
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
4+
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
5+
6+
public class ImmersiveHotbarDataGenerator implements DataGeneratorEntrypoint {
7+
@Override
8+
public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) {
9+
10+
}
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package derp.immersivehotbar;
2+
3+
public interface InGameHudAnimationHandler {
4+
void immersive_hotbar$triggerSlotAnimation(int slotIndex);
5+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package derp.immersivehotbar.config;
2+
3+
import dev.isxander.yacl3.config.v2.api.SerialEntry;
4+
5+
import java.awt.*;
6+
7+
public class ImmersiveHotbarConfig {
8+
9+
@SerialEntry
10+
public static float selectedItemSize = 1.2f;
11+
12+
@SerialEntry
13+
public static float bouncyStiffness = 0.3f;
14+
15+
@SerialEntry
16+
public static float bouncyDamping = 0.2f;
17+
18+
@SerialEntry
19+
public static boolean shouldItemGrowWhenSelected = true;
20+
21+
@SerialEntry
22+
public static boolean durabilityAnimates = true;
23+
24+
@SerialEntry
25+
public static boolean toolAnimates = false;
26+
27+
@SerialEntry
28+
public static boolean weaponAnimates = false;
29+
30+
@SerialEntry
31+
public static boolean bouncyAnimation = false;
32+
33+
@SerialEntry
34+
public static boolean foodAnimates = true;
35+
36+
@SerialEntry
37+
public static boolean toolsIgnoreBounce = false;
38+
39+
@SerialEntry
40+
public static boolean weaponsIgnoreBounce = false;
41+
42+
@SerialEntry
43+
public static boolean textScales = true;
44+
45+
@SerialEntry
46+
public static Color hotbarSelectionColor = new Color(255, 255, 255, 127);
47+
48+
@SerialEntry
49+
public static boolean lowDurabilityGlow = false;
50+
51+
@SerialEntry
52+
public static boolean immersiveToolTip = true;
53+
54+
@SerialEntry
55+
public static int tooltipYOffset = 52;
56+
57+
@SerialEntry
58+
public static boolean scaleTooltipOffset = true;
59+
60+
@SerialEntry
61+
public static float durabilityGlowThreshold = 0.8f;
62+
63+
@SerialEntry
64+
public static shouldShowBackground showBackground = shouldShowBackground.DISABLED;
65+
66+
@SerialEntry
67+
public static float animationIntensity = 0.5f;
68+
69+
@SerialEntry
70+
public static float nonSelectedItemSize = 1.0f;
71+
72+
@SerialEntry
73+
public static float shrinkAnimationSpeed = 2.5f;
74+
75+
@SerialEntry
76+
public static float animationSpeed = 0.1f;
77+
78+
public enum shouldShowBackground {
79+
DISABLED,
80+
ENABLED,
81+
ONLY_WHEN_SELECTED;
82+
83+
@Override
84+
public String toString() {
85+
return switch (this) {
86+
case DISABLED -> "Disabled";
87+
case ENABLED -> "Always";
88+
case ONLY_WHEN_SELECTED -> "Only When Selected";
89+
};
90+
}
91+
}
92+
93+
}

0 commit comments

Comments
 (0)