77import net .minecraft .block .Block ;
88import net .minecraft .block .state .IBlockState ;
99import net .minecraft .init .Blocks ;
10- import net .minecraft .item .ItemBlock ;
1110import net .minecraft .item .ItemStack ;
1211import net .minecraft .util .ResourceLocation ;
1312import net .minecraftforge .event .world .BlockEvent ;
1918import stanhebben .zenscript .annotations .ZenMethod ;
2019
2120import java .util .*;
22- import java .util .concurrent .ConcurrentHashMap ;
2321
2422@ ZenRegister
2523@ ZenClass ("novaeng.hypernet.RawOre" )
@@ -73,13 +71,6 @@ public static void registry() {
7371 var ok = OreKey .getKey (ore );
7472 map .put (ok , rawOre );
7573 mapO .put (ok , ODore );
76-
77- if (ore .getItem () instanceof ItemBlock ik && ik .getBlock () == Blocks .REDSTONE_ORE ) {
78- ok = OreKey .getKey (Blocks .LIT_REDSTONE_ORE .getRegistryName (), ore .getItemDamage ());
79- map .put (ok , rawOre );
80- mapO .put (ok , ODore );
81- }
82-
8374 NovaEngineeringCore .log .info ("registered : {}[{}]" , ok .toString (), rawOreName );
8475 }
8576 }
@@ -97,8 +88,7 @@ public void onHarvestDropsEvent(BlockEvent.HarvestDropsEvent event) {
9788 IBlockState blockState = event .getState ();
9889 Block block = blockState .getBlock ();
9990 int meta = block .getMetaFromState (blockState );
100- ResourceLocation registryName = block .getRegistryName ();
101- final OreKey key = OreKey .getKey (registryName ,meta );
91+ final OreKey key = OreKey .getKey (block ,meta );
10292 if (rawOreMap .containsKey (key )){
10393 List <ItemStack > drops = event .getDrops ();
10494 drops .clear ();
@@ -123,51 +113,55 @@ public void onHarvestDropsEvent(BlockEvent.HarvestDropsEvent event) {
123113 }
124114
125115 private final static class OreKey {
126- private final ResourceLocation rl ;
127- private final int meta ;
116+ private final ItemStack item ;
128117 private String toString ;
129118 private int hash = -1 ;
130119
131- private static final Map <ResourceLocation , Map <Integer , OreKey >> keyPool = new HashMap <>();
120+ private OreKey (ItemStack item ){
121+ this .item = item ;
122+ }
123+
124+ public int getMetadata (){
125+ return item .getMetadata ();
126+ }
132127
133- private OreKey (ResourceLocation Rl ,int Meta ){
134- this .rl = Rl ;
135- this .meta = Meta ;
128+ public ResourceLocation getRl (){
129+ return item .getItem ().getRegistryName ();
136130 }
137131
138132 @ Override
139133 public boolean equals (Object o ) {
140134 if (!(o instanceof OreKey oreKey )) return false ;
141- return meta == oreKey .meta && rl .equals (oreKey .rl );
135+ return this . getMetadata () == oreKey .getMetadata () && Objects .equals (this . getRl (), oreKey .getRl () );
142136 }
143137
144138 @ Override
145139 public int hashCode () {
146140 if (hash == -1 ){
147- hash = Objects .hash (rl , meta );
141+ hash = Objects .hash (this . getRl (), this . getMetadata () );
148142 }
149143 return hash ;
150144 }
151145
152146 @ Override
153147 public String toString (){
154148 if (toString == null ){
155- toString = rl . toString () + ":" + meta ;
149+ toString = this . getRl (). toString () + ":" + this . getMetadata () ;
156150 }
157151 return toString ;
158152 }
159153
160154 public static OreKey getKey (ItemStack itemStack ) {
161- ResourceLocation rl = itemStack .getItem ().getRegistryName ();
162- int meta = itemStack .getItemDamage ();
163- return keyPool .computeIfAbsent (rl , k -> new ConcurrentHashMap <>())
164- .computeIfAbsent (meta , m -> new OreKey (rl , meta ));
155+ return new OreKey (itemStack );
165156 }
166157
167- public static OreKey getKey (ResourceLocation rl , int meta ) {
168- return keyPool .computeIfAbsent (rl , k -> new ConcurrentHashMap <>())
169- .computeIfAbsent (meta , m -> new OreKey (rl , meta ));
158+ private static final OreKey redStone = new OreKey (new ItemStack (Blocks .REDSTONE_ORE ));
159+
160+ public static OreKey getKey (Block block ,int meta ) {
161+ if (block == Blocks .LIT_REDSTONE_ORE )return redStone ;
162+ return new OreKey (new ItemStack (block ,1 ,meta ));
170163 }
164+
171165 }
172166
173167 public static class OreDictHelper {
0 commit comments