Register the pony manager at the correct time

This commit is contained in:
Sollace 2019-07-03 14:16:03 +02:00
parent 098918c505
commit 9641bbfe5c
2 changed files with 13 additions and 7 deletions

View file

@ -18,13 +18,14 @@ import java.util.stream.Collectors;
import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding;
import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.texture.PlayerSkinProvider;
import net.minecraft.client.util.InputUtil;
import net.minecraft.resource.ReloadableResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Style;
import net.minecraft.text.TranslatableText;
@ -54,12 +55,13 @@ public class MineLPClient extends MineLittlePony {
}
public MineLPClient() {
config = JsonConfig.of(GamePaths.getConfigDirectory().resolve("minelp.json"), this::createConfig);
ponyManager = new PonyManager(config);
keyBinding = FabricKeyBinding.Builder.create(new Identifier("minelittlepony", "settings"), InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_F9, "key.categories.misc").build();
KeyBindingRegistry.INSTANCE.register(keyBinding);
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(ponyManager);
}
protected ClientPonyConfig createConfig() {
@ -72,9 +74,6 @@ public class MineLPClient extends MineLittlePony {
public void postInit(MinecraftClient minecraft) {
EntityRenderDispatcher rm = minecraft.getEntityRenderManager();
renderManager.initialiseRenderers(rm);
ReloadableResourceManager irrm = (ReloadableResourceManager) MinecraftClient.getInstance().getResourceManager();
irrm.registerListener(ponyManager);
}
public void onTick(MinecraftClient minecraft, boolean inGame) {

View file

@ -16,13 +16,13 @@ import com.minelittlepony.util.math.MathUtil;
import javax.annotation.Nullable;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.client.util.DefaultSkinHelper;
import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceReloadListener;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
@ -43,7 +43,9 @@ import java.util.concurrent.TimeUnit;
* The PonyManager is responsible for reading and recoding all the pony data associated with an entity of skin.
*
*/
public class PonyManager implements IPonyManager, ResourceReloadListener {
public class PonyManager implements IPonyManager, IdentifiableResourceReloadListener {
private static final Identifier ID = new Identifier("minelittlepony", "background_ponies");
private static final Gson GSON = new Gson();
@ -158,6 +160,11 @@ public class PonyManager implements IPonyManager, ResourceReloadListener {
}, clientExecutor);
}
@Override
public Identifier getFabricId() {
return ID;
}
public void clearCache() {
MineLittlePony.logger.info("Flushed {} cached ponies.", poniesCache.size());
poniesCache.invalidateAll();