aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/util
diff options
context:
space:
mode:
authorJakub <53441451+kuba6000@users.noreply.github.com>2022-07-27 04:39:06 +0200
committerGitHub <noreply@github.com>2022-07-27 09:39:06 +0700
commitb3c3b9c5d7d0f40404f702b849d46f348cd78a9c (patch)
tree76fa9babd038565663f70f02395bbb3151e37a5a /src/main/java/gregtech/api/util
parent8c2089b5e3d1591d4c3904494414ea26815079e8 (diff)
downloadGT5-Unofficial-b3c3b9c5d7d0f40404f702b849d46f348cd78a9c.tar.gz
GT5-Unofficial-b3c3b9c5d7d0f40404f702b849d46f348cd78a9c.tar.bz2
GT5-Unofficial-b3c3b9c5d7d0f40404f702b849d46f348cd78a9c.zip
Move Industrial Apiary to gregtech (#1107)
* Industrial Apiary * Make Forestry not required. * Add support for gendustry upgrades and lower energy demand * Add item validation to input slots and fix battery + special slots * Automation upgrade support and bug fixes * Better canWork check and flower detection * GUI work * Better detection of modifier update * Add button to cancel process * Add textures * Tooltip changes * Add convert crafting * Make top and sides glow * Bug fix * New textures * Add bee effects * Make all tooltips translatable * Implement GT Apiary Upgrades * Prevent inserting too many upgrades * Just require gendustry instead of checking it everywhere * Add blacklist (bug fix) and use hashsets instead of arrays * Cache beemember to do effects * Make blacklist automatic * Add acceleration upgrades for all tiers (LV -> UV) * Lock the machine to maxspeed by default * Correct required energy in info tooltip * Use isUpgrade method instead of manually checking * Lower amperage to 4 * Save locked speed to nbt
Diffstat (limited to 'src/main/java/gregtech/api/util')
-rw-r--r--src/main/java/gregtech/api/util/GT_ApiaryUpgrade.java108
-rw-r--r--src/main/java/gregtech/api/util/GT_TooltipDataCache.java16
2 files changed, 116 insertions, 8 deletions
diff --git a/src/main/java/gregtech/api/util/GT_ApiaryUpgrade.java b/src/main/java/gregtech/api/util/GT_ApiaryUpgrade.java
new file mode 100644
index 0000000000..4c60e6f8bc
--- /dev/null
+++ b/src/main/java/gregtech/api/util/GT_ApiaryUpgrade.java
@@ -0,0 +1,108 @@
+package gregtech.api.util;
+
+import cpw.mods.fml.common.Loader;
+import gregtech.api.enums.OrePrefixes;
+import gregtech.common.items.GT_MetaGenerated_Item_03;
+import net.bdew.gendustry.api.ApiaryModifiers;
+import net.bdew.gendustry.api.items.IApiaryUpgrade;
+import net.minecraft.item.ItemStack;
+
+import java.util.*;
+import java.util.function.Consumer;
+
+public enum GT_ApiaryUpgrade {
+ speed1(UNIQUE_INDEX.SPEED_UPGRADE, 32200, 1, 1),
+ speed2(UNIQUE_INDEX.SPEED_UPGRADE, 32201, 1, 2),
+ speed3(UNIQUE_INDEX.SPEED_UPGRADE, 32202, 1, 3),
+ speed4(UNIQUE_INDEX.SPEED_UPGRADE, 32203, 1, 4),
+ speed5(UNIQUE_INDEX.SPEED_UPGRADE, 32204, 1, 5),
+ speed6(UNIQUE_INDEX.SPEED_UPGRADE, 32205, 1, 6),
+ speed7(UNIQUE_INDEX.SPEED_UPGRADE, 32206, 1, 7),
+ speed8(UNIQUE_INDEX.SPEED_UPGRADE, 32207, 1, 8),
+ ;
+
+ private enum UNIQUE_INDEX{
+ SPEED_UPGRADE,
+ ;
+ void apply(Consumer<GT_ApiaryUpgrade> fn){
+ UNIQUE_UPGRADE_LIST.get(this).forEach(fn);
+ }
+ }
+
+ private static final EnumMap<UNIQUE_INDEX, ArrayList<GT_ApiaryUpgrade>> UNIQUE_UPGRADE_LIST = new EnumMap<>(UNIQUE_INDEX.class);
+
+ private int meta = 0;
+ private int maxnumber = 1;
+ private int maxspeedmodifier = 0; // formula: maxspeed = modifier
+
+ private final GT_Utility.ItemId id;
+ private final UNIQUE_INDEX unique_index;
+
+ private final HashMap<GT_Utility.ItemId, ItemStack> additionalGendustryUpgrades = new HashMap<>();
+ private final HashSet<GT_Utility.ItemId> blacklistedUpgrades = new HashSet<>(); // additionalGendustryUpgrades are blacklisted by default
+
+ GT_ApiaryUpgrade(UNIQUE_INDEX unique_index, int meta, int maxnumber, int maxspeedmodifier){
+ this.unique_index = unique_index;
+ this.meta = meta;
+ this.maxnumber = maxnumber;
+ this.maxspeedmodifier = maxspeedmodifier;
+ this.id = GT_Utility.ItemId.createNoCopy(get(1));
+ }
+
+ private void setup_static_variables(){
+ quickLookup.put(this.meta, this);
+ ArrayList<GT_ApiaryUpgrade> un = UNIQUE_UPGRADE_LIST.get(this.unique_index);
+ if(un != null)
+ un.forEach((u) -> { u.blacklistedUpgrades.add(this.id); this.blacklistedUpgrades.add(u.id); });
+ else {
+ un = new ArrayList<>(1);
+ UNIQUE_UPGRADE_LIST.put(this.unique_index, un);
+ }
+ un.add(this);
+ }
+
+ public static GT_ApiaryUpgrade getUpgrade(ItemStack s){
+ if(s == null)
+ return null;
+ if(!isUpgrade(s))
+ return null;
+ return quickLookup.get(s.getItemDamage());
+ }
+
+ public boolean isAllowedToWorkWith(ItemStack s){
+ GT_Utility.ItemId id = GT_Utility.ItemId.createNoCopy(s);
+ return !additionalGendustryUpgrades.containsKey(id) && !blacklistedUpgrades.contains(id);
+ }
+
+ public int getMaxNumber(){
+ return maxnumber;
+ }
+
+ public void applyModifiers(ApiaryModifiers mods, ItemStack s){
+ additionalGendustryUpgrades.forEach((k, u) -> ((IApiaryUpgrade)u.getItem()).applyModifiers(mods, u));
+ }
+
+ public ItemStack get(int count){
+ return new ItemStack(GT_MetaGenerated_Item_03.INSTANCE, count, meta);
+ }
+
+ public static boolean isUpgrade(ItemStack s){
+ return OrePrefixes.apiaryUpgrade.contains(s);
+ }
+
+ public int applyMaxSpeedModifier(int maxspeed){
+ return Math.max(maxspeed, maxspeedmodifier);
+ }
+
+ private static final HashMap<Integer, GT_ApiaryUpgrade> quickLookup = new HashMap<>();
+
+ static{
+ EnumSet.allOf(GT_ApiaryUpgrade.class).forEach(GT_ApiaryUpgrade::setup_static_variables);
+
+ if(Loader.isModLoaded("gendustry")) {
+ ItemStack s = GT_ModHandler.getModItem("gendustry", "ApiaryUpgrade", 8L, 0);
+ GT_Utility.ItemId a = GT_Utility.ItemId.createNoCopy(s);
+ UNIQUE_INDEX.SPEED_UPGRADE.apply((u) -> u.additionalGendustryUpgrades.put(a, s));
+ }
+ }
+}
diff --git a/src/main/java/gregtech/api/util/GT_TooltipDataCache.java b/src/main/java/gregtech/api/util/GT_TooltipDataCache.java
index 7844bb04fd..4309958b82 100644
--- a/src/main/java/gregtech/api/util/GT_TooltipDataCache.java
+++ b/src/main/java/gregtech/api/util/GT_TooltipDataCache.java
@@ -23,8 +23,8 @@ public class GT_TooltipDataCache {
/**
* Returns tooltip data respecting the user's configured verbosity levels, applying any formatting arguments.
- *
- * @param key the key to lookup
+ *
+ * @param key the key to lookup
* @param args arguments for string formatting (prefer using positional arguments)
* @return The tooltip data the user asked for
*/
@@ -39,12 +39,12 @@ public class GT_TooltipDataCache {
/**
* Builds tooltip data respecting the user's configured verbosity levels, applying any formatting arguments.
- *
- * @param key the key to lookup
+ *
+ * @param key the key to lookup
* @param args arguments for string formatting (prefer using positional arguments)
* @return The tooltip data the user asked for
*/
- private TooltipData getUncachedTooltipData(String key, Object... args) {
+ public TooltipData getUncachedTooltipData(String key, Object... args) {
List<String> lines = getAllLines(key, args);
int normalLines = lines.size();
if (Math.max(GT_Mod.gregtechproxy.mTooltipVerbosity, GT_Mod.gregtechproxy.mTooltipShiftVerbosity) >= 3) {
@@ -60,8 +60,8 @@ public class GT_TooltipDataCache {
/**
* Gets all the lines for the given key and every other subsequent consecutive key with a .n suffix, n in {1,2,3...}
- *
- * @param key the key to lookup
+ *
+ * @param key the key to lookup
* @param args arguments for string formatting (prefer using positional arguments)
* @return The lines for the key and all of it's subkeys
*/
@@ -78,7 +78,7 @@ public class GT_TooltipDataCache {
/**
* Determines how many lines from a tooltip to include from the full line list to respect a given verbosity level.
- *
+ *
* @param tooltipVerbosity the verbosity level we're applying
* @param defaultIndex return if tooltipVerbosity is 2
* @param maxIndex return if tooltipVerbosity is greater than 2