Skip to content

Commit

Permalink
Ore Dictionary Helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
IntegerLimit committed Feb 17, 2024
1 parent 1405aa1 commit 049dcb7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/groovy-tests/oreDictTests.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Note that just like groovy's default, removing Ore Dictionaries that apply to all metas of a item
// is quite buggy.

// Get all Ore Dicts of a Stack (Pink Wool)
println(item('minecraft:wool', 6).getAllOreDicts())

// Remove all Ore Dicts of a Stack (Lapis Block)
item('minecraft:lapis_block').removeAllOreDicts()

// Remove all Ore Dicts of a Stack (Gray Wool)
// The 'wool' oreDict is only sometimes removed, because it applies to all wool items.
item('minecraft:wool', 7).removeAllOreDicts()
34 changes: 34 additions & 0 deletions src/main/java/com/nomiceu/nomilabs/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.nomiceu.nomilabs.mixin;

import com.cleanroommc.groovyscript.api.GroovyBlacklist;
import com.cleanroommc.groovyscript.compat.vanilla.VanillaModule;
import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient;
import com.nomiceu.nomilabs.config.LabsConfig;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
* This mixin makes it so that the repair cost returned from a given itemstack is always 0.
*/
Expand All @@ -17,4 +26,29 @@ public void getRepairCost(CallbackInfoReturnable<Integer> cir) {
if (LabsConfig.advanced.disableXpScaling)
cir.setReturnValue(0);
}

@Unique
@SuppressWarnings("unused")
public List<OreDictIngredient> getAllOreDicts() {
return getOreDictNames().stream()
.map(OreDictIngredient::new)
.collect(Collectors.toList());
}

@Unique
@GroovyBlacklist
private List<String> getOreDictNames() {
var stack = (ItemStack) (Object) this;
var ids = OreDictionary.getOreIDs(stack);
return Arrays.stream(ids)
.mapToObj(OreDictionary::getOreName)
.collect(Collectors.toList());
}

@Unique
@SuppressWarnings("unused")
public void removeAllOreDicts() {
var stack = (ItemStack) (Object) this;
getOreDictNames().forEach((name) -> VanillaModule.oreDict.remove(name, stack));
}
}

0 comments on commit 049dcb7

Please sign in to comment.