Skip to content

Commit

Permalink
fix(track encasing): broken textures after reloading resources
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Jul 29, 2024
1 parent 68713f0 commit d074878
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Fixes
- Texture inconsistency with the white color used for the favourites button
- Bogey Menu scrollbar not having ridges like other scroll bars in Minecraft
- Fix handcars parking at stations allowing them to be disassembled
- Tracking encasing having the wrong texture after changing resource packs or reloading resources

Changes
- Lower particle count for boiler blocks being broken
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Steam 'n' Rails
* Copyright (c) 2024 The Railways Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.railwayteam.railways.content.custom_tracks.casing;

import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
import org.jetbrains.annotations.NotNull;

public class CasingResourceReloadListener implements ResourceManagerReloadListener {
public static CasingResourceReloadListener INSTANCE = new CasingResourceReloadListener();

@Override
public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
CasingRenderUtils.clearModelCache();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@
import com.mojang.brigadier.CommandDispatcher;
import com.railwayteam.railways.Railways;
import com.railwayteam.railways.config.fabric.CRConfigsImpl;
import com.railwayteam.railways.content.fuel.LiquidFuelManager;
import com.railwayteam.railways.fabric.events.CommonEventsFabric;
import com.railwayteam.railways.registry.fabric.CRParticleTypesParticleEntryImpl;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.server.packs.PackType;

import java.util.function.BiConsumer;

Expand All @@ -41,9 +37,6 @@ public void onInitialize() {
CRConfigsImpl.register();
CRParticleTypesParticleEntryImpl.register();
CommonEventsFabric.init();

// This is fine at runtime, there's a mixin implementing that interface
ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener((IdentifiableResourceReloadListener) LiquidFuelManager.ReloadListener.INSTANCE);
}

public static String findVersion() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
package com.railwayteam.railways.fabric.events;

import com.railwayteam.railways.Railways;
import com.railwayteam.railways.content.custom_tracks.casing.CasingResourceReloadListener;
import com.railwayteam.railways.events.ClientEvents;
import com.railwayteam.railways.registry.CRParticleTypes;
import io.github.fabricators_of_create.porting_lib.event.client.ClientWorldEvents;
import io.github.fabricators_of_create.porting_lib.event.client.KeyInputCallback;
import io.github.fabricators_of_create.porting_lib.event.client.ParticleManagerRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -52,5 +54,7 @@ public void onResourceManagerReload(@NotNull ResourceManager resourceManager) {
ClientEvents.onTagsUpdated();
}
});

ResourceManagerHelper.get(PackType.CLIENT_RESOURCES).registerReloadListener((IdentifiableResourceReloadListener) CasingResourceReloadListener.INSTANCE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@

package com.railwayteam.railways.fabric.events;

import com.railwayteam.railways.content.fuel.LiquidFuelManager;
import com.railwayteam.railways.events.CommonEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.server.packs.PackType;

public class CommonEventsFabric {
public static void init() {
Expand All @@ -30,5 +34,7 @@ public static void init() {
ServerLifecycleEvents.END_DATA_PACK_RELOAD.register(((server, resourceManager, success) -> {
CommonEvents.onTagsUpdated();
}));
// This is fine at runtime, there's a mixin implementing that interface
ResourceManagerHelper.get(PackType.SERVER_DATA).registerReloadListener((IdentifiableResourceReloadListener) LiquidFuelManager.ReloadListener.INSTANCE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Steam 'n' Rails
* Copyright (c) 2024 The Railways Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.railwayteam.railways.fabric.mixin.self;

import com.railwayteam.railways.Railways;
import com.railwayteam.railways.content.custom_tracks.casing.CasingResourceReloadListener;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManagerReloadListener;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;

@Mixin(CasingResourceReloadListener.class)
public abstract class CasingResourceReloadListenerMixin implements ResourceManagerReloadListener, IdentifiableResourceReloadListener {
@Unique
private static final ResourceLocation ID = Railways.asResource("casing_reload_listener");

@Override
public ResourceLocation getFabricId() {
return ID;
}
}
1 change: 1 addition & 0 deletions fabric/src/main/resources/railways.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"MountedStorageManagerMixin",
"TrainMixin",
"self.BoilerBlockMixin",
"self.CasingResourceReloadListenerMixin",
"self.LiquidFuelManagerReloadListenerMixin"
],
"injectors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

package com.railwayteam.railways.forge.events;

import com.railwayteam.railways.content.custom_tracks.casing.CasingResourceReloadListener;
import com.railwayteam.railways.events.ClientEvents;
import com.railwayteam.railways.registry.forge.CRKeysImpl;
import net.minecraft.client.Minecraft;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.InputEvent;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.event.TagsUpdatedEvent;
import net.minecraftforge.event.TickEvent;
Expand Down Expand Up @@ -66,5 +68,10 @@ public static class ModBusEvents {
public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) {
CRKeysImpl.onRegisterKeyMappings(event);
}

@SubscribeEvent
public static void registerClientReloadListeners(RegisterClientReloadListenersEvent event) {
event.registerReloadListener(CasingResourceReloadListener.INSTANCE);
}
}
}

0 comments on commit d074878

Please sign in to comment.