diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index c16376a..0506f0f 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -87,4 +87,5 @@ ff234dac4f0b0b4f83ffa92f2d2fb1074c68df43 data/functionalstorage/recipes/spruce_4 bcb281904eac23183c45786e3d703d24bba92be6 data/functionalstorage/recipes/warped_1.json 8fc3f76a2c57eb4d80ce86947fabebe48fa6f692 data/functionalstorage/recipes/warped_2.json 7510a8ca1f1e3bb63f4c4f4add0bb6b713feaa0b data/functionalstorage/recipes/warped_4.json -f37e620a26ceb158507c607cee6ba3b51f14c6d6 data/functionalstorage/tags/items/drawer.json +db0122948639b122cb0c1df7530996e9784356b0 data/functionalstorage/tags/items/drawer.json +12ec935226bf5a6a1493d353ef6dc6c224c256dd data/functionalstorage/tags/items/ignore_crafting_check.json diff --git a/src/generated/resources/data/functionalstorage/tags/items/drawer.json b/src/generated/resources/data/functionalstorage/tags/items/drawer.json index dd31495..6dff867 100644 --- a/src/generated/resources/data/functionalstorage/tags/items/drawer.json +++ b/src/generated/resources/data/functionalstorage/tags/items/drawer.json @@ -1,14 +1,14 @@ { "replace": false, "values": [ - "functionalstorage:oak_2", - "functionalstorage:spruce_2", - "functionalstorage:birch_2", - "functionalstorage:jungle_2", - "functionalstorage:acacia_2", - "functionalstorage:dark_oak_2", - "functionalstorage:crimson_2", - "functionalstorage:warped_2", + "functionalstorage:oak_1", + "functionalstorage:spruce_1", + "functionalstorage:birch_1", + "functionalstorage:jungle_1", + "functionalstorage:acacia_1", + "functionalstorage:dark_oak_1", + "functionalstorage:crimson_1", + "functionalstorage:warped_1", "functionalstorage:oak_4", "functionalstorage:spruce_4", "functionalstorage:birch_4", @@ -17,13 +17,13 @@ "functionalstorage:dark_oak_4", "functionalstorage:crimson_4", "functionalstorage:warped_4", - "functionalstorage:oak_1", - "functionalstorage:spruce_1", - "functionalstorage:birch_1", - "functionalstorage:jungle_1", - "functionalstorage:acacia_1", - "functionalstorage:dark_oak_1", - "functionalstorage:crimson_1", - "functionalstorage:warped_1" + "functionalstorage:oak_2", + "functionalstorage:spruce_2", + "functionalstorage:birch_2", + "functionalstorage:jungle_2", + "functionalstorage:acacia_2", + "functionalstorage:dark_oak_2", + "functionalstorage:crimson_2", + "functionalstorage:warped_2" ] } \ No newline at end of file diff --git a/src/generated/resources/data/functionalstorage/tags/items/ignore_crafting_check.json b/src/generated/resources/data/functionalstorage/tags/items/ignore_crafting_check.json new file mode 100644 index 0000000..fad5dae --- /dev/null +++ b/src/generated/resources/data/functionalstorage/tags/items/ignore_crafting_check.json @@ -0,0 +1,9 @@ +{ + "replace": false, + "values": [ + "minecraft:clay", + "minecraft:clay_ball", + "minecraft:glowstone", + "minecraft:glowstone_dust" + ] +} \ No newline at end of file diff --git a/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingDrawerTile.java b/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingDrawerTile.java index 5a7f038..651e893 100644 --- a/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingDrawerTile.java +++ b/src/main/java/com/buuz135/functionalstorage/block/tile/CompactingDrawerTile.java @@ -15,6 +15,7 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.HitResult; @@ -36,6 +37,7 @@ public class CompactingDrawerTile extends ControllableDrawerTile lazyStorage; + private boolean hasCheckedRecipes; public CompactingDrawerTile(BasicTileBlock base, BlockPos pos, BlockState state) { super(base, pos, state); @@ -61,7 +63,20 @@ public class CompactingDrawerTile extends ControllableDrawerTile this.handler); - //TODO Check for the recipe on load + this.hasCheckedRecipes = false; + } + + @Override + public void serverTick(Level level, BlockPos pos, BlockState state, CompactingDrawerTile blockEntity) { + super.serverTick(level, pos, state, blockEntity); + if (!hasCheckedRecipes){ + if (!handler.getParent().isEmpty()){ + CompactingUtil compactingUtil = new CompactingUtil(this.level); + compactingUtil.setup(handler.getParent()); + handler.setup(compactingUtil); + } + hasCheckedRecipes = true; + } } public InteractionResult onSlotActivated(Player playerIn, InteractionHand hand, Direction facing, double hitX, double hitY, double hitZ, int slot) { diff --git a/src/main/java/com/buuz135/functionalstorage/client/CompactingDrawerRenderer.java b/src/main/java/com/buuz135/functionalstorage/client/CompactingDrawerRenderer.java index 43be4b6..e0a85ad 100644 --- a/src/main/java/com/buuz135/functionalstorage/client/CompactingDrawerRenderer.java +++ b/src/main/java/com/buuz135/functionalstorage/client/CompactingDrawerRenderer.java @@ -54,27 +54,7 @@ public class CompactingDrawerRenderer implements BlockEntityRenderer { } matrixStack.translate(0,0,-0.5/16D); combinedLightIn = LevelRenderer.getLightColor(tile.getLevel(), tile.getBlockPos().relative(facing)); + renderUpgrades(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile); + if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_1) render1Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile); + if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_2) render2Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile); + if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_4) render4Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile); + matrixStack.popPose(); + } + + public static void renderUpgrades(PoseStack matrixStack, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn, ControllableDrawerTile tile){ matrixStack.pushPose(); matrixStack.translate(0.031,0.031f,0.469/16D); float scale = 0.0625f; @@ -78,10 +87,6 @@ public class DrawerRenderer implements BlockEntityRenderer { Minecraft.getInstance().getItemRenderer().renderStatic(new ItemStack(FunctionalStorage.VOID_UPGRADE.get()), ItemTransforms.TransformType.NONE, combinedLightIn, combinedOverlayIn, matrixStack, bufferIn, 0); matrixStack.popPose(); } - if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_1) render1Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile); - if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_2) render2Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile); - if (tile.getDrawerType() == FunctionalStorage.DrawerType.X_4) render4Slot(matrixStack, bufferIn, combinedLightIn, combinedOverlayIn, tile); - matrixStack.popPose(); } private void render1Slot(PoseStack matrixStack, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn, DrawerTile tile){ diff --git a/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageTagsProvider.java b/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageTagsProvider.java index a152cd1..70804fa 100644 --- a/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageTagsProvider.java +++ b/src/main/java/com/buuz135/functionalstorage/data/FunctionalStorageTagsProvider.java @@ -8,6 +8,7 @@ import net.minecraft.data.tags.ItemTagsProvider; import net.minecraft.data.tags.TagsProvider; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Block; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.registries.RegistryObject; @@ -29,5 +30,6 @@ public class FunctionalStorageTagsProvider extends ItemTagsProvider { tTagAppender.add(blockRegistryObject.get().asItem()); } } + this.tag(StorageTags.IGNORE_CRAFTING_CHECK).add(Items.CLAY).add(Items.CLAY_BALL).add(Items.GLOWSTONE).add(Items.GLOWSTONE_DUST); } } diff --git a/src/main/java/com/buuz135/functionalstorage/inventory/CompactingInventoryHandler.java b/src/main/java/com/buuz135/functionalstorage/inventory/CompactingInventoryHandler.java index eff3a20..07e2ea2 100644 --- a/src/main/java/com/buuz135/functionalstorage/inventory/CompactingInventoryHandler.java +++ b/src/main/java/com/buuz135/functionalstorage/inventory/CompactingInventoryHandler.java @@ -13,7 +13,7 @@ import java.util.List; public abstract class CompactingInventoryHandler implements IItemHandler, INBTSerializable { - public static String VOID = "Void"; + public static String PARENT = "Parent"; public static String BIG_ITEMS = "BigItems"; public static String STACK = "Stack"; public static String AMOUNT = "Amount"; @@ -21,6 +21,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe public static final int TOTAL_AMOUNT = 512 * 9 * 9; private int amount; + private ItemStack parent; private List resultList; public CompactingInventoryHandler(){ @@ -28,6 +29,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe for (int i = 0; i < 3; i++) { this.resultList.add(i, new CompactingUtil.Result(ItemStack.EMPTY, 1)); } + this.parent = ItemStack.EMPTY; } @Override @@ -69,6 +71,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe public void setup(CompactingUtil compactingUtil){ this.resultList = compactingUtil.getResults(); + this.parent = compactingUtil.getResults().get(2).getResult(); onChange(); } @@ -133,6 +136,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe @Override public CompoundTag serializeNBT() { CompoundTag compoundTag = new CompoundTag(); + compoundTag.put(PARENT, this.getParent().serializeNBT()); compoundTag.putInt(AMOUNT, this.amount); CompoundTag items = new CompoundTag(); for (int i = 0; i < this.resultList.size(); i++) { @@ -147,6 +151,7 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe @Override public void deserializeNBT(CompoundTag nbt) { + this.parent = ItemStack.of(nbt.getCompound(PARENT)); this.amount = nbt.getInt(AMOUNT); for (String allKey : nbt.getCompound(BIG_ITEMS).getAllKeys()) { this.resultList.get(Integer.parseInt(allKey)).setResult(ItemStack.of(nbt.getCompound(BIG_ITEMS).getCompound(allKey).getCompound(STACK))); @@ -165,4 +170,8 @@ public abstract class CompactingInventoryHandler implements IItemHandler, INBTSe public List getResultList() { return resultList; } + + public ItemStack getParent() { + return parent; + } } diff --git a/src/main/java/com/buuz135/functionalstorage/util/CompactingUtil.java b/src/main/java/com/buuz135/functionalstorage/util/CompactingUtil.java index 9d45236..d9e593d 100644 --- a/src/main/java/com/buuz135/functionalstorage/util/CompactingUtil.java +++ b/src/main/java/com/buuz135/functionalstorage/util/CompactingUtil.java @@ -76,7 +76,9 @@ public class CompactingUtil { container = createContainerAndFill(2, stack); outputs = findAllMatchingRecipes(container); } - if (outputs.size() > 0){ + if (stack.is(StorageTags.IGNORE_CRAFTING_CHECK)){ + realOutputs = outputs; + }else if (outputs.size() > 0){ for (ItemStack output : outputs) { container = createContainerAndFill(1, output); List reversed = findAllMatchingRecipes(container); @@ -107,13 +109,18 @@ public class CompactingUtil { if (!ItemStack.isSame(stack, output)) continue; ItemStack match = tryMatch(stack, craftingRecipe.getIngredients()); if (!match.isEmpty()){ + int recipeSize = craftingRecipe.getIngredients().size(); + if (stack.is(StorageTags.IGNORE_CRAFTING_CHECK)){ + candidates.add(match); + candidatesRate.put(match, recipeSize); + } CraftingContainer container = createContainerAndFill(1, output); List matchStacks = findAllMatchingRecipes(container); for (ItemStack matchStack : matchStacks) { - int recipeSize = craftingRecipe.getIngredients().size(); if (ItemStack.isSame(match, matchStack) && matchStack.getCount() == recipeSize){ candidates.add(match); candidatesRate.put(match, recipeSize); + break; } } } diff --git a/src/main/java/com/buuz135/functionalstorage/util/StorageTags.java b/src/main/java/com/buuz135/functionalstorage/util/StorageTags.java index ae1cb89..6ff4a6e 100644 --- a/src/main/java/com/buuz135/functionalstorage/util/StorageTags.java +++ b/src/main/java/com/buuz135/functionalstorage/util/StorageTags.java @@ -9,5 +9,6 @@ import net.minecraftforge.common.Tags; public class StorageTags { public static Tags.IOptionalNamedTag DRAWER = ItemTags.createOptional(new ResourceLocation(FunctionalStorage.MOD_ID, "drawer")); + public static Tags.IOptionalNamedTag IGNORE_CRAFTING_CHECK = ItemTags.createOptional(new ResourceLocation(FunctionalStorage.MOD_ID, "ignore_crafting_check")); }