Add Network Chip Duplicate Recipe
All checks were successful
EnergonRelics/pipeline/head This commit looks good
All checks were successful
EnergonRelics/pipeline/head This commit looks good
This commit is contained in:
parent
10684b4236
commit
c9fae65445
@ -20,6 +20,7 @@ import com.thebrokenrail.energonrelics.block.util.SimpleBlock;
|
||||
import com.thebrokenrail.energonrelics.item.MultimeterItem;
|
||||
import com.thebrokenrail.energonrelics.item.NetworkChipItem;
|
||||
import com.thebrokenrail.energonrelics.potion.CustomPotions;
|
||||
import com.thebrokenrail.energonrelics.recipe.DuplicateNetworkChipRecipe;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
@ -27,6 +28,7 @@ import net.minecraft.block.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.SpecialRecipeSerializer;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.BuiltinRegistries;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
@ -73,6 +75,8 @@ public class EnergonRelics implements ModInitializer {
|
||||
|
||||
public static final LightningRodBlock LIGHTNING_ROD_BLOCK = new LightningRodBlock();
|
||||
|
||||
public static final SpecialRecipeSerializer<DuplicateNetworkChipRecipe> DUPLICATE_NETWORK_CHIP_RECIPE = new SpecialRecipeSerializer<>(DuplicateNetworkChipRecipe::new);
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
NETWORK_CHIP_ITEM = Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "network_chip"), new NetworkChipItem());
|
||||
@ -111,5 +115,7 @@ public class EnergonRelics implements ModInitializer {
|
||||
CustomPotions.register();
|
||||
|
||||
LIGHTNING_ROD_BLOCK.register("lightning_rod");
|
||||
|
||||
Registry.register(Registry.RECIPE_SERIALIZER, new Identifier(NAMESPACE, "duplicate_network_chip"), DUPLICATE_NETWORK_CHIP_RECIPE);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
package com.thebrokenrail.energonrelics.recipe;
|
||||
|
||||
import com.thebrokenrail.energonrelics.EnergonRelics;
|
||||
import net.minecraft.inventory.CraftingInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeSerializer;
|
||||
import net.minecraft.recipe.SpecialCraftingRecipe;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class DuplicateNetworkChipRecipe extends SpecialCraftingRecipe {
|
||||
public DuplicateNetworkChipRecipe(Identifier id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CraftingInventory inv, World world) {
|
||||
boolean foundChip = false;
|
||||
boolean foundCircuit = false;
|
||||
for (int i = 0; i < inv.size(); i++) {
|
||||
ItemStack stack = inv.getStack(i);
|
||||
if (stack.getItem() == EnergonRelics.NETWORK_CHIP_ITEM && !foundChip) {
|
||||
foundChip = true;
|
||||
} else if (stack.getItem() == EnergonRelics.CIRCUIT_BOARD_ITEM && !foundCircuit) {
|
||||
foundCircuit = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return foundChip && foundCircuit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(CraftingInventory inv) {
|
||||
ItemStack out = ItemStack.EMPTY;
|
||||
for (int i = 0; i < inv.size(); i++) {
|
||||
ItemStack stack = inv.getStack(i);
|
||||
if (stack.getItem() == EnergonRelics.NETWORK_CHIP_ITEM) {
|
||||
out = stack.copy();
|
||||
out.setCount(1);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultedList<ItemStack> getRemainingStacks(CraftingInventory inv) {
|
||||
DefaultedList<ItemStack> defaultedList = DefaultedList.ofSize(inv.size(), ItemStack.EMPTY);
|
||||
|
||||
for (int i = 0; i < defaultedList.size(); ++i) {
|
||||
ItemStack stack = inv.getStack(i);
|
||||
if (stack.getItem().hasRecipeRemainder()) {
|
||||
defaultedList.set(i, new ItemStack(stack.getItem().getRecipeRemainder()));
|
||||
} else if (stack.getItem() == EnergonRelics.NETWORK_CHIP_ITEM) {
|
||||
ItemStack newStack = stack.copy();
|
||||
newStack.setCount(1);
|
||||
defaultedList.set(i, newStack);
|
||||
}
|
||||
}
|
||||
|
||||
return defaultedList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fits(int width, int height) {
|
||||
return width >= 2 || height >= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecipeSerializer<?> getSerializer() {
|
||||
return EnergonRelics.DUPLICATE_NETWORK_CHIP_RECIPE;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user