Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复异常的物品压缩/粉碎配方 #13

Merged
merged 1 commit into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;
Expand All @@ -25,13 +26,30 @@ public static void buildRecipes(Consumer<FinishedRecipe> exporter) {
smash(Items.NETHER_STAR, ModItems.NETHER_STAR_SHARD, 4, exporter);
smash(ModItems.HOLLOW_MAGNET_BLOCK, ModItems.MAGNET_INGOT, 8, exporter);
smash(ModItems.MAGNET_BLOCK, ModItems.MAGNET_INGOT, 9, exporter);
smash(Items.MELON, Items.MELON_SLICE, 9, exporter);
smash(Items.SNOW_BLOCK, Items.SNOWBALL, 4, exporter);
smash(Items.CLAY, Items.CLAY_BALL, 4, exporter);
smash(Items.PRISMARINE, Items.PRISMARINE_SHARD, 4, exporter);
smash(Items.PRISMARINE_BRICKS, Items.PRISMARINE, 9, exporter);
smash(Items.GLOWSTONE, Items.GLOWSTONE_DUST, 4, exporter);
smash(Items.QUARTZ_BLOCK, Items.QUARTZ, 4, exporter);
smash(Items.DRIPSTONE_BLOCK, Items.POINTED_DRIPSTONE, 4, exporter);
smash(Items.AMETHYST_BLOCK, Items.AMETHYST_SHARD, 4, exporter);
smash(Items.HONEYCOMB_BLOCK, Items.HONEYCOMB, 4, exporter);
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.hasBlock(Blocks.IRON_TRAPDOOR)
.hasItemIngredient(Items.HONEY_BLOCK)
.hasItemIngredient(Items.GLASS_BOTTLE)
.spawnItem(new Vec3(0.0, -1.0, 0.0), Items.HONEY_BOTTLE, 4)
.unlockedBy(MyRecipesGenerator.hasItem(Items.HONEY_BLOCK), FabricRecipeProvider.has(Items.HONEY_BLOCK))
.save(exporter, AnvilCraft.of("smash/" + BuiltInRegistries.ITEM.getKey(Items.HONEY_BLOCK).getPath() + "_2_" + BuiltInRegistries.ITEM.getKey(Items.HONEY_BOTTLE).getPath()));
}

public static void smash(Item item, @NotNull Item item1, int count, Consumer<FinishedRecipe> exporter) {
AnvilRecipe.Builder.create(RecipeCategory.MISC)
.hasBlock(Blocks.IRON_TRAPDOOR)
.hasItemIngredient(item)
.spawnItem(item1, count)
.spawnItem(new Vec3(0.0, -1.0, 0.0), item1, count)
.unlockedBy(MyRecipesGenerator.hasItem(item), FabricRecipeProvider.has(item))
.save(exporter, AnvilCraft.of("smash/" + BuiltInRegistries.ITEM.getKey(item).getPath() + "_2_" + BuiltInRegistries.ITEM.getKey(item1).getPath()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public static void buildRecipes(Consumer<FinishedRecipe> exporter) {
.hasBlock(Blocks.PISTON.defaultBlockState().setValue(PistonBaseBlock.FACING, Direction.UP))
.hasItemIngredient(Items.MILK_BUCKET)
.spawnItem(ModItems.CREAM)
.spawnItem(Items.BUCKET)
.unlockedBy(MyRecipesGenerator.hasItem(Items.MILK_BUCKET), FabricRecipeProvider.has(Items.MILK_BUCKET))
.save(exporter, AnvilCraft.of("stamping/cream"));
AnvilRecipe.Builder.create(RecipeCategory.MISC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ public boolean process(@NotNull AnvilCraftingContainer container) {
ItemStack item = entity.getItem();
if (this.matchItem.matches(item)) {
int count = this.matchItem.count.getMin() != null ? this.matchItem.count.getMin() : 1;
if (item.getItem().hasCraftingRemainingItem()) {
assert item.getItem().getCraftingRemainingItem() != null;
ItemStack stack = new ItemStack(item.getItem().getCraftingRemainingItem(), count);
Vec3 vec3 = pos.getCenter().add(this.offset);
ItemEntity itemEntity = new ItemEntity(level, vec3.x, vec3.y, vec3.z, stack, 0.0, 0.0, 0.0);
level.addFreshEntity(itemEntity);
}
item.shrink(count);
entity.setItem(item.copy());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static void processRecipes(@NotNull MinecraftServer server) {
public static @Nullable Pair<ResourceLocation, Recipe<?>> processRecipes(ResourceLocation id, @NotNull Recipe<?> oldRecipe) {
ItemStack result = oldRecipe.getResultItem(new RegistryAccess.ImmutableRegistryAccess(List.of()));
if (result.is(Items.IRON_TRAPDOOR)) return null;
if (result.is(Items.PRISMARINE)) return null;
ResourceLocation location = AnvilCraft.of("compress/" + id.getPath());
if (oldRecipe instanceof ShapelessRecipe recipe) {
if (recipe.getIngredients().size() == 1) {
Expand Down Expand Up @@ -115,7 +116,7 @@ private static Pair<ResourceLocation, Recipe<?>> getResourceLocationRecipePair(I
public static boolean isIngredientsSame(@NotNull List<Ingredient> ingredients) {
Ingredient ingredient = ingredients.get(0);
for (Ingredient ingredient1 : ingredients) {
if (ingredient1.equals(ingredient)) continue;
if (ingredient1.toJson().equals(ingredient.toJson())) continue;
return false;
}
return true;
Expand Down
Loading