添加弹药盒装弹配方
This commit is contained in:
parent
26e2ce51a5
commit
b5b4d117d4
5 changed files with 94 additions and 2 deletions
|
@ -1,2 +1,3 @@
|
||||||
// 1.20.1 2025-02-22T22:55:11.4694739 Recipes
|
// 1.20.1 2025-03-11T20:08:33.5240751 Recipes
|
||||||
|
9775e550332c69f1ee2ac4a09834a35db6f6a2ed data/minecraft/recipes/ammo_box_add_ammo.json
|
||||||
2e1d1bbf32801f3d355c0d3f78ebbb1122cebd4c data/minecraft/recipes/potion_mortar_shell.json
|
2e1d1bbf32801f3d355c0d3f78ebbb1122cebd4c data/minecraft/recipes/potion_mortar_shell.json
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"type": "superbwarfare:ammo_box_add_ammo",
|
||||||
|
"category": "misc"
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import net.minecraft.data.recipes.FinishedRecipe;
|
||||||
import net.minecraft.data.recipes.RecipeProvider;
|
import net.minecraft.data.recipes.RecipeProvider;
|
||||||
import net.minecraft.data.recipes.SpecialRecipeBuilder;
|
import net.minecraft.data.recipes.SpecialRecipeBuilder;
|
||||||
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;
|
import net.minecraftforge.common.crafting.conditions.IConditionBuilder;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@ -16,7 +17,8 @@ public class ModRecipeProvider extends RecipeProvider implements IConditionBuild
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void buildRecipes(Consumer<FinishedRecipe> pWriter) {
|
protected void buildRecipes(@NotNull Consumer<FinishedRecipe> pWriter) {
|
||||||
SpecialRecipeBuilder.special(ModRecipes.POTION_MORTAR_SHELL_SERIALIZER.get()).save(pWriter, "potion_mortar_shell");
|
SpecialRecipeBuilder.special(ModRecipes.POTION_MORTAR_SHELL_SERIALIZER.get()).save(pWriter, "potion_mortar_shell");
|
||||||
|
SpecialRecipeBuilder.special(ModRecipes.AMMO_BOX_ADD_AMMO_SERIALIZER.get()).save(pWriter, "ammo_box_add_ammo");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.atsuishio.superbwarfare.init;
|
package com.atsuishio.superbwarfare.init;
|
||||||
|
|
||||||
import com.atsuishio.superbwarfare.ModUtils;
|
import com.atsuishio.superbwarfare.ModUtils;
|
||||||
|
import com.atsuishio.superbwarfare.recipe.AmmoBoxAddAmmoRecipe;
|
||||||
import com.atsuishio.superbwarfare.recipe.PotionMortarShellRecipe;
|
import com.atsuishio.superbwarfare.recipe.PotionMortarShellRecipe;
|
||||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||||
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
|
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
|
||||||
|
@ -14,4 +15,7 @@ public class ModRecipes {
|
||||||
|
|
||||||
public static final RegistryObject<RecipeSerializer<PotionMortarShellRecipe>> POTION_MORTAR_SHELL_SERIALIZER =
|
public static final RegistryObject<RecipeSerializer<PotionMortarShellRecipe>> POTION_MORTAR_SHELL_SERIALIZER =
|
||||||
RECIPE_SERIALIZERS.register("potion_mortar_shell", () -> new SimpleCraftingRecipeSerializer<>(PotionMortarShellRecipe::new));
|
RECIPE_SERIALIZERS.register("potion_mortar_shell", () -> new SimpleCraftingRecipeSerializer<>(PotionMortarShellRecipe::new));
|
||||||
|
|
||||||
|
public static final RegistryObject<RecipeSerializer<AmmoBoxAddAmmoRecipe>> AMMO_BOX_ADD_AMMO_SERIALIZER =
|
||||||
|
RECIPE_SERIALIZERS.register("ammo_box_add_ammo", () -> new SimpleCraftingRecipeSerializer<>(AmmoBoxAddAmmoRecipe::new));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package com.atsuishio.superbwarfare.recipe;
|
||||||
|
|
||||||
|
import com.atsuishio.superbwarfare.init.ModRecipes;
|
||||||
|
import com.atsuishio.superbwarfare.item.common.ammo.AmmoBox;
|
||||||
|
import com.atsuishio.superbwarfare.item.common.ammo.AmmoSupplierItem;
|
||||||
|
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||||
|
import net.minecraft.core.RegistryAccess;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.inventory.CraftingContainer;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
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;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class AmmoBoxAddAmmoRecipe extends CustomRecipe {
|
||||||
|
|
||||||
|
public AmmoBoxAddAmmoRecipe(ResourceLocation pId, CraftingBookCategory pCategory) {
|
||||||
|
super(pId, pCategory);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(CraftingContainer pContainer, @NotNull Level pLevel) {
|
||||||
|
var hasAmmoBox = false;
|
||||||
|
var hasAmmo = false;
|
||||||
|
|
||||||
|
for (var item : pContainer.getItems()) {
|
||||||
|
if (item.getItem() instanceof AmmoBox) {
|
||||||
|
if (hasAmmoBox) return false;
|
||||||
|
hasAmmoBox = true;
|
||||||
|
} else if (item.getItem() instanceof AmmoSupplierItem) {
|
||||||
|
hasAmmo = true;
|
||||||
|
} else if (!item.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hasAmmoBox && hasAmmo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void addAmmo(HashMap<AmmoType, Integer> map, AmmoType type, int count) {
|
||||||
|
map.put(type, map.getOrDefault(type, 0) + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ItemStack assemble(CraftingContainer pContainer, @NotNull RegistryAccess pRegistryAccess) {
|
||||||
|
var map = new HashMap<AmmoType, Integer>();
|
||||||
|
var ammoBox = ItemStack.EMPTY;
|
||||||
|
|
||||||
|
for (var item : pContainer.getItems()) {
|
||||||
|
if (item.getItem() instanceof AmmoSupplierItem ammoSupplier) {
|
||||||
|
addAmmo(map, ammoSupplier.type, ammoSupplier.ammoToAdd);
|
||||||
|
} else if (item.getItem() instanceof AmmoBox) {
|
||||||
|
ammoBox = item.copy();
|
||||||
|
for (var type : AmmoType.values()) {
|
||||||
|
addAmmo(map, type, type.get(item));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var type : AmmoType.values()) {
|
||||||
|
type.set(ammoBox, map.getOrDefault(type, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ammoBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canCraftInDimensions(int pWidth, int pHeight) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull RecipeSerializer<?> getSerializer() {
|
||||||
|
return ModRecipes.AMMO_BOX_ADD_AMMO_SERIALIZER.get();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue