mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-03-22 11:26:58 +00:00
Allow undying items using a sponge
It's much less aggressive than dunking it in a cauldron, so won't damage any of your precious electronics. I had this idea back in 2017 (dan200/ComputerCraft#230). Can't believe it took me almost 6 years to implement.
This commit is contained in:
parent
3075d3cea8
commit
81dad421d5
@ -65,6 +65,7 @@ class RecipeProvider extends net.minecraft.data.recipes.RecipeProvider {
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.PRINTOUT.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.DISK.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.DYEABLE_ITEM.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.DYEABLE_ITEM_CLEAR.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.TURTLE_UPGRADE.get());
|
||||
addSpecial(add, ModRegistry.RecipeSerializers.POCKET_COMPUTER_UPGRADE.get());
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import dan200.computercraft.shared.command.arguments.ComputerArgumentType;
|
||||
import dan200.computercraft.shared.command.arguments.ComputersArgumentType;
|
||||
import dan200.computercraft.shared.command.arguments.RepeatArgumentType;
|
||||
import dan200.computercraft.shared.command.arguments.TrackingFieldArgumentType;
|
||||
import dan200.computercraft.shared.common.ClearColourRecipe;
|
||||
import dan200.computercraft.shared.common.ColourableRecipe;
|
||||
import dan200.computercraft.shared.common.DefaultBundledRedstoneProvider;
|
||||
import dan200.computercraft.shared.common.HeldItemMenu;
|
||||
@ -351,6 +352,7 @@ public final class ModRegistry {
|
||||
}
|
||||
|
||||
public static final RegistryEntry<SimpleCraftingRecipeSerializer<ColourableRecipe>> DYEABLE_ITEM = simple("colour", ColourableRecipe::new);
|
||||
public static final RegistryEntry<SimpleCraftingRecipeSerializer<ClearColourRecipe>> DYEABLE_ITEM_CLEAR = simple("clear_colour", ClearColourRecipe::new);
|
||||
public static final RegistryEntry<TurtleRecipe.Serializer> TURTLE = REGISTRY.register("turtle", TurtleRecipe.Serializer::new);
|
||||
public static final RegistryEntry<SimpleCraftingRecipeSerializer<TurtleUpgradeRecipe>> TURTLE_UPGRADE = simple("turtle_upgrade", TurtleUpgradeRecipe::new);
|
||||
public static final RegistryEntry<SimpleCraftingRecipeSerializer<PocketComputerUpgradeRecipe>> POCKET_COMPUTER_UPGRADE = simple("pocket_computer_upgrade", PocketComputerUpgradeRecipe::new);
|
||||
|
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* This file is part of ComputerCraft - http://www.computercraft.info
|
||||
* Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission.
|
||||
* Send enquiries to dratcliffe@gmail.com
|
||||
*/
|
||||
package dan200.computercraft.shared.common;
|
||||
|
||||
import dan200.computercraft.shared.ModRegistry;
|
||||
import net.minecraft.core.NonNullList;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.CraftingBookCategory;
|
||||
import net.minecraft.world.item.crafting.CustomRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
/**
|
||||
* Craft a wet sponge with a {@linkplain IColouredItem dyable item} to remove its dye.
|
||||
*/
|
||||
public final class ClearColourRecipe extends CustomRecipe {
|
||||
public ClearColourRecipe(ResourceLocation id, CraftingBookCategory category) {
|
||||
super(id, category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CraftingContainer inv, Level world) {
|
||||
var hasColourable = false;
|
||||
var hasSponge = false;
|
||||
for (var i = 0; i < inv.getContainerSize(); i++) {
|
||||
var stack = inv.getItem(i);
|
||||
if (stack.isEmpty()) continue;
|
||||
|
||||
if (stack.getItem() instanceof IColouredItem colourable) {
|
||||
if (hasColourable) return false;
|
||||
if (colourable.getColour(stack) == -1) return false;
|
||||
hasColourable = true;
|
||||
} else if (stack.getItem() == Items.WET_SPONGE) {
|
||||
if (hasSponge) return false;
|
||||
hasSponge = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return hasColourable && hasSponge;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack assemble(CraftingContainer inv) {
|
||||
var colourable = ItemStack.EMPTY;
|
||||
|
||||
for (var i = 0; i < inv.getContainerSize(); i++) {
|
||||
var stack = inv.getItem(i);
|
||||
if (stack.getItem() instanceof IColouredItem) colourable = stack;
|
||||
}
|
||||
|
||||
if (colourable.isEmpty()) return ItemStack.EMPTY;
|
||||
|
||||
var stack = ((IColouredItem) colourable.getItem()).withColour(colourable, -1);
|
||||
stack.setCount(1);
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NonNullList<ItemStack> getRemainingItems(CraftingContainer container) {
|
||||
var remaining = NonNullList.withSize(container.getContainerSize(), ItemStack.EMPTY);
|
||||
for (var i = 0; i < remaining.size(); i++) {
|
||||
if (container.getItem(i).getItem() == Items.WET_SPONGE) remaining.set(i, new ItemStack(Items.WET_SPONGE));
|
||||
}
|
||||
return remaining;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCraftInDimensions(int x, int y) {
|
||||
return x * y >= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<ClearColourRecipe> getSerializer() {
|
||||
return ModRegistry.RecipeSerializers.DYEABLE_ITEM_CLEAR.get();
|
||||
}
|
||||
}
|
@ -74,7 +74,7 @@ public final class ColourableRecipe extends CustomRecipe {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
public RecipeSerializer<ColourableRecipe> getSerializer() {
|
||||
return ModRegistry.RecipeSerializers.DYEABLE_ITEM.get();
|
||||
}
|
||||
}
|
||||
|
1
projects/fabric/src/generated/resources/data/computercraft/recipes/clear_colour.json
generated
Normal file
1
projects/fabric/src/generated/resources/data/computercraft/recipes/clear_colour.json
generated
Normal file
@ -0,0 +1 @@
|
||||
{"type": "computercraft:clear_colour", "category": "misc"}
|
1
projects/forge/src/generated/resources/data/computercraft/recipes/clear_colour.json
generated
Normal file
1
projects/forge/src/generated/resources/data/computercraft/recipes/clear_colour.json
generated
Normal file
@ -0,0 +1 @@
|
||||
{"type": "computercraft:clear_colour", "category": "misc"}
|
Loading…
x
Reference in New Issue
Block a user