-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rework PreferenceList and IngredientBlackList
- Loading branch information
Showing
21 changed files
with
631 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.vfyjxf.nee.asm; | ||
|
||
import appeng.api.storage.data.IAEItemStack; | ||
import appeng.client.gui.implementations.GuiMEMonitorable; | ||
import appeng.core.sync.AppEngPacket; | ||
import appeng.core.sync.network.INetworkInfo; | ||
import mezz.jei.gui.recipes.RecipesGui; | ||
import net.minecraft.client.gui.GuiScreen; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import p455w0rd.wct.client.gui.GuiWCT; | ||
|
||
import java.util.List; | ||
|
||
@SuppressWarnings("unused") | ||
public class AppengHooks { | ||
|
||
/** | ||
* Before {@link appeng.core.sync.packets.PacketMEInventoryUpdate#clientPacketData(INetworkInfo, AppEngPacket, EntityPlayer)} Return | ||
*/ | ||
public static void updateMeInventory(GuiScreen screen, final List<IAEItemStack> list) { | ||
if (screen instanceof RecipesGui) { | ||
GuiScreen parent = ((RecipesGui) screen).getParentScreen(); | ||
if (parent instanceof GuiMEMonitorable) { | ||
((GuiMEMonitorable) parent).postUpdate(list); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Before {@link appeng.client.gui.implementations.GuiMEMonitorable#postUpdate(List)} Return | ||
*/ | ||
public static void updateWirelessInventory(GuiScreen screen, final List<IAEItemStack> list){ | ||
if (screen instanceof RecipesGui) { | ||
GuiScreen parent = ((RecipesGui) screen).getParentScreen(); | ||
if (parent instanceof GuiWCT) { | ||
((GuiWCT) parent).postUpdate(list); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/com/github/vfyjxf/nee/config/IngredientBlackList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.github.vfyjxf.nee.config; | ||
|
||
import com.github.vfyjxf.nee.utils.BlackIngredient; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.nbt.JsonToNBT; | ||
import net.minecraft.nbt.NBTException; | ||
import org.apache.commons.io.IOUtils; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class IngredientBlackList { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
public static final IngredientBlackList INSTANCE = new IngredientBlackList(); | ||
|
||
private final List<BlackIngredient> blackList = new ArrayList<>(); | ||
|
||
private IngredientBlackList() { | ||
|
||
} | ||
|
||
public void addPreference(ItemStack stack, String acceptedType) { | ||
BlackIngredient ingredient = new BlackIngredient(stack, acceptedType); | ||
if (!blackList.contains(ingredient)) { | ||
blackList.add(ingredient); | ||
saveList(); | ||
} | ||
} | ||
|
||
public List<BlackIngredient> getBlackList() { | ||
return blackList; | ||
} | ||
|
||
public void loadList() { | ||
|
||
File file = NEEConfig.getBlacklistFile(); | ||
if (file == null || !file.exists()) { | ||
return; | ||
} | ||
|
||
List<String> strings; | ||
try (FileReader reader = new FileReader(file)) { | ||
strings = IOUtils.readLines(reader); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to load blacklist from file {}", file, e); | ||
return; | ||
} | ||
|
||
List<BlackIngredient> list = strings.stream() | ||
.map(jsonString -> { | ||
try { | ||
return JsonToNBT.getTagFromJson(jsonString); | ||
} catch (NBTException e) { | ||
throw new RuntimeException(e); | ||
} | ||
}) | ||
.map(tagCompound -> { | ||
ItemStack identifier = new ItemStack(tagCompound.getCompoundTag("identifier")); | ||
String acceptedType = tagCompound.hasKey("acceptedType") ? tagCompound.getString("acceptedType") : null; | ||
return new BlackIngredient(identifier, acceptedType); | ||
}) | ||
.collect(Collectors.toList()); | ||
|
||
this.blackList.clear(); | ||
this.blackList.addAll(list); | ||
} | ||
|
||
public void saveList() { | ||
File file = NEEConfig.getBlacklistFile(); | ||
if (file != null) { | ||
List<String> strings = blackList.stream() | ||
.map(blackIngredient -> blackIngredient.toTag().toString()) | ||
.collect(Collectors.toList()); | ||
try (FileWriter writer = new FileWriter(file)) { | ||
IOUtils.writeLines(strings, "\n", writer); | ||
} catch (IOException e) { | ||
LOGGER.error("Failed to save blacklist to file {}", file, e); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.