Skip to content

Commit 3a117e5

Browse files
eristheaA5ho9999
andauthored
1.21.4 port (#39)
* port work * Full working update with 1.21.4 (and 3 maybe) * Update build.yml * fix crash when spawning new entity * fix a cast exception on glow squids * eliminate really unsafe getColour method * bump version --------- Co-authored-by: A5ho9999 <a5ho9999.gamer@gmail.com> Co-authored-by: A5ho9999 <46066364+A5ho9999@users.noreply.github.com>
1 parent a00c9c6 commit 3a117e5

26 files changed

+342
-77
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ jobs:
77
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v3
10+
- uses: actions/checkout@v4
1111
- name: set up JDK 21
12-
uses: actions/setup-java@v3
12+
uses: actions/setup-java@v4
1313
with:
1414
distribution: 'temurin'
1515
java-version: '21'
@@ -18,7 +18,7 @@ jobs:
1818
- name: build with gradle
1919
run: ./gradlew build
2020
- name: capture build artifacts
21-
uses: actions/upload-artifact@v3
21+
uses: actions/upload-artifact@v4
2222
with:
2323
name: artifacts
2424
path: build/libs/

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
//file:noinspection GroovyAssignabilityCheck
12
plugins {
2-
id "fabric-loom" version "1.6.+"
3+
id "fabric-loom" version "1.7.+"
34
id "com.github.johnrengelman.shadow" version "7.1.+"
45
id "me.modmuss50.mod-publish-plugin" version "0.5.2"
56
}

gradle.properties

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# increase gradle memory
2-
org.gradle.jvmargs=-Xmx1G
2+
org.gradle.jvmargs = -Xmx1G
33

44
# minecraft, mappings and loader dependencies
55
# check these on https://modmuss50.me/fabric.html
6-
minecraft_version=1.21.1
7-
quilt_mappings=2
8-
loader_version=0.15.11
9-
kaleido_config_version=0.3.1+1.3.2
6+
minecraft_version = 1.21.4
7+
quilt_mappings = 3
8+
loader_version = 0.16.10
9+
kaleido_config_version = 0.3.1+1.3.2
1010

1111
# mod properties
12-
mod_version=1.3.5+mc1.21.1
13-
maven_group=rainglow
14-
archives_base_name=rainglow
12+
mod_version = 1.3.6+mc1.21.4
13+
maven_group = rainglow
14+
archives_base_name = rainglow
1515

1616
# other dependencies
17-
java_version=21
18-
mod_menu_version=11.0.1
19-
fabric_api_version=0.102.0+1.21.1
17+
java_version = 21
18+
mod_menu_version = 13.0.0-beta.1
19+
fabric_api_version = 0.118.5+1.21.4
2020

2121
pub.should_publish = true
22-
pub.additional_versions = 1.21
22+
pub.additional_versions = 1.21.4

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/java/io/ix0rai/rainglow/Rainglow.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.ix0rai.rainglow.config.RainglowConfig;
99
import io.ix0rai.rainglow.data.*;
1010
import net.fabricmc.api.ModInitializer;
11+
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
1112
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
1213
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
1314
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
@@ -71,8 +72,14 @@ public void onInitialize() {
7172
});
7273

7374
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
74-
COLOURS.clear();
75+
// Only clear colours on disconnect if server is NOT single-player to prevent NBT save failure (Unsure how this works with Lan-instances)
76+
if (!server.isSingleplayer()) {
77+
COLOURS.clear();
78+
}
7579
});
80+
81+
// Instead use SERVER_STOPPED for clearing colours from single-player worlds. (Doesn't affect others because mod would most likely be shutdown in non-single-player instances)
82+
ServerLifecycleEvents.SERVER_STOPPED.register(server -> COLOURS.clear());
7683
}
7784

