Skip to content

Commit

Permalink
Merge pull request #523 from P3pp3rF1y/1.21.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 7bb785a + 85d48c9 commit 8d28009
Show file tree
Hide file tree
Showing 22 changed files with 189 additions and 21 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ loader_version_range=[4,)
mod_id=sophisticatedstorage
mod_name=Sophisticated Storage
mod_license=GNU General Public License v3.0
mod_version=0.10.49
mod_version=0.10.50
mod_group_id=sophisticatedstorage
mod_authors=P3pp3rF1y, Ridanisaurus
mod_description=Fancy and functional storage containers.
Expand All @@ -35,7 +35,7 @@ jade_cf_file_id=5109393
chipped_cf_file_id=5506938
resourcefullib_cf_file_id=5483169
athena_cf_file_id=5431579
sc_version=[1.21-0.6.44,1.22)
sc_version=[1.21-0.6.49,1.22)
sb_version=[1.21,1.22)

#publish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"itemRegistryName": "sophisticatedstorage:shulker_box"
}
],
"type": "minecraft:crafting_shapeless",
"type": "sophisticatedstorage:shulker_box_from_vanilla_shapeless",
"category": "misc",
"ingredients": [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package net.p3pp3rf1y.sophisticatedstorage.crafting;

import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler;
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.StackStorageWrapper;
import net.p3pp3rf1y.sophisticatedstorage.item.WoodStorageBlockItem;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class ShulkerBoxFromVanillaShapedRecipe extends ShapedRecipe implements IWrapperRecipe<ShapedRecipe> {
private final ShapedRecipe compose;

public ShulkerBoxFromVanillaShapedRecipe(ShapedRecipe compose) {
super(compose.getGroup(), compose.category(), compose.pattern, compose.result);
this.compose = compose;
}

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

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

@Override
public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {
ItemStack upgradedStorage = super.assemble(input, registries);
getVanillaShulkerBox(input).ifPresent(vanillaShulkerBox -> {
@Nullable IItemHandler itemCap = vanillaShulkerBox.getCapability(Capabilities.ItemHandler.ITEM);
if (itemCap != null) {
StackStorageWrapper wrapper = StackStorageWrapper.fromStack(registries, upgradedStorage);
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(CraftingInput input) {
for (int slot = 0; slot < input.size(); 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_SHAPED_RECIPE_SERIALIZER.get();
}

public static class Serializer extends RecipeWrapperSerializer<ShapedRecipe, ShulkerBoxFromVanillaShapedRecipe> {
public Serializer() {
super(ShulkerBoxFromVanillaShapedRecipe::new, RecipeSerializer.SHAPED_RECIPE);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package net.p3pp3rf1y.sophisticatedstorage.crafting;

import net.minecraft.core.HolderLookup;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingInput;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.ShapelessRecipe;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.items.IItemHandler;
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.StackStorageWrapper;
import net.p3pp3rf1y.sophisticatedstorage.item.WoodStorageBlockItem;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class ShulkerBoxFromVanillaShapelessRecipe extends ShapelessRecipe implements IWrapperRecipe<ShapelessRecipe> {
private final ShapelessRecipe compose;

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

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

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

@Override
public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {
ItemStack upgradedStorage = super.assemble(input, registries);
getVanillaShulkerBox(input).ifPresent(vanillaShulkerBox -> {
@Nullable IItemHandler itemCap = vanillaShulkerBox.getCapability(Capabilities.ItemHandler.ITEM);
if (itemCap != null) {
StackStorageWrapper wrapper = StackStorageWrapper.fromStack(registries, upgradedStorage);
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(CraftingInput input) {
for (int slot = 0; slot < input.size(); 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 @@ -345,7 +345,7 @@ private void addShulkerBoxRecipes(RecipeOutput recipeOutput) {
.unlockedBy("has_shulker_shell", has(Items.SHULKER_SHELL))
.save(recipeOutput);

ShapelessBasedRecipeBuilder.shapeless(ModBlocks.SHULKER_BOX_ITEM.get())
ShapelessBasedRecipeBuilder.shapeless(ModBlocks.SHULKER_BOX_ITEM.get(), ShulkerBoxFromVanillaShapelessRecipe::new)
.requires(Items.SHULKER_BOX).requires(Items.REDSTONE_TORCH)
.unlockedBy("has_shulker_box", has(Items.SHULKER_BOX))
.save(recipeOutput, "shulker_box_from_vanilla_shulker_box");
Expand Down Expand Up @@ -1135,7 +1135,7 @@ private void woodChestRecipe(RecipeOutput recipeOutput, WoodType woodType, Block

private void tintedShulkerBoxRecipe(RecipeOutput recipeOutput, Block vanillaShulkerBox, DyeColor dyeColor) {
String vanillaShulkerBoxName = BuiltInRegistries.BLOCK.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), ShulkerBoxFromVanillaShapelessRecipe::new).requires(vanillaShulkerBox).requires(Items.REDSTONE_TORCH)
.unlockedBy("has_" + vanillaShulkerBoxName, has(vanillaShulkerBox))
.save(recipeOutput, SophisticatedStorage.getRL(vanillaShulkerBoxName + "_to_sophisticated"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
private static final DeferredRegister<RecipeSerializer<?>> RECIPE_SERIALIZERS = DeferredRegister.create(BuiltInRegistries.RECIPE_SERIALIZER, SophisticatedStorage.MOD_ID);
public static final Supplier<SimpleCraftingRecipeSerializer<?>> STORAGE_DYE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("storage_dye", () -> new SimpleCraftingRecipeSerializer<>(StorageDyeRecipe::new));
public static final Supplier<RecipeSerializer<?>> STORAGE_TIER_UPGRADE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("storage_tier_upgrade", StorageTierUpgradeRecipe.Serializer::new);
public static final Supplier<RecipeSerializer<?>> SHULKER_BOX_FROM_VANILLA_SHAPED_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("shulker_box_from_vanilla_shaped", ShulkerBoxFromVanillaShapedRecipe.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 Supplier<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_CHEST_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("shulker_box_from_chest", ShulkerBoxFromChestRecipe.Serializer::new);
public static final Supplier<SimpleCraftingRecipeSerializer<?>> FLAT_TOP_BARREL_TOGGLE_RECIPE_SERIALIZER = RECIPE_SERIALIZERS.register("flat_top_barrel_toggle", () -> new SimpleCraftingRecipeSerializer<>(FlatTopBarrelToggleRecipe::new));
Expand Down

0 comments on commit 8d28009

Please sign in to comment.