-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
common/src/main/java/dev/dubhe/anvilcraft/data/recipe/anvil/AnvilRecipeMap.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package dev.dubhe.anvilcraft.data.recipe.anvil; | ||
|
||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.crafting.Recipe; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class AnvilRecipeMap extends LinkedHashMap<ResourceLocation, Recipe<?>> { | ||
/** | ||
* 排序 | ||
*/ | ||
public void sort() { | ||
List<Map.Entry<ResourceLocation, Recipe<?>>> entryList = new ArrayList<>(); | ||
this.entrySet().forEach(entryList::add); | ||
this.clear(); | ||
entryList.sort(this::compare); | ||
entryList.forEach(entry -> this.put(entry.getKey(), entry.getValue())); | ||
} | ||
|
||
/** | ||
* @return 不可变 Map | ||
*/ | ||
public Map<ResourceLocation, Recipe<?>> unmodifiable() { | ||
return Collections.unmodifiableMap(this); | ||
} | ||
|
||
private int compare( | ||
@NotNull Map.Entry<ResourceLocation, Recipe<?>> entry1, | ||
@NotNull Map.Entry<ResourceLocation, Recipe<?>> entry2 | ||
) { | ||
if (!(entry1.getValue() instanceof AnvilRecipe value1 && entry2.getValue() instanceof AnvilRecipe value2)) { | ||
return 0; | ||
} | ||
int size1 = value1.getOutcomes().size(); | ||
int size2 = value2.getOutcomes().size(); | ||
if (size1 != size2) return size1 - size2; | ||
size1 = value1.getPredicates().size(); | ||
size2 = value2.getPredicates().size(); | ||
return size1 - size2; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
"anvilcraft:heater" | ||
], | ||
"state": { | ||
"lit": "true" | ||
"overload": "false" | ||
} | ||
}, | ||
"offset": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
"anvilcraft:heater" | ||
], | ||
"state": { | ||
"lit": "true" | ||
"overload": "false" | ||
} | ||
}, | ||
"offset": [ | ||
|