Skip to content

Commit

Permalink
Delay recipe syncing if the player is null, closes #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Buuz135 committed Aug 5, 2018
1 parent 36a2454 commit 6cd75d0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
buildscript {
repositories {
jcenter()
mavenCentral()
maven {
name = "forge"
url = "https://files.minecraftforge.net/maven"
Expand All @@ -17,7 +16,7 @@ plugins {
id "com.github.hierynomus.license" version "0.14.0"
id "com.matthewprenger.cursegradle" version "1.0.10"
}
apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.selesse.git.changelog'
apply plugin: 'java'

Expand Down Expand Up @@ -114,7 +113,7 @@ changelog {
title = "Thaumic JEI"
fileName = "CHANGELOG.md"
outputDirectory = file("$projectDir")
since = 'last_tag'
since = '1.4.0'
commitFormat = '%s (%an)'
markdown {
commitFormat = '* %s (%an)'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
modGroup=com.buuz135.thaumicjei.ThaumicJEI
modVersion=1.5.0
modVersion=1.5.1
minecraftVersion=1.12.2
modBaseName=ThaumicJEI
forgeVersion=1.12.2-14.23.4.2747
mcpVersion=snapshot_20180410
mcpVersion=snapshot_20171003
jei_version=4.10.0.198
35 changes: 30 additions & 5 deletions src/main/java/com/buuz135/thaumicjei/event/ResearchManager.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
/*
* This file is part of Hot or Not.
*
* Copyright 2018, Buuz135
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in the
* Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.buuz135.thaumicjei.event;

import com.buuz135.thaumicjei.ThaumcraftJEIPlugin;
Expand All @@ -19,7 +40,7 @@
@Mod.EventBusSubscriber(modid = ThaumicJEI.MOD_ID, value = Side.CLIENT)
public class ResearchManager {

private static int needSync = -1;
private static int timeToSync = -1;

@SubscribeEvent
public static void onResearch(ResearchEvent.Research event) {
Expand All @@ -29,20 +50,24 @@ public static void onResearch(ResearchEvent.Research event) {
@SubscribeEvent
public static void onJoin(WorldEvent.Load event) {
if (event.getWorld() instanceof WorldClient) {
needSync = 20;
timeToSync = 20;
}
}

@SubscribeEvent
public static void onTick(TickEvent.ClientTickEvent event) {
if (needSync >= 0 && event.phase == TickEvent.Phase.END) {
if (needSync == 0) sync("");
needSync--;
if (timeToSync >= 0 && event.phase == TickEvent.Phase.END) {
if (timeToSync == 0) sync("");
timeToSync--;
}
}

private static void sync(String current) {
if (!ThaumicConfig.hideRecipesIfMissingResearch) return;
if (Minecraft.getMinecraft().player == null) {
timeToSync = 20;
return;
}
if (Minecraft.getMinecraft().player.hasCapability(ThaumcraftCapabilities.KNOWLEDGE, null)) {
for (String uuid : new String[]{ThaumcraftJEIPlugin.arcaneWorkbenchCategory.getUid(), ThaumcraftJEIPlugin.crucibleCategory.getUid(), ThaumcraftJEIPlugin.infusionCategory.getUid()}) {
ThaumcraftJEIPlugin.runtime.getRecipeRegistry().getRecipeWrappers(ThaumcraftJEIPlugin.runtime.getRecipeRegistry().getRecipeCategory(uuid)).forEach(o -> ThaumcraftJEIPlugin.runtime.getRecipeRegistry().hideRecipe((IRecipeWrapper) o, uuid));
Expand Down

0 comments on commit 6cd75d0

Please sign in to comment.