From dbd259b4c05f6ea6a8ad359aa38ab5b597e3f8e8 Mon Sep 17 00:00:00 2001 From: Dragonoidzero Date: Thu, 4 Mar 2021 00:33:42 -0600 Subject: [PATCH] Finished recipe system rewrite, updated fabric.mod.json, added more recipes, cleaned up machine code. --- gradle.properties | 2 +- .../LookingGlassREIIntegration.java | 20 ++- .../block/BlockInductorBlock.java | 4 +- .../block/HorizontalMachineBlock.java | 9 + .../block/LookingGlassBlocks.java | 2 +- .../blockentity/AlloyFurnaceEntity.java | 19 +- .../blockentity/BlockTesseractEntity.java | 2 +- .../blockentity/GrinderEntity.java | 45 +---- .../LookingGlassUpgradeableMachine.java | 4 +- .../lookingglass/blockentity/MixerEntity.java | 31 +--- .../blockentity/PoweredFurnaceEntity.java | 27 +-- .../blockentity/VacuumHopperEntity.java | 2 +- .../gui/UpgradeableMachineGuiDescription.java | 4 +- .../lookingglass/item/GenericUpgradeItem.java | 4 +- .../lookingglass/item/LookingGlassItems.java | 9 +- .../item/RecipeConvertingUpgradeItem.java | 4 +- .../lookingglass/mixin/IngredientMixin.java | 21 +++ .../lookingglass/recipe/AlloyingRecipe.java | 56 +++--- .../lookingglass/recipe/FreezingRecipe.java | 36 ++-- .../lookingglass/recipe/GrinderRecipe.java | 145 ---------------- .../lookingglass/recipe/GrindingRecipe.java | 162 ++++++++++++++++++ .../lookingglass/recipe/InductionRecipe.java | 5 +- .../recipe/LookingGlassRecipe.java | 3 +- .../recipe/LookingGlassRecipes.java | 9 +- .../{MixerRecipe.java => MixingRecipe.java} | 65 +++---- .../fabric/lookingglass/util/BufUtils.java | 16 +- .../lookingglass/util/IngredientStack.java | 132 ++++++++++++++ .../util/MatchingStackAccessor.java | 8 + .../lookingglass/util/json/JsonUtils.java | 30 +++- .../util/{ => machine}/BlockEntityMover.java | 3 +- .../util/{ => machine}/FalseInventory.java | 2 +- .../util/{ => machine}/ModifierProvider.java | 2 +- .../RecipeConversionProvider.java | 2 +- .../util/rei/FreezingRecipeCategory.java | 2 +- .../util/rei/GrindingRecipeCategory.java | 43 +++++ .../util/rei/LookingGlassRecipeDisplay.java | 6 +- .../util/rei/MixingRecipeCategory.java | 41 +++++ .../assets/lookingglass/lang/en_us.json | 15 +- .../textures/block/finis_block.png | Bin 560 -> 534 bytes .../textures/block/silicon_cable.png | Bin 386 -> 405 bytes .../textures/item/red_silicon_ingot.png | Bin 380 -> 288 bytes .../textures/item/silicon_induction_coil.png | Bin 0 -> 392 bytes .../recipes/manual/alloying/finis_ingot.json | 23 ++- .../manual/alloying/guilded_cable.json | 22 ++- .../manual/alloying/red_silicon_ingot.json | 23 ++- .../manual/alloying/rose_gold_ingot.json | 23 ++- .../recipes/manual/core/interminal_core.json | 19 ++ .../recipes/manual/freezing/snow_to_ice.json | 10 +- .../manual/grinding/gravel_to_flint.json | 20 ++- .../recipes/manual/machine/alloy_furnace.json | 5 +- .../recipes/manual/machine/grinder.json | 28 +++ .../recipes/manual/machine/mixer.json | 28 +++ .../manual/machine/powered_furnace.json | 7 +- .../recipes/manual/machine/silicon_cable.json | 17 ++ .../machine/silicon_induction_coil.json | 16 ++ .../recipes/manual/machine/vacuum_hopper.json | 22 +++ .../recipes/{ => manual}/misc/fish_feed.json | 3 + .../recipes/manual/mixing/cake.json | 34 ++-- .../recipes/manual/mixing/fish_feed.json | 24 +++ .../recipes/manual/tool/angel_block.json | 22 +++ .../recipes/manual/tool/angel_ring.json | 25 +++ .../recipes/manual/tool/lumen_resonator.json | 22 +++ .../upgrade/arc_smelter_conversion.json | 25 +++ .../upgrade/basic_capacitance_module.json | 22 +++ .../upgrade/basic_efficiency_module.json | 22 +++ .../manual/upgrade/basic_speed_module.json | 22 +++ .../manual/upgrade/heat_pump_conversion.json | 25 +++ .../recipes/manual/upgrade/rose_chipset.json | 22 +++ src/main/resources/fabric.mod.json | 5 +- src/main/resources/lookingglass.mixins.json | 3 +- 70 files changed, 1092 insertions(+), 439 deletions(-) create mode 100644 src/main/java/azzy/fabric/lookingglass/mixin/IngredientMixin.java delete mode 100644 src/main/java/azzy/fabric/lookingglass/recipe/GrinderRecipe.java create mode 100644 src/main/java/azzy/fabric/lookingglass/recipe/GrindingRecipe.java rename src/main/java/azzy/fabric/lookingglass/recipe/{MixerRecipe.java => MixingRecipe.java} (59%) create mode 100644 src/main/java/azzy/fabric/lookingglass/util/IngredientStack.java create mode 100644 src/main/java/azzy/fabric/lookingglass/util/MatchingStackAccessor.java rename src/main/java/azzy/fabric/lookingglass/util/{ => machine}/BlockEntityMover.java (95%) rename src/main/java/azzy/fabric/lookingglass/util/{ => machine}/FalseInventory.java (95%) rename src/main/java/azzy/fabric/lookingglass/util/{ => machine}/ModifierProvider.java (93%) rename src/main/java/azzy/fabric/lookingglass/util/{ => machine}/RecipeConversionProvider.java (79%) create mode 100644 src/main/java/azzy/fabric/lookingglass/util/rei/GrindingRecipeCategory.java create mode 100644 src/main/java/azzy/fabric/lookingglass/util/rei/MixingRecipeCategory.java create mode 100755 src/main/resources/assets/lookingglass/textures/item/silicon_induction_coil.png create mode 100644 src/main/resources/data/lookingglass/recipes/manual/core/interminal_core.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/machine/grinder.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/machine/mixer.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/machine/silicon_cable.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/machine/silicon_induction_coil.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/machine/vacuum_hopper.json rename src/main/resources/data/lookingglass/recipes/{ => manual}/misc/fish_feed.json (88%) create mode 100644 src/main/resources/data/lookingglass/recipes/manual/mixing/fish_feed.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/tool/angel_block.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/tool/angel_ring.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/tool/lumen_resonator.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/upgrade/arc_smelter_conversion.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/upgrade/basic_capacitance_module.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/upgrade/basic_efficiency_module.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/upgrade/basic_speed_module.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/upgrade/heat_pump_conversion.json create mode 100644 src/main/resources/data/lookingglass/recipes/manual/upgrade/rose_chipset.json diff --git a/gradle.properties b/gradle.properties index c45cdb9..5d3f945 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ minecraft_version=1.16.5 yarn_mappings=1.16.5+build.5 loader_version=0.11.2 # Mod Properties -mod_version=ALPHA.12 +mod_version=ALPHA.11 maven_group=azzy.ttlg archives_base_name=TTLG libgui_version=3.3.3+1.16.5 diff --git a/src/main/java/azzy/fabric/lookingglass/LookingGlassREIIntegration.java b/src/main/java/azzy/fabric/lookingglass/LookingGlassREIIntegration.java index 43684ab..8585457 100644 --- a/src/main/java/azzy/fabric/lookingglass/LookingGlassREIIntegration.java +++ b/src/main/java/azzy/fabric/lookingglass/LookingGlassREIIntegration.java @@ -2,14 +2,8 @@ import azzy.fabric.lookingglass.block.LookingGlassBlocks; import azzy.fabric.lookingglass.item.LookingGlassItems; -import azzy.fabric.lookingglass.recipe.AlloyingRecipe; -import azzy.fabric.lookingglass.recipe.FreezingRecipe; -import azzy.fabric.lookingglass.recipe.InductionRecipe; -import azzy.fabric.lookingglass.recipe.LookingGlassRecipes; -import azzy.fabric.lookingglass.util.rei.AlloyingRecipeCategory; -import azzy.fabric.lookingglass.util.rei.FreezingRecipeCategory; -import azzy.fabric.lookingglass.util.rei.InductionRecipeCategory; -import azzy.fabric.lookingglass.util.rei.LookingGlassRecipeDisplay; +import azzy.fabric.lookingglass.recipe.*; +import azzy.fabric.lookingglass.util.rei.*; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.RecipeHelper; import me.shedaniel.rei.api.plugins.REIPluginV0; @@ -23,6 +17,8 @@ public void registerRecipeDisplays(RecipeHelper recipeHelper) { recipeHelper.registerRecipes(LookingGlassRecipes.ALLOYING_RECIPE.getId(), AlloyingRecipe.class, LookingGlassRecipeDisplay::new); recipeHelper.registerRecipes(LookingGlassRecipes.INDUCTION_RECIPE.getId(), InductionRecipe.class, LookingGlassRecipeDisplay::new); recipeHelper.registerRecipes(LookingGlassRecipes.FREEZING_RECIPE.getId(), FreezingRecipe.class, LookingGlassRecipeDisplay::new); + recipeHelper.registerRecipes(LookingGlassRecipes.GRINDING_RECIPE.getId(), GrindingRecipe.class, LookingGlassRecipeDisplay::new); + recipeHelper.registerRecipes(LookingGlassRecipes.MIXING_RECIPE.getId(), MixingRecipe.class, LookingGlassRecipeDisplay::new); } @Override @@ -30,14 +26,20 @@ public void registerPluginCategories(RecipeHelper recipeHelper) { recipeHelper.registerCategory(new AlloyingRecipeCategory()); recipeHelper.registerCategory(new InductionRecipeCategory()); recipeHelper.registerCategory(new FreezingRecipeCategory()); + recipeHelper.registerCategory(new GrindingRecipeCategory()); + recipeHelper.registerCategory(new MixingRecipeCategory()); } @Override public void registerOthers(RecipeHelper recipeHelper) { recipeHelper.registerWorkingStations(DefaultPlugin.SMELTING, EntryStack.create(LookingGlassBlocks.POWERED_FURNACE_BLOCK)); - recipeHelper.registerWorkingStations(DefaultPlugin.BLASTING, EntryStack.create(LookingGlassItems.BLAST_UPGRADE_ITEM)); + recipeHelper.registerWorkingStations(LookingGlassRecipes.ALLOYING_RECIPE.getId(), EntryStack.create(LookingGlassBlocks.ALLOY_FURNACE_BLOCK)); recipeHelper.registerWorkingStations(LookingGlassRecipes.INDUCTION_RECIPE.getId(), EntryStack.create(LookingGlassBlocks.BLOCK_INDUCTOR_BLOCK)); + recipeHelper.registerWorkingStations(LookingGlassRecipes.GRINDING_RECIPE.getId(), EntryStack.create(LookingGlassBlocks.GRINDER_BLOCK)); + recipeHelper.registerWorkingStations(LookingGlassRecipes.MIXING_RECIPE.getId(), EntryStack.create(LookingGlassBlocks.MIXER_BLOCK)); + + recipeHelper.registerWorkingStations(DefaultPlugin.BLASTING, EntryStack.create(LookingGlassItems.BLAST_UPGRADE_ITEM)); recipeHelper.registerWorkingStations(LookingGlassRecipes.FREEZING_RECIPE.getId(), EntryStack.create(LookingGlassItems.FREEZER_UPGRADE_ITEM)); } diff --git a/src/main/java/azzy/fabric/lookingglass/block/BlockInductorBlock.java b/src/main/java/azzy/fabric/lookingglass/block/BlockInductorBlock.java index 4483ab5..1007e0e 100644 --- a/src/main/java/azzy/fabric/lookingglass/block/BlockInductorBlock.java +++ b/src/main/java/azzy/fabric/lookingglass/block/BlockInductorBlock.java @@ -3,8 +3,8 @@ import azzy.fabric.lookingglass.mixin.RecipeMapAccessor; import azzy.fabric.lookingglass.recipe.InductionRecipe; import azzy.fabric.lookingglass.recipe.LookingGlassRecipes; -import azzy.fabric.lookingglass.util.BlockEntityMover; -import azzy.fabric.lookingglass.util.FalseInventory; +import azzy.fabric.lookingglass.util.machine.BlockEntityMover; +import azzy.fabric.lookingglass.util.machine.FalseInventory; import azzy.fabric.lookingglass.util.LookingGlassSounds; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/azzy/fabric/lookingglass/block/HorizontalMachineBlock.java b/src/main/java/azzy/fabric/lookingglass/block/HorizontalMachineBlock.java index 93e412a..88c99a2 100644 --- a/src/main/java/azzy/fabric/lookingglass/block/HorizontalMachineBlock.java +++ b/src/main/java/azzy/fabric/lookingglass/block/HorizontalMachineBlock.java @@ -2,9 +2,13 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.block.ShapeContext; import net.minecraft.item.ItemPlacementContext; import net.minecraft.state.StateManager; import net.minecraft.state.property.Properties; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.BlockView; import org.jetbrains.annotations.Nullable; public class HorizontalMachineBlock extends LookingGlassBlock { @@ -25,4 +29,9 @@ protected void appendProperties(StateManager.Builder builder) builder.add(Properties.LIT); super.appendProperties(builder); } + + @Override + public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { + return super.getCollisionShape(state, world, pos, context); + } } diff --git a/src/main/java/azzy/fabric/lookingglass/block/LookingGlassBlocks.java b/src/main/java/azzy/fabric/lookingglass/block/LookingGlassBlocks.java index 04b221a..cf73766 100644 --- a/src/main/java/azzy/fabric/lookingglass/block/LookingGlassBlocks.java +++ b/src/main/java/azzy/fabric/lookingglass/block/LookingGlassBlocks.java @@ -90,7 +90,6 @@ private static FabricBlockSettings eldenMachine() { public static final Block PROJECTORBLOCK = registerBlock("projector", new ProjectorBlock(paleMachine().luminance(ignored -> 7)), basicItem()); public static final Block CHUNKLOADERBLOCK = registerBlock("chunkloader", new ChunkAnchorBlock(paleMachine().luminance(ignored -> 7)), basicItem()); public static final Block WORMHOLEBLOCK = registerBlock("wormhole", new WormholeBlock(paleMachine().luminance(ignored -> 5)), basicItem()); - public static final Block VACUUM_HOPPER_BLOCK = registerBlock("vacuum_hopper", new VacuumHopperBlock(dwarvenMachine(), 20, 4, 9), basicItem()); public static final Block ADVANCED_VACUUM_HOPPER_BLOCK = registerBlock("advanced_vacuum_hopper", new VacuumHopperBlock(hardenedMachine(), 5, 7, 27), advancedItem()); public static final Block BLOCK_TESSERACT_BLOCK = registerBlock("block_tesseract", new BlockTesseractBlock(eldenMachine().nonOpaque()), lategameItem()); public static final Block BLOCK_INDUCTOR_BLOCK = registerBlock("block_inductor", new BlockInductorBlock(basicMachine(BlockSoundGroup.STONE).nonOpaque().luminance(state -> state.get(AbstractInductorBlock.POWERED) ? 15 : 5)), basicItem()); @@ -100,6 +99,7 @@ private static FabricBlockSettings eldenMachine() { public static final Block ALLOY_FURNACE_BLOCK = registerBlock("alloy_furnace", new AlloyFurnaceBlock(dwarvenMachine()), basicItem()); public static final Block GRINDER_BLOCK = registerBlock("grinder", new GrinderBlock(dwarvenMachine()), basicItem()); public static final Block MIXER_BLOCK = registerBlock("mixer", new MixerBlock(dwarvenMachine()), basicItem()); + public static final Block VACUUM_HOPPER_BLOCK = registerBlock("vacuum_hopper", new VacuumHopperBlock(dwarvenMachine(), 20, 4, 9), basicItem()); //Power public static final Block CREATIVE_ENERGY_SOURCE_BLOCK = registerBlock("creative_energy_source", new CreativeEnergySourceBlock(paleMachine().nonOpaque().luminance(7).emissiveLighting((state, world, pos) -> true)), worldforgeItem()); diff --git a/src/main/java/azzy/fabric/lookingglass/blockentity/AlloyFurnaceEntity.java b/src/main/java/azzy/fabric/lookingglass/blockentity/AlloyFurnaceEntity.java index fb7c0af..237c0cf 100644 --- a/src/main/java/azzy/fabric/lookingglass/blockentity/AlloyFurnaceEntity.java +++ b/src/main/java/azzy/fabric/lookingglass/blockentity/AlloyFurnaceEntity.java @@ -56,22 +56,9 @@ public void tick() { private void tickRecipeProgression() { if(trackedRecipe != null) { if(progress >= getProcessTime()) { - ItemStack outSlot = inventory.get(2); - if(outSlot.isEmpty()) { - inventory.set(2, trackedRecipe.craft(this)); - inventory.get(1).decrement(1); - inventory.get(0).decrement(1); - progress = 0; - sync(); - } - ItemStack output = trackedRecipe.getOutput(); - if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) { - inventory.get(2).increment(output.getCount()); - inventory.get(1).decrement(1); - inventory.get(0).decrement(1); - progress = 0; - sync(); - } + trackedRecipe.craft(this); + progress = 0; + sync(); } else { double drain = getPowerUsage(); diff --git a/src/main/java/azzy/fabric/lookingglass/blockentity/BlockTesseractEntity.java b/src/main/java/azzy/fabric/lookingglass/blockentity/BlockTesseractEntity.java index 695dd1a..b0a789e 100644 --- a/src/main/java/azzy/fabric/lookingglass/blockentity/BlockTesseractEntity.java +++ b/src/main/java/azzy/fabric/lookingglass/blockentity/BlockTesseractEntity.java @@ -2,7 +2,7 @@ import azzy.fabric.lookingglass.block.LookingGlassBlocks; import azzy.fabric.lookingglass.render.TesseractRenderable; -import azzy.fabric.lookingglass.util.BlockEntityMover; +import azzy.fabric.lookingglass.util.machine.BlockEntityMover; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.minecraft.block.Block; import net.minecraft.block.BlockState; diff --git a/src/main/java/azzy/fabric/lookingglass/blockentity/GrinderEntity.java b/src/main/java/azzy/fabric/lookingglass/blockentity/GrinderEntity.java index d49e7de..05aec5c 100644 --- a/src/main/java/azzy/fabric/lookingglass/blockentity/GrinderEntity.java +++ b/src/main/java/azzy/fabric/lookingglass/blockentity/GrinderEntity.java @@ -1,10 +1,8 @@ package azzy.fabric.lookingglass.blockentity; import azzy.fabric.lookingglass.block.LookingGlassBlocks; -import azzy.fabric.lookingglass.gui.AlloyingFurnaceGuiDescription; import azzy.fabric.lookingglass.gui.GrinderGuiDescription; -import azzy.fabric.lookingglass.recipe.AlloyingRecipe; -import azzy.fabric.lookingglass.recipe.GrinderRecipe; +import azzy.fabric.lookingglass.recipe.GrindingRecipe; import azzy.fabric.lookingglass.recipe.LookingGlassRecipes; import io.github.cottonmc.cotton.gui.PropertyDelegateHolder; import net.minecraft.entity.player.PlayerEntity; @@ -23,7 +21,7 @@ @SuppressWarnings("unchecked") public class GrinderEntity extends LookingGlassUpgradeableMachine implements PropertyDelegateHolder { - private GrinderRecipe trackedRecipe; + private GrindingRecipe trackedRecipe; private int progress; public GrinderEntity() { @@ -34,7 +32,7 @@ public GrinderEntity() { public void tick() { if(!world.isClient()) { if(trackedRecipe == null) { - Optional recipeOptional = world.getRecipeManager().getFirstMatch(getRecipeType(), this, world); + Optional recipeOptional = world.getRecipeManager().getFirstMatch(getRecipeType(), this, world); recipeOptional.ifPresent(recipe -> trackedRecipe = recipe); tickRecipeProgression(); } @@ -60,40 +58,9 @@ public void tick() { private void tickRecipeProgression() { if(trackedRecipe != null) { if(progress >= getProcessTime()) { - ItemStack outSlot = inventory.get(1); - ItemStack secSlot = inventory.get(2); - List outputs = trackedRecipe.getOutputs(); - ItemStack output = outputs.get(0); - ItemStack secondary = outputs.get(1); - float chance = trackedRecipe.getChance(); - if(outSlot.isEmpty()) { - inventory.get(0).decrement(1); - inventory.set(1, output.copy()); - if(world.getRandom().nextFloat() <= chance) { - if(secSlot.isEmpty()) { - inventory.set(2, secondary.copy()); - } - else if(secSlot.getCount() + secondary.getCount() <= secSlot.getMaxCount() && secondary.isItemEqual(secSlot)) { - inventory.get(2).increment(secondary.getCount()); - } - } - progress = 0; - sync(); - } - if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) { - inventory.get(0).decrement(1); - inventory.get(1).increment(output.getCount()); - if(world.getRandom().nextFloat() <= chance) { - if(secSlot.isEmpty()) { - inventory.set(2, secondary.copy()); - } - else if(secSlot.getCount() + secondary.getCount() <= secSlot.getMaxCount() && secondary.isItemEqual(secSlot)) { - inventory.get(2).increment(secondary.getCount()); - } - } - progress = 0; - sync(); - } + trackedRecipe.craft(this); + progress = 0; + sync(); } else { double drain = getPowerUsage(); diff --git a/src/main/java/azzy/fabric/lookingglass/blockentity/LookingGlassUpgradeableMachine.java b/src/main/java/azzy/fabric/lookingglass/blockentity/LookingGlassUpgradeableMachine.java index 3aabbdd..0563e8b 100644 --- a/src/main/java/azzy/fabric/lookingglass/blockentity/LookingGlassUpgradeableMachine.java +++ b/src/main/java/azzy/fabric/lookingglass/blockentity/LookingGlassUpgradeableMachine.java @@ -1,7 +1,7 @@ package azzy.fabric.lookingglass.blockentity; -import azzy.fabric.lookingglass.util.ModifierProvider; -import azzy.fabric.lookingglass.util.RecipeConversionProvider; +import azzy.fabric.lookingglass.util.machine.ModifierProvider; +import azzy.fabric.lookingglass.util.machine.RecipeConversionProvider; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; diff --git a/src/main/java/azzy/fabric/lookingglass/blockentity/MixerEntity.java b/src/main/java/azzy/fabric/lookingglass/blockentity/MixerEntity.java index 3ecd0e5..1042491 100644 --- a/src/main/java/azzy/fabric/lookingglass/blockentity/MixerEntity.java +++ b/src/main/java/azzy/fabric/lookingglass/blockentity/MixerEntity.java @@ -1,11 +1,9 @@ package azzy.fabric.lookingglass.blockentity; import azzy.fabric.lookingglass.block.LookingGlassBlocks; -import azzy.fabric.lookingglass.gui.AlloyingFurnaceGuiDescription; import azzy.fabric.lookingglass.gui.MixerGuiDescription; -import azzy.fabric.lookingglass.recipe.AlloyingRecipe; import azzy.fabric.lookingglass.recipe.LookingGlassRecipes; -import azzy.fabric.lookingglass.recipe.MixerRecipe; +import azzy.fabric.lookingglass.recipe.MixingRecipe; import io.github.cottonmc.cotton.gui.PropertyDelegateHolder; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; @@ -22,7 +20,7 @@ @SuppressWarnings("unchecked") public class MixerEntity extends LookingGlassUpgradeableMachine implements PropertyDelegateHolder { - private MixerRecipe trackedRecipe; + private MixingRecipe trackedRecipe; private int progress; public MixerEntity() { @@ -33,7 +31,7 @@ public MixerEntity() { public void tick() { if(!world.isClient()) { if(trackedRecipe == null) { - Optional recipeOptional = world.getRecipeManager().getFirstMatch(getRecipeType(), this, world); + Optional recipeOptional = world.getRecipeManager().getFirstMatch(getRecipeType(), this, world); recipeOptional.ifPresent(recipe -> trackedRecipe = recipe); tickRecipeProgression(); } @@ -59,26 +57,9 @@ public void tick() { private void tickRecipeProgression() { if(trackedRecipe != null) { if(progress >= getProcessTime()) { - ItemStack outSlot = inventory.get(4); - if(outSlot.isEmpty()) { - inventory.set(4, trackedRecipe.craft(this)); - inventory.get(3).decrement(1); - inventory.get(2).decrement(1); - inventory.get(1).decrement(1); - inventory.get(0).decrement(1); - progress = 0; - sync(); - } - ItemStack output = trackedRecipe.getOutput(); - if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) { - inventory.get(4).increment(output.getCount()); - inventory.get(3).decrement(1); - inventory.get(2).decrement(1); - inventory.get(1).decrement(1); - inventory.get(0).decrement(1); - progress = 0; - sync(); - } + trackedRecipe.craft(this); + progress = 0; + sync(); } else { double drain = getPowerUsage(); diff --git a/src/main/java/azzy/fabric/lookingglass/blockentity/PoweredFurnaceEntity.java b/src/main/java/azzy/fabric/lookingglass/blockentity/PoweredFurnaceEntity.java index adb0ca0..3ef601a 100644 --- a/src/main/java/azzy/fabric/lookingglass/blockentity/PoweredFurnaceEntity.java +++ b/src/main/java/azzy/fabric/lookingglass/blockentity/PoweredFurnaceEntity.java @@ -58,17 +58,24 @@ public void tick() { private void tickRecipeProgression() { if(trackedRecipe != null) { if(progress >= getProcessTime()) { - ItemStack outSlot = inventory.get(1); - if(outSlot.isEmpty()) { - inventory.set(1, trackedRecipe.craft(this)); - inventory.get(0).decrement(1); - progress = 0; - sync(); + if(trackedRecipe.getType() == RecipeType.SMELTING || trackedRecipe.getType() == RecipeType.BLASTING) { + ItemStack outSlot = inventory.get(1); + if(outSlot.isEmpty()) { + inventory.set(1, trackedRecipe.craft(this)); + inventory.get(0).decrement(1); + progress = 0; + sync(); + } + ItemStack output = trackedRecipe.getOutput(); + if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) { + inventory.get(1).increment(output.getCount()); + inventory.get(0).decrement(1); + progress = 0; + sync(); + } } - ItemStack output = trackedRecipe.getOutput(); - if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) { - inventory.get(1).increment(output.getCount()); - inventory.get(0).decrement(1); + else { + trackedRecipe.craft(this); progress = 0; sync(); } diff --git a/src/main/java/azzy/fabric/lookingglass/blockentity/VacuumHopperEntity.java b/src/main/java/azzy/fabric/lookingglass/blockentity/VacuumHopperEntity.java index f2a62d0..6c46ac0 100644 --- a/src/main/java/azzy/fabric/lookingglass/blockentity/VacuumHopperEntity.java +++ b/src/main/java/azzy/fabric/lookingglass/blockentity/VacuumHopperEntity.java @@ -29,7 +29,7 @@ public VacuumHopperEntity(BlockEntityType type, int invSize, int delay, int r @Override public void tick() { if(!world.isClient() && !getCachedState().get(LookingGlassBlock.POWERED) && (world.getTime() + offset) % delay == 0) { - List itemEntities = world.getEntitiesByType(EntityType.ITEM, new Box(pos.add(-radius, -radius, -radius), pos.add(radius, radius, radius)), ignored -> true); + List itemEntities = world.getEntitiesByType(EntityType.ITEM, new Box(pos.add(-radius, -radius, -radius), pos.add(radius + 1, radius + 1, radius + 1)), ignored -> true); entityCheck: for (ItemEntity itemEntity : itemEntities) { ItemStack stack = itemEntity.getStack(); diff --git a/src/main/java/azzy/fabric/lookingglass/gui/UpgradeableMachineGuiDescription.java b/src/main/java/azzy/fabric/lookingglass/gui/UpgradeableMachineGuiDescription.java index 8beeb7e..0a8a675 100644 --- a/src/main/java/azzy/fabric/lookingglass/gui/UpgradeableMachineGuiDescription.java +++ b/src/main/java/azzy/fabric/lookingglass/gui/UpgradeableMachineGuiDescription.java @@ -1,10 +1,8 @@ package azzy.fabric.lookingglass.gui; -import azzy.fabric.lookingglass.LookingGlassCommon; -import azzy.fabric.lookingglass.util.ModifierProvider; +import azzy.fabric.lookingglass.util.machine.ModifierProvider; import azzy.fabric.lookingglass.util.client.BackgroundType; import io.github.cottonmc.cotton.gui.SyncedGuiDescription; -import io.github.cottonmc.cotton.gui.client.BackgroundPainter; import io.github.cottonmc.cotton.gui.widget.WBar; import io.github.cottonmc.cotton.gui.widget.WItemSlot; import io.github.cottonmc.cotton.gui.widget.WPlainPanel; diff --git a/src/main/java/azzy/fabric/lookingglass/item/GenericUpgradeItem.java b/src/main/java/azzy/fabric/lookingglass/item/GenericUpgradeItem.java index 4bb6981..b678460 100644 --- a/src/main/java/azzy/fabric/lookingglass/item/GenericUpgradeItem.java +++ b/src/main/java/azzy/fabric/lookingglass/item/GenericUpgradeItem.java @@ -2,9 +2,7 @@ import azzy.fabric.lookingglass.blockentity.LookingGlassMachine; import azzy.fabric.lookingglass.gui.UpgradeableMachineGuiDescription; -import azzy.fabric.lookingglass.util.ModifierProvider; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.block.entity.BlockEntityType; +import azzy.fabric.lookingglass.util.machine.ModifierProvider; import net.minecraft.item.Item; public class GenericUpgradeItem extends Item implements ModifierProvider { diff --git a/src/main/java/azzy/fabric/lookingglass/item/LookingGlassItems.java b/src/main/java/azzy/fabric/lookingglass/item/LookingGlassItems.java index 2a159da..85fc359 100644 --- a/src/main/java/azzy/fabric/lookingglass/item/LookingGlassItems.java +++ b/src/main/java/azzy/fabric/lookingglass/item/LookingGlassItems.java @@ -4,7 +4,7 @@ import azzy.fabric.lookingglass.blockentity.LookingGlassMachine; import azzy.fabric.lookingglass.gui.PoweredFurnaceGuiDescription; import azzy.fabric.lookingglass.recipe.LookingGlassRecipes; -import azzy.fabric.lookingglass.util.ModifierProvider; +import azzy.fabric.lookingglass.util.machine.ModifierProvider; import azzy.fabric.lookingglass.util.datagen.ModelJsonGen; import dev.emi.trinkets.api.SlotGroups; import dev.emi.trinkets.api.Slots; @@ -51,6 +51,8 @@ private static FabricItemSettings eldenmetalSettings() { public static final Item BASE_RING = registerGeneratedItem("ring", new Item(defaultSettings().rarity(Rarity.UNCOMMON).maxCount(8))); public static final Item SIMPLE_ANGEL_RING = registerItem("simple_angel_ring", new SimpleAngelRingItem(new FabricItemSettings().group(LOOKINGGLASS_ITEMS).rarity(FINIS_RARITY).maxCount(1))); public static final Item ADVANCED_ANGEL_RING = registerItem("advanced_angel_ring", new AdvancedAngelRingItem(new FabricItemSettings().group(LOOKINGGLASS_ITEMS).rarity(LUPREVAN_RARITY).fireproof().maxCount(1))); + public static final Item GOLDEN_LASSO = registerItem("golden_lasso", new LassoItem(defaultSettings(), false)); + public static final Item CURSED_LASSO = registerItem("cursed_lasso", new LassoItem(defaultSettings(), true)); //Upgrades public static final Item ROSE_CHIPSET = registerGeneratedItem("rose_chipset", new Item(defaultSettings())); @@ -63,7 +65,8 @@ private static FabricItemSettings eldenmetalSettings() { //Materials public static final Item FISH_FEED = registerItem("fish_feed", new Item(defaultSettings().food(BAD_NOMS))); public static final Item DWARVEN_CLAY = registerGeneratedItem("dwarven_clay", new Item(defaultSettings())); - public static final Item RED_SILICON_INGOT = registerGeneratedItem("red_silicon_ingot", new Item(defaultSettings())); + public static final Item SILICON_INGOT = registerGeneratedItem("red_silicon_ingot", new Item(defaultSettings())); + public static final Item SILICON_INDUCTION_COIL = registerGeneratedItem("silicon_induction_coil", new Item(defaultSettings())); public static final Item ROSE_GOLD_INGOT = registerGeneratedItem("rose_gold_ingot", new Item(defaultSettings())); public static final Item ROSE_GOLD_NUGGET = registerGeneratedItem("rose_gold_nugget", new Item(defaultSettings())); public static final Item CELESTIAL_AMALGAM = registerGeneratedItem("celestial_amalgam", new Item(genericSettings(FINIS_RARITY))); @@ -87,8 +90,6 @@ private static FabricItemSettings eldenmetalSettings() { public static final Item SLOW_VECTOR_PLATE_BLOCK = registerItem("slow_vector_plate", new VectorPlateBlockItem(LookingGlassBlocks.SLOW_VECTOR_PLATE_BLOCK, new FabricItemSettings().group(LOOKINGGLASS_BLOCKS))); public static final Item NORMAL_VECTOR_PLATE_BLOCK = registerItem("normal_vector_plate", new VectorPlateBlockItem(LookingGlassBlocks.NORMAL_VECTOR_PLATE_BLOCK, new FabricItemSettings().group(LOOKINGGLASS_BLOCKS))); public static final Item FAST_VECTOR_PLATE_BLOCK = registerItem("fast_vector_plate", new VectorPlateBlockItem(LookingGlassBlocks.FAST_VECTOR_PLATE_BLOCK, new FabricItemSettings().group(LOOKINGGLASS_BLOCKS))); - public static final Item GOLDEN_LASSO = registerItem("golden_lasso", new LassoItem(defaultSettings(), false)); - public static final Item CURSED_LASSO = registerItem("cursed_lasso", new LassoItem(defaultSettings(), true)); private static Item registerItem(String name, Item item) { return Registry.register(Registry.ITEM, new Identifier(MODID, name), item); diff --git a/src/main/java/azzy/fabric/lookingglass/item/RecipeConvertingUpgradeItem.java b/src/main/java/azzy/fabric/lookingglass/item/RecipeConvertingUpgradeItem.java index b498769..98f9481 100644 --- a/src/main/java/azzy/fabric/lookingglass/item/RecipeConvertingUpgradeItem.java +++ b/src/main/java/azzy/fabric/lookingglass/item/RecipeConvertingUpgradeItem.java @@ -1,10 +1,8 @@ package azzy.fabric.lookingglass.item; import azzy.fabric.lookingglass.blockentity.LookingGlassMachine; -import azzy.fabric.lookingglass.gui.PoweredFurnaceGuiDescription; import azzy.fabric.lookingglass.gui.UpgradeableMachineGuiDescription; -import azzy.fabric.lookingglass.recipe.LookingGlassRecipe; -import azzy.fabric.lookingglass.util.RecipeConversionProvider; +import azzy.fabric.lookingglass.util.machine.RecipeConversionProvider; import net.minecraft.recipe.RecipeType; public class RecipeConvertingUpgradeItem extends GenericUpgradeItem implements RecipeConversionProvider { diff --git a/src/main/java/azzy/fabric/lookingglass/mixin/IngredientMixin.java b/src/main/java/azzy/fabric/lookingglass/mixin/IngredientMixin.java new file mode 100644 index 0000000..dd0b905 --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/mixin/IngredientMixin.java @@ -0,0 +1,21 @@ +package azzy.fabric.lookingglass.mixin; + +import azzy.fabric.lookingglass.util.MatchingStackAccessor; +import net.minecraft.item.ItemStack; +import net.minecraft.recipe.Ingredient; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(Ingredient.class) +public abstract class IngredientMixin implements MatchingStackAccessor { + + @Shadow protected abstract void cacheMatchingStacks(); + + @Shadow private ItemStack[] matchingStacks; + + @Override + public ItemStack[] getMatchingStacks() { + cacheMatchingStacks(); + return matchingStacks; + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/recipe/AlloyingRecipe.java b/src/main/java/azzy/fabric/lookingglass/recipe/AlloyingRecipe.java index e69988c..4839b25 100644 --- a/src/main/java/azzy/fabric/lookingglass/recipe/AlloyingRecipe.java +++ b/src/main/java/azzy/fabric/lookingglass/recipe/AlloyingRecipe.java @@ -2,6 +2,8 @@ import azzy.fabric.lookingglass.block.LookingGlassBlocks; import azzy.fabric.lookingglass.blockentity.AlloyFurnaceEntity; +import azzy.fabric.lookingglass.util.IngredientStack; +import azzy.fabric.lookingglass.util.json.JsonUtils; import com.google.gson.JsonObject; import net.fabricmc.loader.lib.gson.MalformedJsonException; import net.minecraft.item.Item; @@ -14,6 +16,7 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.World; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -21,26 +24,32 @@ public class AlloyingRecipe implements LookingGlassRecipe { - private final Ingredient inputA, inputB; + private final List ingredients; private final ItemStack output; private final Identifier id; - public AlloyingRecipe(Identifier id, Ingredient inputA, Ingredient inputB, ItemStack output) { - this.inputA = inputA; - this.inputB = inputB; + public AlloyingRecipe(Identifier id, List ingredients, ItemStack output) { + this.ingredients = ingredients; this.output = output; this.id = id; } @Override public boolean matches(AlloyFurnaceEntity inv, World world) { - ItemStack a = inv.getStack(0); - ItemStack b = inv.getStack(1); - return ((inputA.test(a)) ^ (inputA.test(b))) && ((inputB.test(a)) ^ (inputB.test(b))); + return IngredientStack.matchInvExclusively(inv, ingredients, 2, 0); } @Override public ItemStack craft(AlloyFurnaceEntity inv) { + ItemStack outSlot = inv.getStack(2); + if(outSlot.isEmpty()) { + inv.setStack(2, output.copy()); + IngredientStack.decrementExclusively(inv, ingredients, 2, 0); + } + else if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) { + inv.getStack(2).increment(output.getCount()); + IngredientStack.decrementExclusively(inv, ingredients, 2, 0); + } return output.copy(); } @@ -66,10 +75,7 @@ public ItemStack getRecipeKindIcon() { @Override public DefaultedList getPreviewInputs() { - DefaultedList inputs = DefaultedList.of(); - inputs.add(inputA); - inputs.add(inputB); - return inputs; + return IngredientStack.listIngredients(ingredients); } @Override @@ -88,8 +94,8 @@ public LookingGlassRecipeType getType() { } @Override - public List getInputs() { - return Arrays.asList(inputA, inputB); + public List getInputs() { + return ingredients; } public static class AlloyingRecipeSerializer implements RecipeSerializer { @@ -97,39 +103,31 @@ public static class AlloyingRecipeSerializer implements RecipeSerializer ingredients; + ItemStack output; try { - if(!(json.has("inputA") && json.has("inputB") && json.has("output"))) + if(!(json.has("inputs") && json.has("output"))) throw new MalformedJsonException("Invalid Alloying Recipe Json"); - inputA = Ingredient.fromJson(json.get("inputA")); - inputB = Ingredient.fromJson(json.get("inputB")); - output = Registry.ITEM.get(Identifier.tryParse(json.get("output").getAsString())); - count = json.has("count") ? json.get("count").getAsInt() : 1; + ingredients = JsonUtils.ingredientsFromJson(json.getAsJsonArray("inputs"), 2); + output = JsonUtils.stackFromJson(json.getAsJsonObject("output")); } catch (Exception e) { FFLog.error("Exception found while loading Alloying recipe json " + id.toString() + " ", e); return null; } - return new AlloyingRecipe(id, inputA, inputB, new ItemStack(output, count)); + return new AlloyingRecipe(id, ingredients, output); } @Override public AlloyingRecipe read(Identifier id, PacketByteBuf buf) { - ItemStack output = buf.readItemStack(); - Ingredient inputA = Ingredient.fromPacket(buf); - Ingredient inputB = Ingredient.fromPacket(buf); - return new AlloyingRecipe(id, inputA, inputB, output); + return new AlloyingRecipe(id, IngredientStack.decodeByteBuf(buf, 2), buf.readItemStack()); } @Override public void write(PacketByteBuf buf, AlloyingRecipe recipe) { + recipe.getInputs().forEach(ingredientStack -> ingredientStack.write(buf)); buf.writeItemStack(recipe.output); - recipe.inputA.write(buf); - recipe.inputB.write(buf); } } } diff --git a/src/main/java/azzy/fabric/lookingglass/recipe/FreezingRecipe.java b/src/main/java/azzy/fabric/lookingglass/recipe/FreezingRecipe.java index b677aa9..97ca5fd 100644 --- a/src/main/java/azzy/fabric/lookingglass/recipe/FreezingRecipe.java +++ b/src/main/java/azzy/fabric/lookingglass/recipe/FreezingRecipe.java @@ -3,6 +3,8 @@ import azzy.fabric.lookingglass.block.LookingGlassBlocks; import azzy.fabric.lookingglass.blockentity.AlloyFurnaceEntity; import azzy.fabric.lookingglass.blockentity.PoweredFurnaceEntity; +import azzy.fabric.lookingglass.util.IngredientStack; +import azzy.fabric.lookingglass.util.json.JsonUtils; import com.google.gson.JsonObject; import net.fabricmc.loader.lib.gson.MalformedJsonException; import net.minecraft.item.Item; @@ -15,6 +17,7 @@ import net.minecraft.util.registry.Registry; import net.minecraft.world.World; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -23,11 +26,11 @@ public class FreezingRecipe implements LookingGlassRecipe { - private final Ingredient input; + private final IngredientStack input; private final ItemStack output; private final Identifier id; - public FreezingRecipe(Identifier id, Ingredient input, ItemStack output) { + public FreezingRecipe(Identifier id, IngredientStack input, ItemStack output) { this.input = input; this.output = output; this.id = id; @@ -40,6 +43,15 @@ public boolean matches(PoweredFurnaceEntity inv, World world) { @Override public ItemStack craft(PoweredFurnaceEntity inv) { + ItemStack outSlot = inv.getStack(1); + if(outSlot.isEmpty()) { + inv.setStack(1, output.copy()); + inv.getStack(0).decrement(input.getCount()); + } + else if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) { + inv.getStack(1).increment(output.getCount()); + inv.getStack(0).decrement(input.getCount()); + } return output.copy(); } @@ -60,9 +72,7 @@ public ItemStack getRecipeKindIcon() { @Override public DefaultedList getPreviewInputs() { - DefaultedList inputs = DefaultedList.of(); - inputs.add(input); - return inputs; + return IngredientStack.listIngredients(Collections.singletonList(input)); } @Override @@ -81,7 +91,7 @@ public LookingGlassRecipeType getType() { } @Override - public List getInputs() { + public List getInputs() { return Collections.singletonList(input); } @@ -90,28 +100,26 @@ public static class FreezingRecipeSerializer implements RecipeSerializer { - - private final Ingredient input; - private final ItemStack outputTop, outputBottom; - private final float chance; - private final Identifier id; - - public GrinderRecipe(Identifier id, Ingredient input, ItemStack outputTop, ItemStack outputBottom, float chance) { - this.input = input; - this.outputTop = outputTop; - this.outputBottom = outputBottom; - this.chance = chance; - this.id = id; - } - - @Override - public boolean matches(GrinderEntity inv, World world) { - return input.test(inv.getStack(0)); - } - - @Override - public ItemStack craft(GrinderEntity inv) { - return outputTop.copy(); - } - - @Override - public boolean fits(int width, int height) { - return true; - } - - @Override - public ItemStack getOutput() { - return outputTop; - } - - @Override - public ItemStack getRecipeKindIcon() { - return new ItemStack(LookingGlassBlocks.GRINDER_BLOCK); - } - - @Override - public DefaultedList getPreviewInputs() { - DefaultedList inputs = DefaultedList.of(); - inputs.add(input); - return inputs; - } - - @Override - public Identifier getId() { - return id; - } - - @Override - public RecipeSerializer getSerializer() { - return LookingGlassRecipes.GRINDING_SERIALIZER; - } - - @Override - public LookingGlassRecipeType getType() { - return LookingGlassRecipes.GRINDING_RECIPE; - } - - @Override - public List getInputs() { - return Collections.singletonList(input); - } - - @Override - public List getOutputs() { - return Arrays.asList(outputTop, outputBottom); - } - - public float getChance() { - return chance; - } - - public static class GrinderRecipeSerializer implements RecipeSerializer { - - @Override - public GrinderRecipe read(Identifier id, JsonObject json) { - Ingredient input; - Item outputTop, outputBottom; - float chance; - int countTop, countBottom; - - try { - if(!(json.has("outputTop") && json.has("input"))) - throw new MalformedJsonException("Invalid Grinding Recipe Json"); - input = Ingredient.fromJson(json.get("input")); - outputTop = Registry.ITEM.get(Identifier.tryParse(json.get("outputTop").getAsString())); - outputBottom = Registry.ITEM.get(Identifier.tryParse(json.get("outputBottom").getAsString())); - countTop = json.has("countTop") ? json.get("countTop").getAsInt() : 1; - countBottom = json.has("countBottom") ? json.get("countBottom").getAsInt() : 1; - chance = json.get("chance").getAsFloat(); - } catch (Exception e) { - FFLog.error("Exception found while loading Grinding recipe json " + id.toString() + " ", e); - return null; - } - - ItemStack secOut = outputBottom == Items.AIR ? ItemStack.EMPTY : new ItemStack(outputBottom, countBottom); - return new GrinderRecipe(id, input, new ItemStack(outputTop, countTop), secOut, chance); - } - - @Override - public GrinderRecipe read(Identifier id, PacketByteBuf buf) { - ItemStack outputTop = buf.readItemStack(); - ItemStack outputBottom = buf.readItemStack(); - float chance = buf.readFloat(); - Ingredient input = Ingredient.fromPacket(buf); - return new GrinderRecipe(id, input, outputTop, outputBottom, chance); - } - - @Override - public void write(PacketByteBuf buf, GrinderRecipe recipe) { - buf.writeItemStack(recipe.outputTop); - buf.writeItemStack(recipe.getOutput()); - buf.writeFloat(recipe.chance); - recipe.input.write(buf); - } - } -} diff --git a/src/main/java/azzy/fabric/lookingglass/recipe/GrindingRecipe.java b/src/main/java/azzy/fabric/lookingglass/recipe/GrindingRecipe.java new file mode 100644 index 0000000..3fa145d --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/recipe/GrindingRecipe.java @@ -0,0 +1,162 @@ +package azzy.fabric.lookingglass.recipe; + +import azzy.fabric.lookingglass.block.LookingGlassBlocks; +import azzy.fabric.lookingglass.blockentity.GrinderEntity; +import azzy.fabric.lookingglass.util.IngredientStack; +import azzy.fabric.lookingglass.util.json.JsonUtils; +import com.google.gson.JsonObject; +import net.fabricmc.loader.lib.gson.MalformedJsonException; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.recipe.Ingredient; +import net.minecraft.recipe.RecipeSerializer; +import net.minecraft.util.Identifier; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.world.World; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static azzy.fabric.lookingglass.LookingGlassCommon.FFLog; + +public class GrindingRecipe implements LookingGlassRecipe { + + private final IngredientStack input; + private final ItemStack mainOutput, secondaryOutput; + private final float chance; + private final Identifier id; + + public GrindingRecipe(Identifier id, IngredientStack input, ItemStack outputTop, ItemStack outputBottom, float chance) { + this.input = input; + this.mainOutput = outputTop; + this.secondaryOutput = outputBottom; + this.chance = chance; + this.id = id; + } + + @Override + public boolean matches(GrinderEntity inv, World world) { + return input.test(inv.getStack(0)); + } + + @Override + public ItemStack craft(GrinderEntity inv) { + ItemStack outSlot = inv.getStack(1); + ItemStack secSlot = inv.getStack(2); + if(outSlot.isEmpty()) { + inv.setStack(1, mainOutput.copy()); + inv.getStack(0).decrement(input.getCount()); + if(inv.getWorld().getRandom().nextFloat() <= chance) { + if(secSlot.isEmpty()) { + inv.setStack(2, secondaryOutput.copy()); + } + else if(secSlot.getCount() + secSlot.getCount() <= secSlot.getMaxCount() && secSlot.isItemEqual(secSlot)) { + inv.getStack(2).increment(secondaryOutput.getCount()); + } + } + } + else if(outSlot.getCount() + mainOutput.getCount() <= outSlot.getMaxCount() && mainOutput.isItemEqual(outSlot)) { + inv.getStack(1).increment(mainOutput.getCount()); + inv.getStack(0).decrement(input.getCount()); + if(inv.getWorld().getRandom().nextFloat() <= chance) { + if(secSlot.isEmpty()) { + inv.setStack(2, secondaryOutput.copy()); + } + else if(secSlot.getCount() + secSlot.getCount() <= secSlot.getMaxCount() && secSlot.isItemEqual(secSlot)) { + inv.getStack(2).increment(secondaryOutput.getCount()); + } + } + } + return mainOutput.copy(); + } + + @Override + public boolean fits(int width, int height) { + return true; + } + + @Override + public ItemStack getOutput() { + return mainOutput; + } + + @Override + public ItemStack getRecipeKindIcon() { + return new ItemStack(LookingGlassBlocks.GRINDER_BLOCK); + } + + @Override + public DefaultedList getPreviewInputs() { + return IngredientStack.listIngredients(Collections.singletonList(input)); + } + + @Override + public Identifier getId() { + return id; + } + + @Override + public RecipeSerializer getSerializer() { + return LookingGlassRecipes.GRINDING_SERIALIZER; + } + + @Override + public LookingGlassRecipeType getType() { + return LookingGlassRecipes.GRINDING_RECIPE; + } + + @Override + public List getInputs() { + return Collections.singletonList(input); + } + + @Override + public List getOutputs() { + return Arrays.asList(mainOutput, secondaryOutput); + } + + public float getChance() { + return chance; + } + + public static class GrindingRecipeSerializer implements RecipeSerializer { + + @Override + public GrindingRecipe read(Identifier id, JsonObject json) { + IngredientStack input; + ItemStack output, secondary; + float chance; + + try { + if(!(json.has("output") && json.has("input"))) + throw new MalformedJsonException("Invalid Grinding Recipe Json"); + input = JsonUtils.ingredientFromJson(json.getAsJsonObject("input")); + output = JsonUtils.stackFromJson(json.getAsJsonObject("output")); + secondary = JsonUtils.stackFromJson(json.getAsJsonObject("secondary")); + chance = json.get("chance").getAsFloat(); + } catch (Exception e) { + FFLog.error("Exception found while loading Grinding recipe json " + id.toString() + " ", e); + return null; + } + return new GrindingRecipe(id, input, output, secondary, chance); + } + + @Override + public GrindingRecipe read(Identifier id, PacketByteBuf buf) { + ItemStack outputTop = buf.readItemStack(); + ItemStack outputBottom = buf.readItemStack(); + IngredientStack input = IngredientStack.fromByteBuf(buf); + float chance = buf.readFloat(); + return new GrindingRecipe(id, input, outputTop, outputBottom, chance); + } + + @Override + public void write(PacketByteBuf buf, GrindingRecipe recipe) { + buf.writeItemStack(recipe.mainOutput); + buf.writeItemStack(recipe.secondaryOutput); + recipe.input.write(buf); + buf.writeFloat(recipe.chance); + } + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/recipe/InductionRecipe.java b/src/main/java/azzy/fabric/lookingglass/recipe/InductionRecipe.java index 149181d..aa86541 100644 --- a/src/main/java/azzy/fabric/lookingglass/recipe/InductionRecipe.java +++ b/src/main/java/azzy/fabric/lookingglass/recipe/InductionRecipe.java @@ -2,6 +2,7 @@ import azzy.fabric.lookingglass.block.BlockInductorBlock; import azzy.fabric.lookingglass.block.LookingGlassBlocks; +import azzy.fabric.lookingglass.util.IngredientStack; import com.google.gson.JsonObject; import net.fabricmc.loader.lib.gson.MalformedJsonException; import net.minecraft.block.Block; @@ -84,8 +85,8 @@ public LookingGlassRecipeType getType() { } @Override - public List getInputs() { - return Arrays.stream(inputs).map(Ingredient::ofItems).collect(Collectors.toList()); + public List getInputs() { + return Arrays.stream(inputs).map(Ingredient::ofItems).map(IngredientStack::of).collect(Collectors.toList()); } @Override diff --git a/src/main/java/azzy/fabric/lookingglass/recipe/LookingGlassRecipe.java b/src/main/java/azzy/fabric/lookingglass/recipe/LookingGlassRecipe.java index 0333401..332c3a7 100644 --- a/src/main/java/azzy/fabric/lookingglass/recipe/LookingGlassRecipe.java +++ b/src/main/java/azzy/fabric/lookingglass/recipe/LookingGlassRecipe.java @@ -1,5 +1,6 @@ package azzy.fabric.lookingglass.recipe; +import azzy.fabric.lookingglass.util.IngredientStack; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.recipe.Ingredient; @@ -14,7 +15,7 @@ public interface LookingGlassRecipe extends Recipe { @Override LookingGlassRecipeType getType(); - List getInputs(); + List getInputs(); @Override default String getGroup() { diff --git a/src/main/java/azzy/fabric/lookingglass/recipe/LookingGlassRecipes.java b/src/main/java/azzy/fabric/lookingglass/recipe/LookingGlassRecipes.java index 32b485d..2513617 100644 --- a/src/main/java/azzy/fabric/lookingglass/recipe/LookingGlassRecipes.java +++ b/src/main/java/azzy/fabric/lookingglass/recipe/LookingGlassRecipes.java @@ -3,7 +3,6 @@ import azzy.fabric.lookingglass.LookingGlassCommon; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeSerializer; -import net.minecraft.recipe.RecipeType; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; @@ -14,14 +13,14 @@ public static void init() {} public static final LookingGlassRecipeType INDUCTION_RECIPE = registerType("induction"); public static final LookingGlassRecipeType ALLOYING_RECIPE = registerType("alloying"); public static final LookingGlassRecipeType FREEZING_RECIPE = registerType("freezing"); - public static final LookingGlassRecipeType GRINDING_RECIPE = registerType("grinding"); - public static final LookingGlassRecipeType MIXING_RECIPE = registerType("mixing"); + public static final LookingGlassRecipeType GRINDING_RECIPE = registerType("grinding"); + public static final LookingGlassRecipeType MIXING_RECIPE = registerType("mixing"); public static final InductionRecipe.InductionRecipeSerializer INDUCTION_SERIALIZER = registerSerializer("induction", new InductionRecipe.InductionRecipeSerializer()); public static final AlloyingRecipe.AlloyingRecipeSerializer ALLOYING_SERIALIZER = registerSerializer("alloying", new AlloyingRecipe.AlloyingRecipeSerializer()); public static final FreezingRecipe.FreezingRecipeSerializer FREEZING_SERIALIZER = registerSerializer("freezing", new FreezingRecipe.FreezingRecipeSerializer()); - public static final GrinderRecipe.GrinderRecipeSerializer GRINDING_SERIALIZER = registerSerializer("grinding", new GrinderRecipe.GrinderRecipeSerializer()); - public static final MixerRecipe.MixerRecipeSerializer MIXING_SERIALIZER = registerSerializer("mixing", new MixerRecipe.MixerRecipeSerializer()); + public static final GrindingRecipe.GrindingRecipeSerializer GRINDING_SERIALIZER = registerSerializer("grinding", new GrindingRecipe.GrindingRecipeSerializer()); + public static final MixingRecipe.MixingRecipeSerializer MIXING_SERIALIZER = registerSerializer("mixing", new MixingRecipe.MixingRecipeSerializer()); public static > LookingGlassRecipeType registerType(String name) { final Identifier id = new Identifier(LookingGlassCommon.MODID, name); diff --git a/src/main/java/azzy/fabric/lookingglass/recipe/MixerRecipe.java b/src/main/java/azzy/fabric/lookingglass/recipe/MixingRecipe.java similarity index 59% rename from src/main/java/azzy/fabric/lookingglass/recipe/MixerRecipe.java rename to src/main/java/azzy/fabric/lookingglass/recipe/MixingRecipe.java index ff46cf3..a92c484 100644 --- a/src/main/java/azzy/fabric/lookingglass/recipe/MixerRecipe.java +++ b/src/main/java/azzy/fabric/lookingglass/recipe/MixingRecipe.java @@ -1,37 +1,32 @@ package azzy.fabric.lookingglass.recipe; import azzy.fabric.lookingglass.block.LookingGlassBlocks; +import azzy.fabric.lookingglass.blockentity.AlloyFurnaceEntity; import azzy.fabric.lookingglass.blockentity.MixerEntity; import azzy.fabric.lookingglass.util.BufUtils; +import azzy.fabric.lookingglass.util.IngredientStack; import azzy.fabric.lookingglass.util.json.JsonUtils; -import com.google.gson.JsonArray; import com.google.gson.JsonObject; import net.fabricmc.loader.lib.gson.MalformedJsonException; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; import net.minecraft.network.PacketByteBuf; import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.RecipeSerializer; import net.minecraft.util.Identifier; import net.minecraft.util.collection.DefaultedList; -import net.minecraft.util.registry.Registry; import net.minecraft.world.World; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; import static azzy.fabric.lookingglass.LookingGlassCommon.FFLog; -public class MixerRecipe implements LookingGlassRecipe { +public class MixingRecipe implements LookingGlassRecipe { - private final DefaultedList ingredients; + private final List ingredients; private final ItemStack output; private final Identifier id; - public MixerRecipe(Identifier id, DefaultedList ingredients, ItemStack output) { + public MixingRecipe(Identifier id, List ingredients, ItemStack output) { this.ingredients = ingredients; this.output = output; this.id = id; @@ -39,30 +34,20 @@ public MixerRecipe(Identifier id, DefaultedList ingredients, ItemSta @Override public boolean matches(MixerEntity inv, World world) { - List invStacks = new ArrayList<>(); - for (int i = 0; i < 4; i++) { - invStacks.add(inv.getStack(i)); - } - AtomicInteger matches = new AtomicInteger(); - ingredients.forEach(ingredient -> { - for (int i = 0; i < invStacks.size(); i++) { - if(ingredient.isEmpty()) { - matches.getAndIncrement(); - break; - } - ItemStack stack = invStacks.get(i); - if(ingredient.test(stack)) { - matches.getAndIncrement(); - invStacks.remove(i); - break; - } - } - }); - return matches.get() == 4; + return IngredientStack.matchInvExclusively(inv, ingredients, 4, 0); } @Override public ItemStack craft(MixerEntity inv) { + ItemStack outSlot = inv.getStack(4); + if(outSlot.isEmpty()) { + inv.setStack(4, output.copy()); + IngredientStack.decrementExclusively(inv, ingredients, 4, 0); + } + else if(outSlot.getCount() + output.getCount() <= outSlot.getMaxCount() && output.isItemEqual(outSlot)) { + inv.getStack(4).increment(output.getCount()); + IngredientStack.decrementExclusively(inv, ingredients, 4, 0); + } return output.copy(); } @@ -83,7 +68,7 @@ public ItemStack getRecipeKindIcon() { @Override public DefaultedList getPreviewInputs() { - return ingredients; + return IngredientStack.listIngredients(ingredients); } @Override @@ -102,15 +87,15 @@ public LookingGlassRecipeType getType() { } @Override - public List getInputs() { + public List getInputs() { return ingredients; } - public static class MixerRecipeSerializer implements RecipeSerializer { + public static class MixingRecipeSerializer implements RecipeSerializer { @Override - public MixerRecipe read(Identifier id, JsonObject json) { - DefaultedList ingredients; + public MixingRecipe read(Identifier id, JsonObject json) { + List ingredients; ItemStack output; try { @@ -123,18 +108,18 @@ public MixerRecipe read(Identifier id, JsonObject json) { return null; } - return new MixerRecipe(id, ingredients, output); + return new MixingRecipe(id, ingredients, output); } @Override - public MixerRecipe read(Identifier id, PacketByteBuf buf) { + public MixingRecipe read(Identifier id, PacketByteBuf buf) { ItemStack output = buf.readItemStack(); - DefaultedList ingredients = BufUtils.ingredientsFromBuf(buf); - return new MixerRecipe(id, ingredients, output); + List ingredients = BufUtils.ingredientsFromBuf(buf); + return new MixingRecipe(id, ingredients, output); } @Override - public void write(PacketByteBuf buf, MixerRecipe recipe) { + public void write(PacketByteBuf buf, MixingRecipe recipe) { buf.writeItemStack(recipe.output); BufUtils.ingredientsToBuf(recipe.ingredients, buf); } diff --git a/src/main/java/azzy/fabric/lookingglass/util/BufUtils.java b/src/main/java/azzy/fabric/lookingglass/util/BufUtils.java index b55a92f..2a15d5e 100644 --- a/src/main/java/azzy/fabric/lookingglass/util/BufUtils.java +++ b/src/main/java/azzy/fabric/lookingglass/util/BufUtils.java @@ -1,20 +1,22 @@ package azzy.fabric.lookingglass.util; import net.minecraft.network.PacketByteBuf; -import net.minecraft.recipe.Ingredient; -import net.minecraft.util.collection.DefaultedList; + +import java.util.ArrayList; +import java.util.List; public class BufUtils { - public static DefaultedList ingredientsFromBuf(PacketByteBuf buf) { - DefaultedList ingredients = DefaultedList.ofSize(buf.readInt(), Ingredient.EMPTY); - for (int i = 0; i < ingredients.size(); i++) { - ingredients.set(i, Ingredient.fromPacket(buf)); + public static List ingredientsFromBuf(PacketByteBuf buf) { + int size = buf.readInt(); + List ingredients = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + ingredients.set(i, IngredientStack.fromByteBuf(buf)); } return ingredients; } - public static void ingredientsToBuf(DefaultedList ingredients, PacketByteBuf buf) { + public static void ingredientsToBuf(List ingredients, PacketByteBuf buf) { buf.writeInt(ingredients.size()); ingredients.forEach(ingredient -> ingredient.write(buf)); } diff --git a/src/main/java/azzy/fabric/lookingglass/util/IngredientStack.java b/src/main/java/azzy/fabric/lookingglass/util/IngredientStack.java new file mode 100644 index 0000000..9b49066 --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/util/IngredientStack.java @@ -0,0 +1,132 @@ +package azzy.fabric.lookingglass.util; + +import net.minecraft.inventory.Inventory; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketByteBuf; +import net.minecraft.recipe.Ingredient; +import net.minecraft.util.collection.DefaultedList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +public final class IngredientStack { + + public static final IngredientStack EMPTY = new IngredientStack(Ingredient.EMPTY, 0); + private final Ingredient ingredient; + private final int count; + + private IngredientStack(Ingredient ingredient, int count) { + this.ingredient = ingredient; + this.count = count; + } + + public static IngredientStack of(Ingredient ingredient, int count) { + if(ingredient.isEmpty()) { + return EMPTY; + } + return new IngredientStack(ingredient, count); + } + + public static IngredientStack of(Ingredient ingredient) { + return of(ingredient, 1); + } + + public boolean test(ItemStack stack) { + return ingredient.test(stack) && stack.getCount() >= count; + } + + public boolean testStrict(ItemStack stack) { + return ingredient.test(stack) && stack.getCount() == count; + } + + public void write(PacketByteBuf buf) { + ingredient.write(buf); + buf.writeInt(count); + } + + public static IngredientStack fromByteBuf(PacketByteBuf buf) { + return new IngredientStack(Ingredient.fromPacket(buf), buf.readInt()); + } + + public static List decodeByteBuf(PacketByteBuf buf, int size) { + List ingredients = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + ingredients.add(fromByteBuf(buf)); + } + return ingredients; + } + + public List getStacks() { + return Arrays.stream(((MatchingStackAccessor) (Object) ingredient) + .getMatchingStacks()) + .peek(stack -> stack.setCount(count)) + .collect(Collectors.toList()); + } + + public Ingredient getIngredient() { + return ingredient; + } + + public int getCount() { + return count; + } + + public boolean isEmpty() { + return this == EMPTY || ingredient.isEmpty(); + } + + public static DefaultedList listIngredients(List ingredients) { + DefaultedList preview = DefaultedList.ofSize(ingredients.size(), Ingredient.EMPTY); + for (int i = 0; i < ingredients.size(); i++) { + preview.set(i, ingredients.get(i).getIngredient()); + } + return preview; + } + + + public static boolean matchInvExclusively(Inventory inv, List ingredients, int size, int offset) { + List invStacks = new ArrayList<>(size); + for (int i = offset; i < size + offset; i++) { + invStacks.add(inv.getStack(i)); + } + AtomicInteger matches = new AtomicInteger(); + ingredients.forEach(ingredient -> { + for (int i = 0; i < invStacks.size(); i++) { + if(ingredient.isEmpty()) { + matches.getAndIncrement(); + break; + } + ItemStack stack = invStacks.get(i); + if(ingredient.test(stack)) { + matches.getAndIncrement(); + invStacks.remove(i); + break; + } + } + }); + return matches.get() == size; + } + + public static void decrementExclusively(Inventory inv, List ingredients, int size, int offset) { + List invStacks = new ArrayList<>(size); + for (int i = offset; i < size + offset; i++) { + invStacks.add(inv.getStack(i)); + } + ingredients.forEach(ingredient -> { + for (int i = 0; i < invStacks.size(); i++) { + if(ingredient.isEmpty()) { + break; + } + ItemStack stack = invStacks.get(i); + if(ingredient.test(stack)) { + stack.decrement(ingredient.count); + invStacks.remove(i); + break; + } + } + }); + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/util/MatchingStackAccessor.java b/src/main/java/azzy/fabric/lookingglass/util/MatchingStackAccessor.java new file mode 100644 index 0000000..42a9185 --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/util/MatchingStackAccessor.java @@ -0,0 +1,8 @@ +package azzy.fabric.lookingglass.util; + +import net.minecraft.item.ItemStack; + +public interface MatchingStackAccessor { + + ItemStack[] getMatchingStacks(); +} diff --git a/src/main/java/azzy/fabric/lookingglass/util/json/JsonUtils.java b/src/main/java/azzy/fabric/lookingglass/util/json/JsonUtils.java index bb862fa..ee9ba38 100644 --- a/src/main/java/azzy/fabric/lookingglass/util/json/JsonUtils.java +++ b/src/main/java/azzy/fabric/lookingglass/util/json/JsonUtils.java @@ -1,5 +1,6 @@ package azzy.fabric.lookingglass.util.json; +import azzy.fabric.lookingglass.util.IngredientStack; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -15,6 +16,8 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; public class JsonUtils { @@ -24,16 +27,29 @@ public static JsonObject fromInputStream(InputStream in) { return PARSER.parse(new JsonReader(new InputStreamReader(in, StandardCharsets.UTF_8))).getAsJsonObject(); } - public static ItemStack stackFromJson(JsonObject element) { - Item item = Registry.ITEM.get(Identifier.tryParse(element.get("item").getAsString())); - int count = element.has("count") ? element.get("count").getAsInt() : 1; + public static ItemStack stackFromJson(JsonObject json) { + Item item = Registry.ITEM.get(Identifier.tryParse(json.get("item").getAsString())); + int count = json.has("count") ? json.get("count").getAsInt() : 1; return item != Items.AIR ? new ItemStack(item, count) : ItemStack.EMPTY; } - public static DefaultedList ingredientsFromJson(JsonArray elements, int size) { - DefaultedList ingredients = DefaultedList.ofSize(size, Ingredient.EMPTY); - for (int i = 0; i < elements.size() && i < size; i++) { - ingredients.set(i, Ingredient.fromJson(elements.get(i))); + public static IngredientStack ingredientFromJson(JsonObject json) { + Ingredient ingredient = Ingredient.fromJson(json.get("ingredient")); + int count = json.has("count") ? json.get("count").getAsInt() : 1; + return IngredientStack.of(ingredient, count); + } + + public static List ingredientsFromJson(JsonArray array, int size) { + List ingredients = new ArrayList<>(size); + int dif = size - array.size(); + for (int i = 0; i < array.size() && i < size; i++) { + JsonObject object = array.get(i).getAsJsonObject(); + ingredients.add(ingredientFromJson(object)); + } + if(dif > 0) { + for (int i = 0; i < dif; i++) { + ingredients.add(IngredientStack.EMPTY); + } } return ingredients; } diff --git a/src/main/java/azzy/fabric/lookingglass/util/BlockEntityMover.java b/src/main/java/azzy/fabric/lookingglass/util/machine/BlockEntityMover.java similarity index 95% rename from src/main/java/azzy/fabric/lookingglass/util/BlockEntityMover.java rename to src/main/java/azzy/fabric/lookingglass/util/machine/BlockEntityMover.java index bd45d3a..4799e0e 100644 --- a/src/main/java/azzy/fabric/lookingglass/util/BlockEntityMover.java +++ b/src/main/java/azzy/fabric/lookingglass/util/machine/BlockEntityMover.java @@ -1,6 +1,7 @@ -package azzy.fabric.lookingglass.util; +package azzy.fabric.lookingglass.util.machine; import azzy.fabric.lookingglass.blockentity.ChunkLoaderEntity; +import azzy.fabric.lookingglass.util.MovementSensitiveBlockEntity; import net.fabricmc.fabric.api.block.entity.BlockEntityClientSerializable; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; diff --git a/src/main/java/azzy/fabric/lookingglass/util/FalseInventory.java b/src/main/java/azzy/fabric/lookingglass/util/machine/FalseInventory.java similarity index 95% rename from src/main/java/azzy/fabric/lookingglass/util/FalseInventory.java rename to src/main/java/azzy/fabric/lookingglass/util/machine/FalseInventory.java index 99c260c..011e622 100644 --- a/src/main/java/azzy/fabric/lookingglass/util/FalseInventory.java +++ b/src/main/java/azzy/fabric/lookingglass/util/machine/FalseInventory.java @@ -1,4 +1,4 @@ -package azzy.fabric.lookingglass.util; +package azzy.fabric.lookingglass.util.machine; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventory; diff --git a/src/main/java/azzy/fabric/lookingglass/util/ModifierProvider.java b/src/main/java/azzy/fabric/lookingglass/util/machine/ModifierProvider.java similarity index 93% rename from src/main/java/azzy/fabric/lookingglass/util/ModifierProvider.java rename to src/main/java/azzy/fabric/lookingglass/util/machine/ModifierProvider.java index c52daee..dc49800 100644 --- a/src/main/java/azzy/fabric/lookingglass/util/ModifierProvider.java +++ b/src/main/java/azzy/fabric/lookingglass/util/machine/ModifierProvider.java @@ -1,4 +1,4 @@ -package azzy.fabric.lookingglass.util; +package azzy.fabric.lookingglass.util.machine; import azzy.fabric.lookingglass.blockentity.LookingGlassMachine; import azzy.fabric.lookingglass.gui.UpgradeableMachineGuiDescription; diff --git a/src/main/java/azzy/fabric/lookingglass/util/RecipeConversionProvider.java b/src/main/java/azzy/fabric/lookingglass/util/machine/RecipeConversionProvider.java similarity index 79% rename from src/main/java/azzy/fabric/lookingglass/util/RecipeConversionProvider.java rename to src/main/java/azzy/fabric/lookingglass/util/machine/RecipeConversionProvider.java index 7edc9a9..8cd7cad 100644 --- a/src/main/java/azzy/fabric/lookingglass/util/RecipeConversionProvider.java +++ b/src/main/java/azzy/fabric/lookingglass/util/machine/RecipeConversionProvider.java @@ -1,4 +1,4 @@ -package azzy.fabric.lookingglass.util; +package azzy.fabric.lookingglass.util.machine; import azzy.fabric.lookingglass.recipe.LookingGlassRecipe; import net.minecraft.recipe.RecipeType; diff --git a/src/main/java/azzy/fabric/lookingglass/util/rei/FreezingRecipeCategory.java b/src/main/java/azzy/fabric/lookingglass/util/rei/FreezingRecipeCategory.java index 69d1341..628df6f 100644 --- a/src/main/java/azzy/fabric/lookingglass/util/rei/FreezingRecipeCategory.java +++ b/src/main/java/azzy/fabric/lookingglass/util/rei/FreezingRecipeCategory.java @@ -27,7 +27,7 @@ public FreezingRecipeCategory() { Point start = new Point(bounds.getCenterX() - 41, bounds.y + 10); widgets.add(Widgets.createCategoryBase(bounds)); widgets.add(Widgets.createResultSlotBackground(new Point(start.x + 61, start.y + 9))); - widgets.add(Widgets.createSlot(new Point(start.x + 1, start.y + 1)).entries(getInput(recipeDisplay, 0)).markInput()); + widgets.add(Widgets.createSlot(new Point(start.x + 1, start.y + 10)).entries(getInput(recipeDisplay, 0)).markInput()); widgets.add(Widgets.createArrow(new Point(start.x + 24, start.y + 8)).animationDurationTicks(800)); widgets.add(Widgets.createSlot(new Point(start.x + 61, start.y + 9)).entries(getOutput(recipeDisplay, 0)).disableBackground().markOutput()); diff --git a/src/main/java/azzy/fabric/lookingglass/util/rei/GrindingRecipeCategory.java b/src/main/java/azzy/fabric/lookingglass/util/rei/GrindingRecipeCategory.java new file mode 100644 index 0000000..380d36e --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/util/rei/GrindingRecipeCategory.java @@ -0,0 +1,43 @@ +package azzy.fabric.lookingglass.util.rei; + +import azzy.fabric.lookingglass.block.LookingGlassBlocks; +import azzy.fabric.lookingglass.recipe.GrindingRecipe; +import azzy.fabric.lookingglass.recipe.LookingGlassRecipes; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.widget.Widget; +import net.minecraft.text.LiteralText; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class GrindingRecipeCategory extends AbstractLookingGlassRecipeCategory { + + public GrindingRecipeCategory() { + super(LookingGlassRecipes.GRINDING_RECIPE, EntryStack.create(LookingGlassBlocks.GRINDER_BLOCK)); + } + + @Override + public @NotNull List setupDisplay(LookingGlassRecipeDisplay recipeDisplay, Rectangle bounds) { + List widgets = new ArrayList<>(); + Point start = new Point(bounds.getCenterX() - 41, bounds.y + 20); + widgets.add(Widgets.createCategoryBase(bounds)); + widgets.add(Widgets.createSlot(new Point(start.x + 1, start.y + 9)).entries(getInput(recipeDisplay, 0)).markInput()); + widgets.add(Widgets.createArrow(new Point(start.x + 24, start.y + 8)).animationDurationTicks(200)); + widgets.add(Widgets.createSlot(new Point(start.x + 61, start.y - 1)).entries(getOutput(recipeDisplay, 0)).markOutput()); + widgets.add(Widgets.createSlot(new Point(start.x + 61, start.y + 18)).entries(getOutput(recipeDisplay, 1)).markOutput()); + widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 5), + new LiteralText("secondary output chance")).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); + widgets.add(Widgets.createLabel(new Point(bounds.x + bounds.width - 5, bounds.y + 14), + new LiteralText((recipeDisplay.getRecipe().getChance() * 100.0) + "%")).noShadow().rightAligned().color(0xFF404040, 0xFFBBBBBB)); + return widgets; + } + + @Override + public int getDisplayHeight() { + return 64; + } +} diff --git a/src/main/java/azzy/fabric/lookingglass/util/rei/LookingGlassRecipeDisplay.java b/src/main/java/azzy/fabric/lookingglass/util/rei/LookingGlassRecipeDisplay.java index 8789e54..a964232 100644 --- a/src/main/java/azzy/fabric/lookingglass/util/rei/LookingGlassRecipeDisplay.java +++ b/src/main/java/azzy/fabric/lookingglass/util/rei/LookingGlassRecipeDisplay.java @@ -23,7 +23,7 @@ public class LookingGlassRecipeDisplay> implemen public LookingGlassRecipeDisplay(R recipe) { this.recipe = recipe; - this.inputs = CollectionUtils.map(recipe.getInputs(), EntryStack::ofIngredient); + this.inputs = CollectionUtils.map(recipe.getInputs(), stack -> EntryStack.ofItemStacks(stack.getStacks())); this.outputs = CollectionUtils.map(EntryStack.ofItemStacks(recipe.getOutputs()), Collections::singletonList); } @@ -38,6 +38,10 @@ public LookingGlassRecipeDisplay(R recipe) { return inputs; } + public R getRecipe() { + return recipe; + } + @Override public @NotNull List> getRequiredEntries() { return getInputEntries(); diff --git a/src/main/java/azzy/fabric/lookingglass/util/rei/MixingRecipeCategory.java b/src/main/java/azzy/fabric/lookingglass/util/rei/MixingRecipeCategory.java new file mode 100644 index 0000000..dd36396 --- /dev/null +++ b/src/main/java/azzy/fabric/lookingglass/util/rei/MixingRecipeCategory.java @@ -0,0 +1,41 @@ +package azzy.fabric.lookingglass.util.rei; + +import azzy.fabric.lookingglass.block.LookingGlassBlocks; +import azzy.fabric.lookingglass.recipe.LookingGlassRecipes; +import azzy.fabric.lookingglass.recipe.MixingRecipe; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.widgets.Widgets; +import me.shedaniel.rei.gui.widget.Widget; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +public class MixingRecipeCategory extends AbstractLookingGlassRecipeCategory { + + public MixingRecipeCategory() { + super(LookingGlassRecipes.MIXING_RECIPE, EntryStack.create(LookingGlassBlocks.MIXER_BLOCK)); + } + + @Override + public @NotNull List setupDisplay(LookingGlassRecipeDisplay recipeDisplay, Rectangle bounds) { + List widgets = new ArrayList<>(); + Point start = new Point(bounds.getCenterX() - 36, bounds.y + 10); + widgets.add(Widgets.createCategoryBase(bounds)); + widgets.add(Widgets.createResultSlotBackground(new Point(start.x + 61, start.y + 9))); + widgets.add(Widgets.createSlot(new Point(start.x - 17, start.y - 1)).entries(getInput(recipeDisplay, 0)).markInput()); + widgets.add(Widgets.createSlot(new Point(start.x + 1, start.y - 1)).entries(getInput(recipeDisplay, 1)).markInput()); + widgets.add(Widgets.createSlot(new Point(start.x - 17, start.y + 18)).entries(getInput(recipeDisplay, 2)).markInput()); + widgets.add(Widgets.createSlot(new Point(start.x + 1, start.y + 18)).entries(getInput(recipeDisplay, 3)).markInput()); + widgets.add(Widgets.createArrow(new Point(start.x + 24, start.y + 8)).animationDurationTicks(400)); + widgets.add(Widgets.createSlot(new Point(start.x + 61, start.y + 9)).entries(getOutput(recipeDisplay, 0)).disableBackground().markOutput()); + return widgets; + } + + @Override + public int getDisplayHeight() { + return 51; + } +} diff --git a/src/main/resources/assets/lookingglass/lang/en_us.json b/src/main/resources/assets/lookingglass/lang/en_us.json index 5f3a96a..34b4bb0 100644 --- a/src/main/resources/assets/lookingglass/lang/en_us.json +++ b/src/main/resources/assets/lookingglass/lang/en_us.json @@ -13,13 +13,15 @@ "block.lookingglass.eldenmetal_block": "Eldenmetal Block", "block.lookingglass.finis_block": "Block Of Finis", "block.lookingglass.rose_gold_block": "Rose Gold Block", - "block.lookingglass.silicon_cable": "Red Silicon Cable", + "block.lookingglass.silicon_cable": "Silicon Cable", "block.lookingglass.guilded_cable": "Guilded Cable", "block.lookingglass.enchanted_cable": "Enchanted Cable", "block.lookingglass.null_cable": "Null Cable", "block.lookingglass.dwarven_machine_core": "Dwarven Machine Core", "block.lookingglass.powered_furnace": "Powered Furnace", "block.lookingglass.alloy_furnace": "Alloy Furnace", + "block.lookingglass.grinder": "Mill", + "block.lookingglass.mixer": "Mixer", "block.lookingglass.interminal_core": "Interminal Core", "block.lookingglass.growth_core_0": "Growth Core", "block.lookingglass.growth_core_1": "Augmented Growth Core", @@ -92,12 +94,13 @@ "item.lookingglass.basic_energy_usage_upgrade": "Basic Efficiency Module", "item.lookingglass.freezer_upgrade": "Heat Pump Conversion", "item.lookingglass.blast_upgrade": "Arc Smelter Conversion", - "item.lookingglass.red_silicon_ingot": "Silicon Bar", + "item.lookingglass.red_silicon_ingot": "Silicon Crystal", + "item.lookingglass.silicon_induction_coil": "Silicon Induction Coil", "item.lookingglass.celestial_amalgam": "Celestial Amalgam", "item.lookingglass.finis_ingot": "Bar Of Finis", "item.lookingglass.finis_nugget": "Finis Shard", "item.lookingglass.rose_gold_ingot": "Rose Gold Ingot", - "item.lookingglass.rose_gold_nugget": "Rose Gold Nuggets", + "item.lookingglass.rose_gold_nugget": "Rose Gold Nugget", "item.lookingglass.eldenmetal_drop": "Drop of Eldenmetal", "item.lookingglass.eldenmetal_tear": "Eldenmetal Tear", "item.lookingglass.eldenmetal_gem": "Lacuna Crystal", @@ -106,7 +109,7 @@ "item.lookingglass.shimmerfin": "Prismatic Shimmerfin", "item.lookingglass.fish_feed": "Fish Feed", "item.lookingglass.ring": "Rosy Ring", - "item.lookingglass.simple_angel_ring": "Simple Angel Ring", + "item.lookingglass.simple_angel_ring": "Angel Ring", "item.lookingglass.advanced_angel_ring": "Advanced Angel Ring", "item.lookingglass.angelRing.flightEnabled": "Flight Enabled", "item.lookingglass.angelRing.flightDisabled": "Flight Disabled", @@ -120,6 +123,10 @@ "label.lookingglass.glass.player_switch": "§aSwitched mode to: Player Renderer", "label.lookingglass.wrong": "§cDistances must be numerical", "lookingglass:alloying": "Alloying", + "lookingglass:induction": "Induction", + "lookingglass:freezing": "Freezing", + "lookingglass:grinding": "Milling", + "lookingglass:mixing": "Mixing", "death.attack.erasure": "%1$s was finalized", "death.attack.erasure.player": "%2$s finalized %1$s using %3$s", "death.attack.judgement": "%1$s faced judgement, he was deemed unworthy.", diff --git a/src/main/resources/assets/lookingglass/textures/block/finis_block.png b/src/main/resources/assets/lookingglass/textures/block/finis_block.png index a0fd7ac160ad3b7622af15f4c4f3fa4d90cf2985..f2e7f60e6868d0e913d13c364a65a90b2287c4e0 100755 GIT binary patch delta 495 zcmV;Gg+DNbK~%V~w?Gt}6v+h%LZYV456HjB zuS%0562q)256#fKCNq_{v7>pjVCg20VMiuJC|-87zE&wKOc&367&_dBiFT}u`N z_g&up50DlK`PrfO_EJY^3(|1~Kz?@c#ufS50SO2PwUKnb{eQdN(;{Iy3g2}$#O)j) zdO3mw6-%wafFG5Fwm6dDEgL0jBO%aa-NnEqEfRLu(vFay9io>bX_2t}_yGjuk)y%C zB>;XPI9;}M4PY^FnT|pW^2QZ;3=AESd+J`wCfU7CP8Q*8Qk_I-Lyz_L2af1=8wW+L delta 522 zcmV+l0`>it1h52bP$+0h6)?3!5Hx*gQTIs)*{^D>ODKjouv2fIrp6N?$zJwbmF4shmzZN z>%;fuJwTL)WIK!I`$H+;G(^J+fNW=B4=b{r1q$#ig8MtJet-Tuo}xTt-19$7*2I_J z0Kv-|6r>9!3N-kw65lij3hc>QN&2L~6|%-{yG4|T%nzlpknJpjmo-ryGWq%iJjen| zz|RT*$Mx90&S+@BZM(&|=NphctjGe3;MW?v&Oz7qbw-*fMxCh;yl>E%T*}4+luRCV zriQ37Ka^xU%YRrH_xv}{WKSwdT|t^C@B~N#$7M+)%0p?W!_>emu*`Xy)V^;#(kI1n zSu)snB}6?@CqC}^pi{5Ib8bA+M413TUAKt)g%Ct}DE<(cQ66GXD#FJ-_OK#d2+(mo zNWl5-aa@+*3Q@ysRxMS_cU+I~aSyHpmoDV(wTi(~EPpiZVMT^@_V|4E%c3Sm;e4xQ zda!zcxL%O^+EYRRqkfn|t<3q;>A_fHqH)`L&VY*i)UjeVx|2Jz>6oUYABvyDuo!m9ILeRWDAh(u@$4Z{7z~9#~ delta 346 zcmV-g0j2(x1A+sPF@HQsL_t(IjqQ=KO9F8m#XmnW6NR$jq7oe@xS301q!Q#dlh~axM}ND^Y@Hu7YFWtk0H?o* z^a6GYOBlsGvOSpM#lzmJ(q=6JKFt1%Im+9eF`{l}l#Zig&Wrx_P3wOR0T4|AaQpNs zqN2K)QI<2ADf7&F5itPEnNX>gxj0y#8_V?-H+PpDZm&?Omf1fkgj`Ht?bRAMeSc~y zjiL1D)f$wpPg5DSEbL|%ohSzHo8Lcn+a07*qoM6N<$f`Wu13(ZFQJ!^1!2C9(>n7&gxY30;rqOw7L#!^Y^$$5R?{_(95s zxAlRpW*|PBn5uJ|d3L|?o!y_CA6~k8pT~8(|H8r-2MZW?Jqw=u8)U_XtYZcY%YNRI z?TFtl_9iU>2ySfnXdHHyhbLoW!Iw+^Y0{jAyFn<9yNklTP^ zLdQZ8DLP93fS9EqNQaK%&_Oy$mj(pEhSJh5A%aw}6eJGuUenT#RnKzI$9>*&IQPQ8 zv9hIwWlIYe^V^#s;oBz%_}u|Oc=__7tQ3et#as$wf0v!ZBY#;hMu!wpHbL*5CxAJT z*P8~_=7`(3FGVR^T6po`FzdJFg+(YHC(?Ol{Wh&i9mfsW0`MC(66w4YSOkrNjZv@x zxIaFnRjJbpCcis~mQ%wh*m4p9%=&Gf&q@rvDS!mCdXmR+5D7%Z0e-i{-uV^4Qb>Si zMvVgZX96>$GEVfSm>CtnQRD8qLsn0&1gp&vK(s{h3dLM%ZASqKQ25e`i}ZpCSv`s4 n21}v1%_YTu@chrU(BHCe90`>{XJB8&00000NkvXXu0mjf^8KCk diff --git a/src/main/resources/assets/lookingglass/textures/item/silicon_induction_coil.png b/src/main/resources/assets/lookingglass/textures/item/silicon_induction_coil.png new file mode 100755 index 0000000000000000000000000000000000000000..a97830f621c93f8289282f176cb43b0216c5b43e GIT binary patch literal 392 zcmV;30eAk1P)Px$LPTQoU+}P!#?wCb(GAfP;P=qrRiKp!CZ1Rc6{ z5JR(e3r+^wK?oTXR|lb%q=S&a?I2gwYj9}4?VNkQpL@>*{s`{WfoD!hxt=&~<1BxQ zsJ%X5{}DmFmXX>HJmmel5LYK(J>C?gV6g)LNP{kVssLVA@qGV|S+M390neNg>bjk; zDzRxQ<@Ou^@bZ)tBFq)G^A!`5)|RgkLl-OaXLa{BL}3O)7hx$HDFgr@wVg)yGG@V= z^EU@J0RUXwnXT>=p8LZJq_zWT&@G}h!BR9b9(C9R6UXI(#ST4HXmwBGBjPX8yoFEu z8-^|d%RB`gqN)0q?DJGQmXfb23Ny$<0dLDa0AM`oAc>EV`aJy2q4^_~MJP!g=2wcs m4D|KO