7885
public static Identifier id(String id) {
@@ -102,15 +109,14 @@ public static Text translatableText(String key) {
102109
return Text.translatable(translatableTextKey(key));
103110
}
104111

105-
public static RainglowColour getColour(Entity entity) {
106-
RainglowColour colour = COLOURS.get(entity.getUuid());
107-
RainglowEntity entityType = RainglowEntity.get(entity);
112+
public static RainglowColour getColour(UUID uuid, World world, RainglowEntity type) {
113+
RainglowColour colour = COLOURS.get(uuid);
108114

109115
// generate random colour if the squid's colour isn't currently loaded
110-
if (colourUnloaded(entity.getWorld(), entityType, colour)) {
116+
if (colourUnloaded(world, type, colour)) {
111117
// Use last generated colour if not null else generate a new colour
112-
colour = generateRandomColour(entity.getWorld(), entity.getRandom());
113-
COLOURS.put(entity.getUuid(), colour);
118+
colour = generateRandomColour(world, world.getRandom());
119+
COLOURS.put(uuid, colour);
114120
}
115121

116122
return colour;

src/main/java/io/ix0rai/rainglow/config/CustomModeScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected void repositionElements() {
111111

112112
private static void sendNoColoursToast() {
113113
Toast toast = new SystemToast(SystemToast.Id.PACK_LOAD_FAILURE, Rainglow.translatableText("config.no_custom_colours"), Rainglow.translatableText("config.no_custom_colours_description"));
114-
MinecraftClient.getInstance().getToastManager().add(toast);
114+
MinecraftClient.getInstance().method_1566().method_1999(toast);
115115
}
116116

117117
@Override
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.ix0rai.rainglow.data;
2+
3+
import net.minecraft.entity.Entity;
4+
5+
import java.util.UUID;
6+
7+
/**
8+
* @author A5ho9999
9+
* Interface to track entity data in render states
10+
*/
11+
public interface EntityRenderStateTracker {
12+
/**
13+
* Set the associated entity
14+
* @param entity The entity to associate with this render state
15+
*/
16+
void rainglow$setEntity(Entity entity);
17+
18+
/**
19+
* Get the associated entity UUID
20+
* @return The UUID of the associated entity, or null if not set
21+
*/
22+
UUID rainglow$getEntityUuid();
23+
}
Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
package io.ix0rai.rainglow.data;
22

3-
import net.minecraft.entity.EntityData;
3+
import net.minecraft.entity.passive.PassiveEntity;
44

5-
public record GlowSquidEntityData(RainglowColour colour) implements EntityData {
5+
public class GlowSquidEntityData extends PassiveEntity.PassiveData {
6+
private final RainglowColour colour;
7+
8+
public GlowSquidEntityData(RainglowColour colour) {
9+
// copied from SquidEntity#initialize. as far as i can tell we have to duplicate this constant
10+
super(0.05F);
11+
this.colour = colour;
12+
}
13+
14+
public RainglowColour getColour() {
15+
return colour;
16+
}
617
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.ix0rai.rainglow.data;
2+
3+
import net.minecraft.client.particle.ItemBreakParticle;
4+
import net.minecraft.client.particle.Particle;
5+
import net.minecraft.client.world.ClientWorld;
6+
import net.minecraft.unmapped.C_hvackyip;
7+
8+
/**
9+
* @author A5ho9999
10+
* Helper for creating particles because Mojang likes to torture everyone
11+
*/
12+
public class ParticleHelper {
13+
public static class CustomItemBreakParticle extends ItemBreakParticle {
14+
public CustomItemBreakParticle(ClientWorld world, double d, double e, double f, C_hvackyip c_hvackyip) {
15+
super(world, d, e, f, c_hvackyip);
16+
}
17+
}
18+
19+
public static Particle createItemBreakParticle(ClientWorld world, double d, double e, double f, C_hvackyip c_hvackyip) {
20+
return new CustomItemBreakParticle(world, d, e, f, c_hvackyip);
21+
}
22+
}

src/main/java/io/ix0rai/rainglow/data/RainglowEntity.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import net.minecraft.util.random.RandomGenerator;
1414
import net.minecraft.world.World;
1515
import org.jetbrains.annotations.Nullable;
16-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1716

1817
import java.util.Arrays;
1918
import java.util.HashMap;
19+
import java.util.UUID;
2020
import java.util.function.Function;
2121

2222
public enum RainglowEntity {
@@ -99,14 +99,18 @@ public static RainglowEntity get(Entity entity) {
9999
return null;
100100
}
101101

102-
public void overrideTexture(Entity entity, CallbackInfoReturnable<Identifier> cir) {
103-
RainglowColour colour = Rainglow.getColour(entity);
102+
@Nullable
103+
public Identifier overrideTexture(UUID uuid, World world) {
104+
RainglowColour colour = Rainglow.getColour(uuid, world, this);
105+
106+
// Returning null will just use default texture, no need for extra checks
104107

105108
// if the colour is default we don't need to override the method
106109
// this optimises a tiny bit
107110
if (Rainglow.CONFIG.isEntityEnabled(this) && colour != this.getDefaultColour()) {
108-
Identifier texture = colour.getTexture(this);
109-
cir.setReturnValue(texture != null ? texture : this.getDefaultTexture());
111+
return colour.getTexture(this);
110112
}
113+
114+
return null;
111115
}
112116
}

0 commit comments

Comments
 (0)