forked from reo-ar/InvTweaksRenewed
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'forge-1.20.1' of github.com:JDKDigital/InvTweaksRefoxed…
… into neoforge-1.20.6 # Conflicts: # build.gradle # gradle.properties # src/main/java/invtweaks/config/InvTweaksConfig.java # src/main/java/invtweaks/events/ClientEvents.java # src/main/java/invtweaks/events/ServerEvents.java # src/main/java/invtweaks/network/PacketSortInv.java # src/main/java/invtweaks/network/PacketUpdateConfig.java # src/main/java/invtweaks/util/Sorting.java # src/main/resources/META-INF/accesstransformer.cfg # src/main/resources/META-INF/mods.toml
- Loading branch information
Showing
27 changed files
with
647 additions
and
606 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
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
Binary file not shown.
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
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
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,90 @@ | ||
package invtweaks.config; | ||
|
||
import com.electronwill.nightconfig.core.CommentedConfig; | ||
import invtweaks.InvTweaksMod; | ||
import net.minecraft.ResourceLocationException; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.tags.TagKey; | ||
import net.minecraft.world.item.BlockItem; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.block.Block; | ||
|
||
import java.util.*; | ||
import java.util.function.Predicate; | ||
import java.util.stream.IntStream; | ||
|
||
public class Category { | ||
private final List<String> spec; | ||
private final List<List<Predicate<ItemStack>>> compiledSpec = new ArrayList<>(); | ||
|
||
public Category(List<String> spec) { | ||
this.spec = spec; | ||
for (String subspec : spec) { | ||
List<Predicate<ItemStack>> compiledSubspec = new ArrayList<>(); | ||
for (String clause : subspec.split("\\s*;\\s*")) { | ||
compileClause(clause).ifPresent(compiledSubspec::add); | ||
} | ||
compiledSpec.add(compiledSubspec); | ||
} | ||
} | ||
|
||
public Category(String... spec) { | ||
this(Arrays.asList(spec)); | ||
} | ||
|
||
private static Optional<Predicate<ItemStack>> compileClause(String clause) { | ||
if (clause.startsWith("!")) { | ||
return compileClause(clause.substring(1)).map(Predicate::negate); | ||
} | ||
|
||
String[] parts = clause.split(":", 2); | ||
if (parts[0].equals("/tag")) { | ||
TagKey<Item> itemKey = TagKey.create(BuiltInRegistries.ITEM.key(), new ResourceLocation(parts[1])); | ||
TagKey<Block> blockKey = TagKey.create(BuiltInRegistries.BLOCK.key(), new ResourceLocation(parts[1])); | ||
|
||
return Optional.of(stack -> stack.is(itemKey) || ( | ||
stack.getItem() instanceof BlockItem blockItem | ||
&& blockItem.getBlock().defaultBlockState().is(blockKey)) | ||
); | ||
} else if (parts[0].equals("/instanceof") || parts[0].equals("/class")) { // use this for e.g. pickaxes | ||
try { | ||
Class<?> clazz = Class.forName(parts[1]); | ||
if (parts[0].equals("/instanceof")) { | ||
return Optional.of(st -> clazz.isInstance(st.getItem())); | ||
} else { | ||
return Optional.of(st -> st.getItem().getClass().equals(clazz)); | ||
} | ||
} catch (ClassNotFoundException e) { | ||
InvTweaksMod.LOGGER.warn("Class not found! Ignoring clause"); | ||
return Optional.empty(); | ||
} | ||
} else if (parts[0].equals("/isFood")) { | ||
return Optional.of(stack -> stack.getFoodProperties(null) != null); | ||
} else { // default to standard item checking | ||
try { | ||
return Optional.of( | ||
st -> Objects.equals(BuiltInRegistries.ITEM.getKey(st.getItem()), new ResourceLocation(clause))); | ||
} catch (ResourceLocationException e) { | ||
InvTweaksMod.LOGGER.warn("Invalid item resource location found."); | ||
return Optional.empty(); | ||
} | ||
} | ||
} | ||
|
||
// returns an index for sorting within a category | ||
public int checkStack(ItemStack stack) { | ||
return IntStream.range(0, compiledSpec.size()) | ||
.filter(idx -> compiledSpec.get(idx).stream().allMatch(pr -> pr.test(stack))) | ||
.findFirst() | ||
.orElse(-1); | ||
} | ||
|
||
public CommentedConfig toConfig(String catName) { | ||
CommentedConfig result = CommentedConfig.inMemory(); | ||
result.set("name", catName); | ||
result.set("spec", spec); | ||
return result; | ||
} | ||
} |
Oops, something went wrong.