aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-02-10 05:26:41 +0100
committernea <romangraef@gmail.com>2022-02-10 05:26:41 +0100
commit6b0d7adb874e09f3022d22f16815cf07fbf0d828 (patch)
treee58a3a7004e8adb922fff639ba6f5cccca821dae
parent3b844cb2c8bcf191a4249114383ea7cc88c8849c (diff)
downloadNotEnoughUpdates-6b0d7adb874e09f3022d22f16815cf07fbf0d828.tar.gz
NotEnoughUpdates-6b0d7adb874e09f3022d22f16815cf07fbf0d828.tar.bz2
NotEnoughUpdates-6b0d7adb874e09f3022d22f16815cf07fbf0d828.zip
villager trades now respect your profile ( i think) (cant test) (blamenopo)
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java5
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java11
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/recipes/NeuRecipe.java4
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java6
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java110
5 files changed, 127 insertions, 9 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
index 614884d9..4e5a3a01 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUManager.java
@@ -33,6 +33,7 @@ import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -955,7 +956,7 @@ public class NEUManager {
Set<NeuRecipe> usages = usagesMap.get(internalName);
if (usages.isEmpty()) return false;
Minecraft.getMinecraft().displayGuiScreen(
- new GuiItemRecipe("Item Usages", new ArrayList<>(usages), this));
+ new GuiItemRecipe("Item Usages", usages.stream().filter(NeuRecipe::isAvailable).collect(Collectors.toList()), this));
return true;
}
@@ -964,7 +965,7 @@ public class NEUManager {
Set<NeuRecipe> recipes = recipesMap.get(internalName);
if (recipes.isEmpty()) return false;
Minecraft.getMinecraft().displayGuiScreen(
- new GuiItemRecipe(text != null ? text : "Item Recipe", new ArrayList<>(recipes), this));
+ new GuiItemRecipe(text != null ? text : "Item Recipe", recipes.stream().filter(NeuRecipe::isAvailable).collect(Collectors.toList()), this));
return true;
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
index d3fd7e0c..50662a80 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/commands/Commands.java
@@ -14,13 +14,13 @@ import io.github.moulberry.notenoughupdates.cosmetics.GuiCosmetics;
import io.github.moulberry.notenoughupdates.dungeons.DungeonWin;
import io.github.moulberry.notenoughupdates.dungeons.GuiDungeonMapEditor;
import io.github.moulberry.notenoughupdates.gamemodes.GuiGamemodes;
-import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes;
-import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent;
-import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.SpecialBlockZone;
import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls;
import io.github.moulberry.notenoughupdates.miscfeatures.FancyPortals;
import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper;
import io.github.moulberry.notenoughupdates.miscfeatures.NullzeeSphere;
+import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.CustomBiomes;
+import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent;
+import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.SpecialBlockZone;
import io.github.moulberry.notenoughupdates.miscgui.*;
import io.github.moulberry.notenoughupdates.miscgui.tutorials.NeuTutorial;
import io.github.moulberry.notenoughupdates.options.NEUConfig;
@@ -745,6 +745,11 @@ public class Commands {
DupePOC.doDupe(args[0]);
return;
}*/
+ if (args.length >= 1 && args[0].equalsIgnoreCase("profileinfo")) {
+ String currentProfile = SBInfo.getInstance().currentProfile;
+ SBInfo.Gamemode gamemode = SBInfo.getInstance().getGamemodeForProfile(currentProfile);
+ sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + "You are on Profile " + currentProfile + " with the mode " + gamemode));
+ }
if (args.length >= 1 && args[0].equalsIgnoreCase("pricetest")) {
if (args.length == 1) {
NotEnoughUpdates.INSTANCE.manager.auctionManager.updateBazaar();
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/NeuRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/NeuRecipe.java
index f0363bc8..99b05d28 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/NeuRecipe.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/NeuRecipe.java
@@ -45,4 +45,8 @@ public interface NeuRecipe {
default boolean shouldUseForCraftCost() {
return true;
}
+
+ default boolean isAvailable() {
+ return true;
+ }
}
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java b/src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java
index bd3f5be8..761ca181 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/recipes/VillagerTradeRecipe.java
@@ -5,6 +5,7 @@ import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.miscgui.GuiItemRecipe;
+import io.github.moulberry.notenoughupdates.util.SBInfo;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.AbstractClientPlayer;
@@ -93,6 +94,11 @@ public class VillagerTradeRecipe implements NeuRecipe {
}
@Override
+ public boolean isAvailable() {
+ return SBInfo.getInstance().getCurrentMode() == SBInfo.Gamemode.STRANDED;
+ }
+
+ @Override
public void drawExtraInfo(GuiItemRecipe gui, int mouseX, int mouseY) {
if (hasVariableCost()) {
FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java
index 6dcd284e..7b5a29a9 100644
--- a/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java
+++ b/src/main/java/io/github/moulberry/notenoughupdates/util/SBInfo.java
@@ -1,13 +1,19 @@
package io.github.moulberry.notenoughupdates.util;
+import com.google.common.reflect.TypeToken;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.miscfeatures.customblockzones.LocationChangeEvent;
import io.github.moulberry.notenoughupdates.overlays.SlayerOverlay;
import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiChest;
import net.minecraft.client.network.NetworkPlayerInfo;
+import net.minecraft.init.Blocks;
import net.minecraft.inventory.ContainerChest;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
import net.minecraft.scoreboard.Score;
import net.minecraft.scoreboard.ScoreObjective;
import net.minecraft.scoreboard.ScorePlayerTeam;
@@ -19,13 +25,16 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+import net.minecraftforge.fml.common.gameevent.TickEvent;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -61,6 +70,31 @@ public class SBInfo {
public boolean isInDungeon = false;
public boolean hasNewTab = false;
+
+ public enum Gamemode {
+ NORMAL("", ""), IRONMAN("Ironman", "♲"), STRANDED("Stranded", "☀");
+
+ private final String name;
+ private final String emoji;
+
+ Gamemode(String name, String emoji) {
+ this.name = name;
+ this.emoji = emoji;
+ }
+
+ public static Gamemode find(String type) {
+ for (Gamemode gamemode : values()) {
+ if (type.contains(gamemode.name))
+ return gamemode;
+ }
+ return null;
+ }
+ }
+
+
+ private Map<String, Gamemode> gamemodes = new HashMap<>();
+ private boolean areGamemodesLoaded = false;
+ private int tickCount = 0;
public String currentProfile = null;
@SubscribeEvent
@@ -77,6 +111,74 @@ public class SBInfo {
}
@SubscribeEvent
+ public void onGuiTick(TickEvent event) {
+ if (tickCount++ % 10 != 0) return;
+ GuiScreen currentScreen = Minecraft.getMinecraft().currentScreen;
+ if (currentScreen instanceof GuiChest) {
+ ContainerChest container = (ContainerChest) ((GuiChest) currentScreen).inventorySlots;
+ if ("Profile Management".equals(container.getLowerChestInventory().getDisplayName().getUnformattedText())) {
+ updateProfileInformation(container);
+ }
+ }
+ }
+
+ private static final Pattern PROFILE_PATTERN = Pattern.compile("(?<type>(♲ Ironman)|(☀ Stranded)|()) *Profile: (?<name>[^ ]+)");
+
+ private void updateProfileInformation(ContainerChest container) {
+ for (int i = 11; i < 16; i = -~i) {
+ Slot slot = container.getSlot(i);
+ if (slot == null || !slot.getHasStack()) continue;
+ ItemStack item = slot.getStack();
+ if (item == null || item.getItem() == Item.getItemFromBlock(Blocks.bedrock)) continue;
+ String displayName = Utils.cleanColour(item.getDisplayName());
+ Matcher matcher = PROFILE_PATTERN.matcher(displayName);
+ if (!matcher.matches()) continue;
+ String type = matcher.group("type");
+ String name = matcher.group("name");
+ Gamemode gamemode = Gamemode.find(type);
+ gamemodes.put(name, gamemode);
+ }
+ areGamemodesLoaded = true;
+ saveGameModes();
+ }
+
+ private Path getProfilesFile() {
+ return new File(NotEnoughUpdates.INSTANCE.manager.configLocation, "profiles.json").toPath();
+ }
+
+ public Map<String, Gamemode> getAllGamemodes() {
+ if (!areGamemodesLoaded)
+ loadGameModes();
+ return gamemodes;
+ }
+
+ public void saveGameModes() {
+ try {
+ Files.write(getProfilesFile(), NotEnoughUpdates.INSTANCE.manager.gson.toJson(gamemodes).getBytes(StandardCharsets.UTF_8));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Gamemode getGamemodeForProfile(String profiles) {
+ return getAllGamemodes().get(profiles);
+ }
+
+ public Gamemode getCurrentMode() {
+ return getGamemodeForProfile(currentProfile);
+ }
+
+ public void loadGameModes() {
+ try {
+ gamemodes = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(Files.newBufferedReader(getProfilesFile()), new TypeToken<Map<String, Gamemode>>() {
+ }.getType());
+ areGamemodesLoaded = true;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
lastLocRaw = -1;
locraw = null;