1313import net .minecraft .tileentity .TileEntity ;
1414
1515import java .util .*;
16+
1617public class getItemValues {
1718
19+ public static Map <String , Map <String , Integer >> researchCounts = new HashMap <>();
1820 public static Map <String , ResearchValue > Values = new HashMap <>();
1921
22+ // Creates a truly unique identifier for an item including metadata
23+ private static String getUniqueItemKey (Item item , int meta ) {
24+ return Item .itemRegistry .getNameForObject (item ) + ":" + meta ;
25+ }
26+
27+ private static String getUniqueItemKey (ItemStack stack ) {
28+ return getUniqueItemKey (stack .getItem (), stack .getItemDamage ());
29+ }
30+
2031 public static boolean isBlackListed (String key ) {
2132 String [] keywords = {
2233 "ladder" , "plate" , "rod" , "pipe" ,
@@ -34,7 +45,8 @@ public static boolean isBlackListed(String key) {
3445 "glass" , "bars" , "door" , "sand" ,
3546 "axe" , "tank" , "scaffold" , "corner" ,
3647 "pedestal" , "port" , "carrot" , "tile" ,
37- "flint" , "furnace" };
48+ "flint" , "furnace"
49+ };
3850 for (String keyword : keywords ) {
3951 if (key .toLowerCase ().trim ().contains (keyword )) {
4052 return true ;
@@ -46,12 +58,14 @@ public static boolean isBlackListed(String key) {
4658 public static boolean isResearchItem (String name ) {
4759 return !isBlackListed (name );
4860 }
49- public static ResearchValue getItemValue (Item item ) {
50- System .out .println ("Item is: " + item .getUnlocalizedName ());
51- if (Values .containsKey (item .getUnlocalizedName ().toLowerCase ())) {
61+
62+ public static ResearchValue getItemValue (ItemStack stack ) {
63+ String key = getUniqueItemKey (stack ); // uses damage/meta from stack
64+ System .out .println ("Item is: " + key );
65+ if (Values .containsKey (key )) {
5266 System .out .println ("Found item in map" );
5367 }
54- return Values .getOrDefault (item . getUnlocalizedName (). toLowerCase () , new ResearchValue ());
68+ return Values .getOrDefault (key , new ResearchValue ());
5569 }
5670
5771 public static int getResearchTime (TileEntity te ) {
@@ -78,36 +92,34 @@ public static int getResearchTime(TileEntity te) {
7892 }
7993
8094 private static TileEntityResearchController getCore (TileEntity te ) {
81- TileEntityResearchController core = null ;
8295 if (te instanceof TileEntityT1 ) {
83- if (((TileEntityT1 ) te ).core != null ) {
84- core = ((TileEntityT1 ) te ).core ;
85- }
96+ return ((TileEntityT1 ) te ).core ;
8697 } else if (te instanceof TileEntityT2 ) {
87- if (((TileEntityT2 ) te ).core != null ) {
88- core = ((TileEntityT2 ) te ).core ;
89- }
98+ return ((TileEntityT2 ) te ).core ;
9099 } else if (te instanceof TileEntityT3 ) {
91- if (((TileEntityT3 ) te ).core != null ) {
92- core = ((TileEntityT3 ) te ).core ;
93- }
100+ return ((TileEntityT3 ) te ).core ;
94101 }
95- return core ;
102+ return null ;
96103 }
97104
98105 public static void init () {
99106 for (Object obj : Item .itemRegistry ) {
100-
101107 Item item = (Item ) obj ;
102- String name = item .getUnlocalizedName ().toLowerCase ();
108+ String rawName = item .getUnlocalizedName ().toLowerCase ();
109+ String normalizedName = rawName
110+ .replace ("tile." , "" )
111+ .replace ("item." , "" )
112+ .replace ("_" , " " )
113+ .trim ();
114+
115+ if (!isResearchItem (normalizedName )) continue ;
103116
104- if (!isResearchItem (name )) continue ;
105117 ResearchValue value = new ResearchValue ();
106118 for (Map .Entry <String , ResearchValue > entry : ResearchMap .keywordMap .entrySet ()) {
107119 String keyword = entry .getKey ().toLowerCase ();
108- if (name .contains (keyword )) {
109- System .out .println ("Registered " + name );
110- System .out .println (name + " contains " + keyword );
120+ if (normalizedName .contains (keyword )) {
121+ System .out .println ("Registered " + normalizedName );
122+ System .out .println (normalizedName + " contains " + keyword );
111123 ResearchValue toAdd = entry .getValue ();
112124 for (Map .Entry <PointManager .ResearchType , Integer > point : toAdd .getAllPoints ().entrySet ()) {
113125 value .addPoints (point .getKey (), point .getValue ());
@@ -116,25 +128,52 @@ public static void init() {
116128 }
117129
118130 if (!value .getAllPoints ().isEmpty ()) {
119- System .out .println ("Added " + item .getUnlocalizedName ());
120- Values .put (item .getUnlocalizedName ().toLowerCase (), value );
131+ String key = getUniqueItemKey (item , 0 ); // Default meta for base item
132+ System .out .println ("Added " + key );
133+ Values .put (key , value );
121134 }
122-
123135 }
124136 System .out .println ("VALUES OF RESEARCHMAPIDK: " + Values .keySet ());
125137 }
126138
127- public static void setValues (ResearchValue value , ItemStack stack ) {
128- ItemResearchPoint .setRp (stack , "CHEMICAL" , 0 );
129- System .out .println ("setValues called for: " + stack );
139+ private static int getDiminishedValues (String itemKey , int base , String team ) {
140+ researchCounts .computeIfAbsent (team , t -> new HashMap <>());
141+ int count = researchCounts .get (team ).getOrDefault (itemKey , 0 );
142+ return Math .max (1 , base / (1 + count ));
143+ }
144+
145+ public static void setValues (ResearchValue value , ItemStack outStack , String team , ItemStack sourceStack ) {
146+ if (!outStack .hasTagCompound ()) {
147+ outStack .setTagCompound (new NBTTagCompound ());
148+ }
149+
150+ if (sourceStack == null ) {
151+ System .out .println ("sourceStack is null, cannot apply diminishing correctly" );
152+ return ;
153+ }
154+
155+ String sourceKey = getUniqueItemKey (sourceStack ); // << use this for diminishing
156+ System .out .println ("Got source item key for diminishing: " + sourceKey + " for team: " + team );
157+
158+ ItemResearchPoint .setRp (outStack , "CHEMICAL" , 0 );
159+ System .out .println ("setValues called for: " + outStack );
160+
130161 if (value == null ) {
131162 System .out .println ("value is null!" );
132163 return ;
133164 }
165+
134166 Map <PointManager .ResearchType , Integer > map = value .getAllPoints ();
135167 System .out .println ("Map size: " + map .size ());
168+ researchCounts .computeIfAbsent (team , t -> new HashMap <>());
169+
136170 for (Map .Entry <PointManager .ResearchType , Integer > entry : map .entrySet ()) {
137- stack .getTagCompound ().setInteger (entry .getKey ().toString (), entry .getValue ());
171+ int diminishedValue = getDiminishedValues (sourceKey , entry .getValue (), team );
172+ outStack .getTagCompound ().setInteger (entry .getKey ().toString (), diminishedValue );
138173 }
174+
175+ int current = researchCounts .get (team ).getOrDefault (sourceKey , 0 );
176+ researchCounts .get (team ).put (sourceKey , current + 1 );
177+ System .out .println ("Applied diminishing for source item: " + sourceKey + " for team: " + team );
139178 }
140- }
179+ }
0 commit comments