-
Notifications
You must be signed in to change notification settings - Fork 18
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
1 parent
d9e3887
commit c736530
Showing
8 changed files
with
218 additions
and
0 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
95 changes: 95 additions & 0 deletions
95
src/main/java/com/nomiceu/nomilabs/groovy/NBTClearingRecipe.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,95 @@ | ||
package com.nomiceu.nomilabs.groovy; | ||
|
||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
import net.minecraft.inventory.InventoryCrafting; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.crafting.IRecipe; | ||
import net.minecraft.util.NonNullList; | ||
import net.minecraft.world.World; | ||
import net.minecraftforge.registries.IForgeRegistryEntry; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import com.nomiceu.nomilabs.util.ItemMeta; | ||
import com.nomiceu.nomilabs.util.LabsTranslate; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; | ||
|
||
public class NBTClearingRecipe extends IForgeRegistryEntry.Impl<IRecipe> implements IRecipe { | ||
|
||
// Map of Output to Input | ||
public static final Map<ItemMeta, ItemMeta> NBT_CLEARERS = new Object2ObjectOpenHashMap<>(); | ||
public static final LabsTranslate.Translatable WARNING_TOOLTIP = new LabsTranslate.Translatable( | ||
"tooltip.nomilabs.recipe.clearing"); | ||
public static final LabsTranslate.Translatable CAN_CLEAR_TOOLTIP = new LabsTranslate.Translatable( | ||
"tooltip.nomilabs.item.can_clear"); | ||
|
||
@Nullable | ||
private final Consumer<ItemStack> nbtClearer; | ||
private final ItemStack singleInput; | ||
private final ItemStack exampleOutput; | ||
|
||
public NBTClearingRecipe(ItemStack input, ItemStack exampleOutput, @Nullable Consumer<ItemStack> nbtClearer) { | ||
this.singleInput = input; | ||
this.exampleOutput = exampleOutput; | ||
this.nbtClearer = nbtClearer; | ||
} | ||
|
||
@Override | ||
public boolean matches(@NotNull InventoryCrafting inv, @NotNull World worldIn) { | ||
boolean found = false; | ||
for (int i = 0; i < inv.getSizeInventory(); i++) { | ||
var stack = inv.getStackInSlot(i); | ||
if (stack.isEmpty()) continue; | ||
|
||
if (found || !ItemMeta.compare(inv.getStackInSlot(i), singleInput)) return false; | ||
found = true; | ||
} | ||
return found; | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public ItemStack getCraftingResult(@NotNull InventoryCrafting inv) { | ||
if (nbtClearer == null) return exampleOutput; | ||
|
||
var stack = ItemStack.EMPTY; | ||
for (int i = 0; i < inv.getSizeInventory(); i++) { | ||
stack = inv.getStackInSlot(i); | ||
if (!stack.isEmpty()) break; | ||
} | ||
|
||
if (stack.isEmpty()) return ItemStack.EMPTY; | ||
var display = new ItemStack(exampleOutput.getItem(), stack.getCount(), exampleOutput.getMetadata()); | ||
display.setTagCompound(stack.getTagCompound()); | ||
nbtClearer.accept(display); | ||
return display; | ||
} | ||
|
||
@Override | ||
public boolean canFit(int width, int height) { | ||
return true; | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public ItemStack getRecipeOutput() { | ||
return exampleOutput; | ||
} | ||
|
||
/** | ||
* Makes Buckets be Consumed | ||
*/ | ||
@Override | ||
@NotNull | ||
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) { | ||
NonNullList<ItemStack> ret = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY); | ||
for (int i = 0; i < ret.size(); i++) { | ||
ret.set(i, inv.getStackInSlot(i)); | ||
} | ||
return ret; | ||
} | ||
} |
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