Skip to content

Commit

Permalink
Merge pull request #526 from P3pp3rF1y/1.20.x-dev
Browse files Browse the repository at this point in the history
fix: 🐛 Fixed vanilla shulker box to sophisticated shulker box upgrade…
  • Loading branch information
P3pp3rF1y authored Nov 9, 2024
2 parents 518fd8a + d4319c2 commit e9debb6
Show file tree
Hide file tree
Showing 22 changed files with 117 additions and 21 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false

mod_id=sophisticatedstorage
mod_group_id=sophisticatedstorage
mod_version=0.10.46
mod_version=0.10.47
sonar_project_key=sophisticatedstorage:SophisticatedStorage
github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedStorage

Expand All @@ -30,6 +30,6 @@ jade_cf_file_id=4614153
chipped_cf_file_id=5077656
resourcefullib_cf_file_id=5070629
athena_cf_file_id=4764357
sc_version=[1.20.1-0.6.34,1.20.4)
sc_version=[1.20.1-0.6.36,1.20.4)
sb_version=[1.20.1-3.20.5,1.20.4)
parchment_version=1.19.3-2023.03.12-1.20
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"conditions": [
{
"type": "sophisticatedcore:item_enabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
import net.minecraft.client.renderer.Rect2i;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.ShapelessRecipe;
import net.p3pp3rf1y.sophisticatedbackpacks.crafting.BackpackUpgradeRecipe;
import net.p3pp3rf1y.sophisticatedcore.client.gui.SettingsScreen;
import net.p3pp3rf1y.sophisticatedcore.compat.jei.ClientRecipeHelper;
import net.p3pp3rf1y.sophisticatedcore.compat.jei.CraftingContainerRecipeTransferHandlerBase;
import net.p3pp3rf1y.sophisticatedcore.compat.jei.SettingsGhostIngredientHandler;
import net.p3pp3rf1y.sophisticatedcore.compat.jei.StorageGhostIngredientHandler;
import net.p3pp3rf1y.sophisticatedstorage.SophisticatedStorage;
import net.p3pp3rf1y.sophisticatedstorage.client.gui.StorageScreen;
import net.p3pp3rf1y.sophisticatedstorage.client.gui.StorageSettingsScreen;
import net.p3pp3rf1y.sophisticatedstorage.common.gui.StorageContainerMenu;
import net.p3pp3rf1y.sophisticatedstorage.crafting.ShulkerBoxFromVanillaShapelessRecipe;
import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks;
import net.p3pp3rf1y.sophisticatedstorage.init.ModItems;
import net.p3pp3rf1y.sophisticatedstorage.item.BarrelBlockItem;
Expand Down Expand Up @@ -142,6 +147,7 @@ public void registerRecipes(IRecipeRegistration registration) {
registration.addRecipes(RecipeTypes.CRAFTING, DyeRecipesMaker.getRecipes());
registration.addRecipes(RecipeTypes.CRAFTING, TierUpgradeRecipesMaker.getShapedCraftingRecipes());
registration.addRecipes(RecipeTypes.CRAFTING, TierUpgradeRecipesMaker.getShapelessCraftingRecipes());
registration.addRecipes(RecipeTypes.CRAFTING, ClientRecipeHelper.getAndTransformAvailableRecipes(ShulkerBoxFromVanillaShapelessRecipe.REGISTERED_RECIPES, ShulkerBoxFromVanillaShapelessRecipe.class, ClientRecipeHelper::copyShapelessRecipe));
registration.addRecipes(RecipeTypes.CRAFTING, ShulkerBoxFromChestRecipesMaker.getRecipes());
registration.addRecipes(RecipeTypes.CRAFTING, FlatBarrelRecipesMaker.getRecipes());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package net.p3pp3rf1y.sophisticatedstorage.crafting;

import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.ShapelessRecipe;
import net.minecraft.world.level.Level;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.p3pp3rf1y.sophisticatedcore.crafting.IWrapperRecipe;
import net.p3pp3rf1y.sophisticatedcore.crafting.RecipeWrapperSerializer;
import net.p3pp3rf1y.sophisticatedcore.util.InventoryHelper;
import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks;
import net.p3pp3rf1y.sophisticatedstorage.item.CapabilityStorageWrapper;
import net.p3pp3rf1y.sophisticatedstorage.item.WoodStorageBlockItem;

import java.util.LinkedHashSet;
import java.util.Optional;
import java.util.Set;

public class ShulkerBoxFromVanillaShapelessRecipe extends ShapelessRecipe implements IWrapperRecipe<ShapelessRecipe> {
public static final Set<ResourceLocation> REGISTERED_RECIPES = new LinkedHashSet<>();
private final ShapelessRecipe compose;

public ShulkerBoxFromVanillaShapelessRecipe(ShapelessRecipe compose) {
super(compose.getId(), compose.getGroup(), compose.category(), compose.result, compose.getIngredients());
this.compose = compose;
REGISTERED_RECIPES.add(compose.getId());
}

@Override
public boolean matches(CraftingContainer inventory, Level level) {
return super.matches(inventory, level) && getVanillaShulkerBox(inventory).map(storage -> !(storage.getItem() instanceof WoodStorageBlockItem) || !WoodStorageBlockItem.isPacked(storage)).orElse(false);
}

@Override
public ShapelessRecipe getCompose() {
return compose;
}

@Override
public ItemStack assemble(CraftingContainer input, RegistryAccess registries) {
ItemStack upgradedStorage = super.assemble(input, registries);
getVanillaShulkerBox(input).ifPresent(vanillaShulkerBox -> {

vanillaShulkerBox.getCapability(ForgeCapabilities.ITEM_HANDLER).ifPresent(itemCap -> {
upgradedStorage.getCapability(CapabilityStorageWrapper.getCapabilityInstance()).ifPresent(wrapper -> {
InventoryHelper.iterate(itemCap, (slot, stack) -> {
if (!stack.isEmpty()) {
wrapper.getInventoryHandler().insertItem(stack, false);
}
});
});
});
});
return upgradedStorage;
}

@Override
public boolean isSpecial() {
return true;
}

private Optional<ItemStack> getVanillaShulkerBox(CraftingContainer input) {
for (int slot = 0; slot < input.getContainerSize(); slot++) {
ItemStack slotStack = input.getItem(slot);
if (slotStack.getItem() instanceof BlockItem blockItem && blockItem.getBlock() instanceof net.minecraft.world.level.block.ShulkerBoxBlock) {
return Optional.of(slotStack);
}
}

return Optional.empty();
}

@Override
public RecipeSerializer<?> getSerializer() {
return ModBlocks.SHULKER_BOX_FROM_VANILLA_SHAPELESS_RECIPE_SERIALIZER.get();
}

public static class Serializer extends RecipeWrapperSerializer<ShapelessRecipe, ShulkerBoxFromVanillaShapelessRecipe> {
public Serializer() {
super(ShulkerBoxFromVanillaShapelessRecipe::new, RecipeSerializer.SHAPELESS_RECIPE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private void addShulkerBoxRecipes(Consumer<FinishedRecipe> consumer) {
.unlockedBy("has_shulker_shell", has(Items.SHULKER_SHELL))
.save(consumer);

ShapelessBasedRecipeBuilder.shapeless(ModBlocks.SHULKER_BOX_ITEM.get())
ShapelessBasedRecipeBuilder.shapeless(ModBlocks.SHULKER_BOX_ITEM.get(), ModBlocks.SHULKER_BOX_FROM_VANILLA_SHAPELESS_RECIPE_SERIALIZER.get())
.requires(Items.SHULKER_BOX).requires(Items.REDSTONE_TORCH)
.save(consumer, "shulker_box_from_vanilla_shulker_box");

Expand Down Expand Up @@ -1143,7 +1143,7 @@ private void woodChestRecipe(Consumer<FinishedRecipe> consumer, WoodType woodTyp
private void tintedShulkerBoxRecipe(Consumer<FinishedRecipe> consumer, Block vanillaShulkerBox, DyeColor dyeColor) {
//noinspection ConstantConditions
String vanillaShulkerBoxName = ForgeRegistries.BLOCKS.getKey(vanillaShulkerBox).getPath();
ShapelessBasedRecipeBuilder.shapeless(ModBlocks.SHULKER_BOX.get().getTintedStack(dyeColor)).requires(vanillaShulkerBox).requires(Items.REDSTONE_TORCH)
ShapelessBasedRecipeBuilder.shapeless(ModBlocks.SHULKER_BOX.get().getTintedStack(dyeColor), ModBlocks.SHULKER_BOX_FROM_VANILLA_SHAPELESS_RECIPE_SERIALIZER.get()).requires(vanillaShulkerBox).requires(Items.REDSTONE_TORCH)
.unlockedBy("has_" + vanillaShulkerBoxName, has(vanillaShulkerBox))
.save(consumer, SophisticatedStorage.getRL(vanillaShulkerBoxName + "_to_sophisticated"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import net.p3pp3rf1y.sophisticatedstorage.item.ShulkerBoxItem;
import net.p3pp3rf1y.sophisticatedstorage.item.WoodStorageBlockItem;

import java.util.function.Supplier;

public class ModBlocks {
private static final String LIMITED_BARREL_NAME = "limited_barrel";

Expand Down Expand Up @@ -285,6 +287,7 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
public static final RegistryObject<SimpleCraftingRecipeSerializer<?>> STORAGE_DYE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("storage_dye", () -> new SimpleCraftingRecipeSerializer<>(StorageDyeRecipe::new));
public static final RegistryObject<RecipeSerializer<?>> STORAGE_TIER_UPGRADE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("storage_tier_upgrade", StorageTierUpgradeRecipe.Serializer::new);
public static final RegistryObject<RecipeSerializer<?>> STORAGE_TIER_UPGRADE_SHAPELESS_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("storage_tier_upgrade_shapeless", StorageTierUpgradeShapelessRecipe.Serializer::new);
public static final Supplier<RecipeSerializer<?>> SHULKER_BOX_FROM_VANILLA_SHAPELESS_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("shulker_box_from_vanilla_shapeless", ShulkerBoxFromVanillaShapelessRecipe.Serializer::new);
public static final RegistryObject<RecipeSerializer<?>> SHULKER_BOX_FROM_CHEST_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("shulker_box_from_chest", ShulkerBoxFromChestRecipe.Serializer::new);
public static final RegistryObject<SimpleCraftingRecipeSerializer<?>> FLAT_TOP_BARREL_TOGGLE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("flat_top_barrel_toggle", () -> new SimpleCraftingRecipeSerializer<>(FlatTopBarrelToggleRecipe::new));
public static final RegistryObject<SimpleCraftingRecipeSerializer<?>> BARREL_MATERIAL_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("barrel_material", () -> new SimpleCraftingRecipeSerializer<>(BarrelMaterialRecipe::new));
Expand Down

0 comments on commit e9debb6

Please sign in to comment.