Skip to content

Commit

Permalink
fix: gate wire models not refreshing on resource pack reload
Browse files Browse the repository at this point in the history
  • Loading branch information
MrTJP committed Jul 12, 2021
1 parent 8655723 commit 8f840bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ object WireModel3D
bakeOrients(model)
})

def regenerateModels():Unit = {
val keys = cache.keySet.toSet //Copy old keyset
cache.clear()
for (k <- keys) getOrGenerateModels(k) //Regenerate all keys
}

def generateModel(data:Array[Colour]) =
{
val wireRectangles = TWireModel.rectangulate(data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import mrtjp.projectred.integration.ComponentStore._
import net.minecraft.client.renderer.IRenderTypeBuffer
import net.minecraft.item.ItemStack
import net.minecraft.particles.RedstoneParticleData
import net.minecraft.resources.IResourceManager
import net.minecraftforge.resource.{IResourceType, ISelectiveResourceReloadListener, VanillaResourceType}

import java.util.Random
import java.util.function.Predicate

class RenderGate
{
Expand Down Expand Up @@ -95,7 +98,7 @@ class RenderGate
}
}

object RenderGate extends IIconRegister
object RenderGate extends IIconRegister with ISelectiveResourceReloadListener
{
private val instances = new ThreadLocal[RenderGate]() {
override def initialValue() = new RenderGate
Expand All @@ -107,6 +110,11 @@ object RenderGate extends IIconRegister
ComponentStore.registerIcons(map)
for (m <- instance().renderers) m.registerIcons(map)
}

override def onResourceManagerReload(resourceManager:IResourceManager, resourcePredicate:Predicate[IResourceType]):Unit = {
if (resourcePredicate.test(VanillaResourceType.TEXTURES))
WireModel3D.regenerateModels()
}
}

abstract class GateRenderer[T <: GatePart]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package mrtjp.projectred.integration

import codechicken.lib.texture.{AtlasRegistrar, IIconRegister, SpriteRegistryHelper}
import codechicken.lib.util.ResourceUtils
import mrtjp.projectred.ProjectRedIntegration
import mrtjp.projectred.core.IProxy
import net.minecraft.util.ResourceLocation
Expand Down Expand Up @@ -43,6 +44,7 @@ class IntegrationProxyClient extends IntegrationProxy
@SubscribeEvent
@OnlyIn(Dist.CLIENT)
override def clientSetup(event:FMLClientSetupEvent):Unit = {
ResourceUtils.registerReloadListener(RenderGate)
}

@OnlyIn(Dist.CLIENT)
Expand Down

0 comments on commit 8f840bc

Please sign in to comment.