添加弹药盒取弹药配方
This commit is contained in:
parent
2daca17c21
commit
629b71c11b
5 changed files with 115 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
|||
// 1.20.1 2025-03-11T20:08:33.5240751 Recipes
|
||||
// 1.20.1 2025-03-11T20:54:56.3941101 Recipes
|
||||
9775e550332c69f1ee2ac4a09834a35db6f6a2ed data/minecraft/recipes/ammo_box_add_ammo.json
|
||||
b23d5c199168cf868d89722c62042bfa8852b768 data/minecraft/recipes/ammo_box_extract_ammo.json
|
||||
2e1d1bbf32801f3d355c0d3f78ebbb1122cebd4c data/minecraft/recipes/potion_mortar_shell.json
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"type": "superbwarfare:ammo_box_extract_ammo",
|
||||
"category": "misc"
|
||||
}
|
|
@ -20,5 +20,6 @@ public class ModRecipeProvider extends RecipeProvider implements IConditionBuild
|
|||
protected void buildRecipes(@NotNull Consumer<FinishedRecipe> pWriter) {
|
||||
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");
|
||||
SpecialRecipeBuilder.special(ModRecipes.AMMO_BOX_EXTRACT_AMMO_SERIALIZER.get()).save(pWriter, "ammo_box_extract_ammo");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.atsuishio.superbwarfare.init;
|
|||
|
||||
import com.atsuishio.superbwarfare.ModUtils;
|
||||
import com.atsuishio.superbwarfare.recipe.AmmoBoxAddAmmoRecipe;
|
||||
import com.atsuishio.superbwarfare.recipe.AmmoBoxExtractAmmoRecipe;
|
||||
import com.atsuishio.superbwarfare.recipe.PotionMortarShellRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeSerializer;
|
||||
import net.minecraft.world.item.crafting.SimpleCraftingRecipeSerializer;
|
||||
|
@ -18,4 +19,7 @@ public class ModRecipes {
|
|||
|
||||
public static final RegistryObject<RecipeSerializer<AmmoBoxAddAmmoRecipe>> AMMO_BOX_ADD_AMMO_SERIALIZER =
|
||||
RECIPE_SERIALIZERS.register("ammo_box_add_ammo", () -> new SimpleCraftingRecipeSerializer<>(AmmoBoxAddAmmoRecipe::new));
|
||||
public static final RegistryObject<RecipeSerializer<AmmoBoxExtractAmmoRecipe>> AMMO_BOX_EXTRACT_AMMO_SERIALIZER =
|
||||
RECIPE_SERIALIZERS.register("ammo_box_extract_ammo", () -> new SimpleCraftingRecipeSerializer<>(AmmoBoxExtractAmmoRecipe::new));
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
package com.atsuishio.superbwarfare.recipe;
|
||||
|
||||
import com.atsuishio.superbwarfare.init.ModItems;
|
||||
import com.atsuishio.superbwarfare.init.ModRecipes;
|
||||
import com.atsuishio.superbwarfare.item.common.ammo.AmmoBox;
|
||||
import com.atsuishio.superbwarfare.tools.AmmoType;
|
||||
import net.minecraft.core.NonNullList;
|
||||
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;
|
||||
|
||||
public class AmmoBoxExtractAmmoRecipe extends CustomRecipe {
|
||||
|
||||
public AmmoBoxExtractAmmoRecipe(ResourceLocation pId, CraftingBookCategory pCategory) {
|
||||
super(pId, pCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(CraftingContainer pContainer, @NotNull Level pLevel) {
|
||||
var hasAmmoBox = false;
|
||||
var ammoBoxItem = ItemStack.EMPTY;
|
||||
|
||||
for (var item : pContainer.getItems()) {
|
||||
if (item.getItem() instanceof AmmoBox) {
|
||||
if (hasAmmoBox) return false;
|
||||
hasAmmoBox = true;
|
||||
ammoBoxItem = item;
|
||||
} else if (!item.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var tag = ammoBoxItem.getTag();
|
||||
if (tag == null) return false;
|
||||
|
||||
var typeString = tag.getString("Type");
|
||||
var type = AmmoType.getType(typeString);
|
||||
if (type == null) return false;
|
||||
|
||||
return type.get(ammoBoxItem) > 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull ItemStack assemble(CraftingContainer pContainer, @NotNull RegistryAccess pRegistryAccess) {
|
||||
AmmoType type = null;
|
||||
|
||||
for (var item : pContainer.getItems()) {
|
||||
if (item.getItem() instanceof AmmoBox) {
|
||||
type = AmmoType.getType(item.getOrCreateTag().getString("Type"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assert type != null;
|
||||
|
||||
// 也许这边有更好的方案?
|
||||
return switch (type) {
|
||||
case HANDGUN -> new ItemStack(ModItems.HANDGUN_AMMO.get());
|
||||
case RIFLE -> new ItemStack(ModItems.RIFLE_AMMO.get());
|
||||
case SHOTGUN -> new ItemStack(ModItems.SHOTGUN_AMMO.get());
|
||||
case SNIPER -> new ItemStack(ModItems.SNIPER_AMMO.get());
|
||||
case HEAVY -> new ItemStack(ModItems.HEAVY_AMMO.get());
|
||||
default -> throw new IllegalStateException("Unexpected value: " + type);
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull NonNullList<ItemStack> getRemainingItems(@NotNull CraftingContainer pContainer) {
|
||||
var remaining = super.getRemainingItems(pContainer);
|
||||
|
||||
for (int i = 0; i < pContainer.getContainerSize(); i++) {
|
||||
var item = pContainer.getItem(i);
|
||||
if (item.getItem() instanceof AmmoBox) {
|
||||
var ammoBox = item.copy();
|
||||
AmmoType type = AmmoType.getType(item.getOrCreateTag().getString("Type"));
|
||||
|
||||
assert type != null;
|
||||
type.add(ammoBox, -1);
|
||||
remaining.set(i, ammoBox);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return remaining;
|
||||
}
|
||||
|
||||
@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