Skip to content

Commit d074878

Browse files
committed
fix(track encasing): broken textures after reloading resources
1 parent 68713f0 commit d074878

File tree

8 files changed

+89
-7
lines changed

8 files changed

+89
-7
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Fixes
1212
- Texture inconsistency with the white color used for the favourites button
1313
- Bogey Menu scrollbar not having ridges like other scroll bars in Minecraft
1414
- Fix handcars parking at stations allowing them to be disassembled
15+
- Tracking encasing having the wrong texture after changing resource packs or reloading resources
1516

1617
Changes
1718
- Lower particle count for boiler blocks being broken
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Steam 'n' Rails
3+
* Copyright (c) 2024 The Railways Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.railwayteam.railways.content.custom_tracks.casing;
20+
21+
import net.minecraft.server.packs.resources.ResourceManager;
22+
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
23+
import org.jetbrains.annotations.NotNull;
24+
25+
public class CasingResourceReloadListener implements ResourceManagerReloadListener {
26+
public static CasingResourceReloadListener INSTANCE = new CasingResourceReloadListener();
27+
28+
@Override
29+
public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
30+
CasingRenderUtils.clearModelCache();
31+
}
32+
}

fabric/src/main/java/com/railwayteam/railways/fabric/RailwaysImpl.java

-7
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,12 @@
2121
import com.mojang.brigadier.CommandDispatcher;
2222
import com.railwayteam.railways.Railways;
2323
import com.railwayteam.railways.config.fabric.CRConfigsImpl;
24-
import com.railwayteam.railways.content.fuel.LiquidFuelManager;
2524
import com.railwayteam.railways.fabric.events.CommonEventsFabric;
2625
import com.railwayteam.railways.registry.fabric.CRParticleTypesParticleEntryImpl;
2726
import net.fabricmc.api.ModInitializer;
2827
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
29-
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
30-
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
3128
import net.fabricmc.loader.api.FabricLoader;
3229
import net.minecraft.commands.CommandSourceStack;
33-
import net.minecraft.server.packs.PackType;
3430

3531
import java.util.function.BiConsumer;
3632

@@ -41,9 +37,6 @@ public void onInitialize() {
4137
CRConfigsImpl.register();
4238
CRParticleTypesParticleEntryImpl.register();
4339
CommonEventsFabric.init();
44-
45-
// This is fine at runtime, there's a mixin implementing that interface
46-
ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener((IdentifiableResourceReloadListener) LiquidFuelManager.ReloadListener.INSTANCE);
4740
}
4841

4942
public static String findVersion() {

fabric/src/main/java/com/railwayteam/railways/fabric/events/ClientEventsFabric.java

+4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919
package com.railwayteam.railways.fabric.events;
2020

2121
import com.railwayteam.railways.Railways;
22+
import com.railwayteam.railways.content.custom_tracks.casing.CasingResourceReloadListener;
2223
import com.railwayteam.railways.events.ClientEvents;
2324
import com.railwayteam.railways.registry.CRParticleTypes;
2425
import io.github.fabricators_of_create.porting_lib.event.client.ClientWorldEvents;
2526
import io.github.fabricators_of_create.porting_lib.event.client.KeyInputCallback;
2627
import io.github.fabricators_of_create.porting_lib.event.client.ParticleManagerRegistrationCallback;
2728
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
29+
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
2830
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
2931
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
3032
import net.minecraft.resources.ResourceLocation;
@@ -52,5 +54,7 @@ public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
5254
ClientEvents.onTagsUpdated();
5355
}
5456
});
57+
58+
ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener((IdentifiableResourceReloadListener) CasingResourceReloadListener.INSTANCE);
5559
}
5660
}

fabric/src/main/java/com/railwayteam/railways/fabric/events/CommonEventsFabric.java

+6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818

1919
package com.railwayteam.railways.fabric.events;
2020

21+
import com.railwayteam.railways.content.fuel.LiquidFuelManager;
2122
import com.railwayteam.railways.events.CommonEvents;
2223
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
2324
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
2425
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
26+
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
27+
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
28+
import net.minecraft.server.packs.PackType;
2529

2630
public class CommonEventsFabric {
2731
public static void init() {
@@ -30,5 +34,7 @@ public static void init() {
3034
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register(((server, resourceManager, success) -> {
3135
CommonEvents.onTagsUpdated();
3236
}));
37+
// This is fine at runtime, there's a mixin implementing that interface
38+
ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener((IdentifiableResourceReloadListener) LiquidFuelManager.ReloadListener.INSTANCE);
3339
}
3440
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Steam 'n' Rails
3+
* Copyright (c) 2024 The Railways Team
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.railwayteam.railways.fabric.mixin.self;
20+
21+
import com.railwayteam.railways.Railways;
22+
import com.railwayteam.railways.content.custom_tracks.casing.CasingResourceReloadListener;
23+
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
24+
import net.minecraft.resources.ResourceLocation;
25+
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
26+
import org.spongepowered.asm.mixin.Mixin;
27+
import org.spongepowered.asm.mixin.Unique;
28+
29+
@Mixin(CasingResourceReloadListener.class)
30+
public abstract class CasingResourceReloadListenerMixin implements ResourceManagerReloadListener, IdentifiableResourceReloadListener {
31+
@Unique
32+
private static final ResourceLocation ID = Railways.asResource("casing_reload_listener");
33+
34+
@Override
35+
public ResourceLocation getFabricId() {
36+
return ID;
37+
}
38+
}

fabric/src/main/resources/railways.mixins.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"MountedStorageManagerMixin",
2020
"TrainMixin",
2121
"self.BoilerBlockMixin",
22+
"self.CasingResourceReloadListenerMixin",
2223
"self.LiquidFuelManagerReloadListenerMixin"
2324
],
2425
"injectors": {

forge/src/main/java/com/railwayteam/railways/forge/events/ClientEventsForge.java

+7
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818

1919
package com.railwayteam.railways.forge.events;
2020

21+
import com.railwayteam.railways.content.custom_tracks.casing.CasingResourceReloadListener;
2122
import com.railwayteam.railways.events.ClientEvents;
2223
import com.railwayteam.railways.registry.forge.CRKeysImpl;
2324
import net.minecraft.client.Minecraft;
2425
import net.minecraft.world.level.Level;
2526
import net.minecraftforge.api.distmarker.Dist;
2627
import net.minecraftforge.client.event.InputEvent;
28+
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
2729
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
2830
import net.minecraftforge.event.TagsUpdatedEvent;
2931
import net.minecraftforge.event.TickEvent;
@@ -66,5 +68,10 @@ public static class ModBusEvents {
6668
public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) {
6769
CRKeysImpl.onRegisterKeyMappings(event);
6870
}
71+
72+
@SubscribeEvent
73+
public static void registerClientReloadListeners(RegisterClientReloadListenersEvent event) {
74+
event.registerReloadListener(CasingResourceReloadListener.INSTANCE);
75+
}
6976
}
7077
}

0 commit comments

Comments
 (0)