Skip to content

Commit ef74656

Browse files
committed
修复一些小错误
1 parent e93704c commit ef74656

File tree

4 files changed

+55
-54
lines changed

4 files changed

+55
-54
lines changed

src/main/java/github/kasuminova/novaeng/client/gui/widget/ProgressBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ protected Optional<TextureProperties> findProgressForegroundTex(final double per
104104
if (idx >= progressTextures.size()) {
105105
return Optional.of(progressTextures.get(progressTextures.size() - 1));
106106
} else {
107-
return Optional.of(progressTextures.get(idx));
107+
return Optional.of(progressTextures.get(Math.max(idx, 0)));
108108
}
109109
}
110110

src/main/java/github/kasuminova/novaeng/client/util/ExJEI.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package github.kasuminova.novaeng.client.util;
22

3-
import com.github.bsideup.jabel.Desugar;
43
import crafttweaker.api.item.IItemStack;
54
import crafttweaker.api.minecraft.CraftTweakerMC;
65
import github.kasuminova.novaeng.NovaEngineeringCore;
6+
import github.kasuminova.novaeng.common.util.SimpleItem;
77
import ic2.core.ref.BlockName;
88
import ic2.core.ref.ItemName;
99
import ic2.core.ref.TeBlock;
@@ -13,9 +13,7 @@
1313
import ink.ikx.rt.impl.mods.jei.impl.core.MCJeiPanel;
1414
import ink.ikx.rt.impl.mods.jei.impl.core.MCJeiRecipe;
1515
import net.minecraft.client.resources.I18n;
16-
import net.minecraft.item.Item;
1716
import net.minecraft.item.ItemStack;
18-
import net.minecraft.nbt.NBTTagCompound;
1917
import net.minecraftforge.fml.relauncher.Side;
2018
import net.minecraftforge.fml.relauncher.SideOnly;
2119

@@ -69,27 +67,4 @@ public static void jeiRecipeRegister() {
6967

7068
uniqueKeys.clear();
7169
}
72-
73-
@Desugar
74-
private record SimpleItem(Item item, int meta, NBTTagCompound nbt) {
75-
76-
public static SimpleItem getInstance(ItemStack stack) {
77-
return new SimpleItem(stack.getItem(), stack.getMetadata(), stack.getTagCompound());
78-
}
79-
80-
@Override
81-
public boolean equals(Object o) {
82-
if (o == null || getClass() != o.getClass()) return false;
83-
SimpleItem that = (SimpleItem) o;
84-
return meta == that.meta && Objects.equals(item, that.item) && Objects.equals(nbt, that.nbt);
85-
}
86-
87-
@Override
88-
public int hashCode() {
89-
int result = item.hashCode();
90-
result = 31 * result + meta;
91-
result = 31 * result + (nbt != null ? nbt.hashCode() : 0);
92-
return result;
93-
}
94-
}
9570
}

src/main/java/github/kasuminova/novaeng/common/handler/OreHandler.java

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import net.minecraft.block.Block;
88
import net.minecraft.block.state.IBlockState;
99
import net.minecraft.init.Blocks;
10-
import net.minecraft.item.ItemBlock;
1110
import net.minecraft.item.ItemStack;
1211
import net.minecraft.util.ResourceLocation;
1312
import net.minecraftforge.event.world.BlockEvent;
@@ -19,7 +18,6 @@
1918
import stanhebben.zenscript.annotations.ZenMethod;
2019

2120
import 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 {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package github.kasuminova.novaeng.common.util;
2+
3+
4+
import com.github.bsideup.jabel.Desugar;
5+
import net.minecraft.item.Item;
6+
import net.minecraft.item.ItemStack;
7+
import net.minecraft.nbt.NBTTagCompound;
8+
9+
import java.util.Objects;
10+
11+
@Desugar
12+
public record SimpleItem(Item item, int meta, NBTTagCompound nbt) {
13+
14+
public static SimpleItem getInstance(ItemStack stack) {
15+
return new SimpleItem(stack.getItem(), stack.getMetadata(), stack.getTagCompound());
16+
}
17+
18+
@Override
19+
public boolean equals(Object o) {
20+
if (o == null || getClass() != o.getClass()) return false;
21+
SimpleItem that = (SimpleItem) o;
22+
return meta == that.meta && Objects.equals(item, that.item) && Objects.equals(nbt, that.nbt);
23+
}
24+
25+
@Override
26+
public int hashCode() {
27+
int result = item.hashCode();
28+
result = 31 * result + meta;
29+
result = 31 * result + (nbt != null ? nbt.hashCode() : 0);
30+
return result;
31+
}
32+
}

0 commit comments

Comments
 (0)