From d07758052777a3fb44b863b95108bf2e7dd33918 Mon Sep 17 00:00:00 2001 From: Buuz135 Date: Mon, 24 Jun 2024 21:29:05 +0200 Subject: [PATCH] Fixed black hole units losing the nbt of items when stored in controllers, closes #1435 --- CHANGELOG.md | 4 + build.gradle | 2 +- .../978d9ef6efbd3faa67b30ce46c34ea51e4b10e33 | 8 +- .../9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e | 5 +- .../c06b22f661d5f8690ae5a8441f9d34dce0f7210c | 3 +- .../laser_drill_ore/ores/draconium.json | 2 +- .../raw_materials/sheldonite.json | 2 +- .../raw_materials/tungsten.json | 2 +- .../recipes/machine_settings_copier.json | 42 ++++++ .../industrial/api/IMachineSettings.java | 35 +++++ .../tile/AnimalBabySeparatorTile.java | 13 ++ .../tile/MobCrusherTile.java | 17 ++- .../tile/MobDuplicatorTile.java | 16 +++ .../tile/PlantSowerTile.java | 26 ++++ .../core/tile/DissolutionChamberTile.java | 26 ++++ .../block/generator/tile/BioReactorTile.java | 26 ++++ .../misc/tile/EnchantmentExtractorTile.java | 13 ++ .../resourceproduction/tile/DyeMixerTile.java | 16 +++ .../tile/FermentationStationTile.java | 20 +++ .../tile/FluidLaserBaseTile.java | 16 ++- .../tile/MaterialStoneWorkFactoryTile.java | 34 ++++- .../tile/OreLaserBaseTile.java | 16 +++ .../tile/PotionBrewerTile.java | 25 ++++ .../block/tile/IndustrialMachineTile.java | 130 ++++++++++++++---- .../industrial/item/MachineSettingCopier.java | 92 +++++++++++++ .../buuz135/industrial/module/ModuleCore.java | 15 +- .../industrial/proxy/client/ClientProxy.java | 3 + .../provider/IndustrialRecipeProvider.java | 1 + src/main/resources/META-INF/mods.toml | 2 +- .../industrialforegoing/lang/en_us.json | 7 +- .../models/item/machine_settings_copier.json | 20 +++ .../item/machine_settings_copier_empty.json | 6 + .../item/machine_settings_copier_stored.json | 6 + .../textures/item/machine_setting_copier.png | Bin 0 -> 397 bytes .../item/machine_setting_copier_stored.png | Bin 0 -> 411 bytes 35 files changed, 597 insertions(+), 54 deletions(-) create mode 100644 src/generated/resources/data/industrialforegoing/recipes/machine_settings_copier.json create mode 100644 src/main/java/com/buuz135/industrial/api/IMachineSettings.java create mode 100644 src/main/java/com/buuz135/industrial/item/MachineSettingCopier.java create mode 100644 src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier.json create mode 100644 src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier_empty.json create mode 100644 src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier_stored.json create mode 100644 src/main/resources/assets/industrialforegoing/textures/item/machine_setting_copier.png create mode 100644 src/main/resources/assets/industrialforegoing/textures/item/machine_setting_copier_stored.png diff --git a/CHANGELOG.md b/CHANGELOG.md index 6923aabe2..e984ef623 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# Version 3.5.18 + +* Added Machine Settings Copier + # Version 3.5.17 * Fix bug where Black Hole Units could transmute items (by notcake) diff --git a/build.gradle b/build.gradle index 621cf617c..bc5f52ea9 100644 --- a/build.gradle +++ b/build.gradle @@ -154,7 +154,7 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-1.20.1-forge-api:15.2.0.23") // at runtime, use the full JEI jar for Forge runtimeOnly fg.deobf("mezz.jei:jei-1.20.1-forge:15.2.0.23") - implementation fg.deobf(project.dependencies.create('com.hrznstudio:titanium:1.20.1-3.8.25')) + implementation fg.deobf(project.dependencies.create('com.hrznstudio:titanium:1.20.1-3.8.32')) implementation fg.deobf("curse.maven:curios-309927:5086821") implementation fg.deobf("curse.maven:patchouli-306770:4636277") diff --git a/src/generated/resources/.cache/978d9ef6efbd3faa67b30ce46c34ea51e4b10e33 b/src/generated/resources/.cache/978d9ef6efbd3faa67b30ce46c34ea51e4b10e33 index ae6b32d80..fcc6c2275 100644 --- a/src/generated/resources/.cache/978d9ef6efbd3faa67b30ce46c34ea51e4b10e33 +++ b/src/generated/resources/.cache/978d9ef6efbd3faa67b30ce46c34ea51e4b10e33 @@ -1,4 +1,4 @@ -// 1.20.1 2023-07-29T16:46:10.132647 Titanium Serializable (industrialforegoing) +// 1.20.1 2024-06-24T21:25:49.052893 Titanium Serializable (industrialforegoing) 447935433d16d79caf2fe9ab416dc72313d264c9 data/industrialforegoing/recipes/crusher/cobble_gravel.json 4581eba498ede5633c603189ae2e7d3825519364 data/industrialforegoing/recipes/crusher/gravel_sand.json f9381c4e926f16b49a2e00fe0d52e4db4de7e8bf data/industrialforegoing/recipes/crusher/sand_silicon.json @@ -70,7 +70,7 @@ e918fe6905db398570f947cc4fb00329087e5378 data/industrialforegoing/recipes/laser_ c04b6ad48ff9e3a3e568f3b2fcc3eb6954ee04a6 data/industrialforegoing/recipes/laser_drill_ore/ores/arcane.json 7ebd9c0c04dd8203b262756b3d7de0fe031aab0b data/industrialforegoing/recipes/laser_drill_ore/ores/bitumen.json 9433e8dc94616f5ee60ed268b07761e73a4125eb data/industrialforegoing/recipes/laser_drill_ore/ores/cinnabar.json -225e946b9329975efb01892c489114810286dd7f data/industrialforegoing/recipes/laser_drill_ore/ores/draconium.json +48979b5ea08762752ce9e456cac3094091f4f00d data/industrialforegoing/recipes/laser_drill_ore/ores/draconium.json 455f8955cc7340a58c3cd3ca87ad4d0224b046f4 data/industrialforegoing/recipes/laser_drill_ore/ores/fluorite.json 509a42763d5dc2c3b191f1cbf6b767bfa1818b02 data/industrialforegoing/recipes/laser_drill_ore/ores/niter.json 4dc21472f8183148bf65d5a6b6d798a150690be6 data/industrialforegoing/recipes/laser_drill_ore/ores/peridot.json @@ -95,11 +95,11 @@ da8f8ad50ae07882efc3cc351b2b73a4c0b1d084 data/industrialforegoing/recipes/laser_ 4ab3581ad0aa8df18ed90343edbdc561f8476958 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/osmium.json ed404e550f07f6935ebd8454a5f9db903f775cb7 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/platinum.json 0df626d3246810813093185a349abae680185cd7 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/pyrite.json -bcdf66a104cbcd3230ac20df3f6faac2078bff04 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/sheldonite.json +41d33ad8b448d82bbe160256793278b0d6afee11 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/sheldonite.json 3e3b445e83bfb7211240f8ab69a57861bb1cf4aa data/industrialforegoing/recipes/laser_drill_ore/raw_materials/silver.json 1b9d2ad49c1968f6f4569bbe9700aefccd41bf41 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/tetrahedrite.json c83076227a472bf77cb14c2047f1537c9e10d9d1 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/tin.json -28edb5ffb344915a51c1edebd57910a22ac4e32f data/industrialforegoing/recipes/laser_drill_ore/raw_materials/tungsten.json +f04ac0255b11df77aefb63669ebef608d6c45561 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/tungsten.json da8d278159b12d8b81ec34639118637095d8bb9c data/industrialforegoing/recipes/laser_drill_ore/raw_materials/uranium.json 8106837eb4bd3e92befdffe0738344d3a25fe105 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/yellorite.json 3541011ea411945c16294a925a3ce6071a8b3779 data/industrialforegoing/recipes/laser_drill_ore/raw_materials/yellorium.json diff --git a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e index 730d94313..e5a1100ef 100644 --- a/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e +++ b/src/generated/resources/.cache/9fb1092f32d4fcbf9e061ffd718d4ec689c6c95e @@ -1,4 +1,4 @@ -// 1.20.1 2023-07-29T16:46:10.13545 Recipes +// 1.20.1 2024-06-24T21:25:49.0568937 Recipes c8f846bcd9160f716825ea42b439dea11e0ca891 data/industrialforegoing/advancements/recipes/misc/dryrubber.json a6b4e1ab72ec8541dabe29faaa7da3e48f7a4049 data/industrialforegoing/advancements/recipes/misc/laser_lens_black_recolor.json ec8c71020b9cc7203af2fe111e7aaa4641844cc9 data/industrialforegoing/advancements/recipes/misc/laser_lens_blue_recolor.json @@ -74,8 +74,9 @@ f0983f5553778f6515aae7e480b0445e849cdce0 data/industrialforegoing/recipes/laser_ 1911650b20a7e168c0f3a9bd57357c62a0d0f67e data/industrialforegoing/recipes/laser_lens_red_recolor.json 8df2405341d74e993701da5085f11efe3ae3d1a2 data/industrialforegoing/recipes/laser_lens_white_recolor.json 394567cca53b8f25ccae6350cba00aa1cb7f7e00 data/industrialforegoing/recipes/laser_lens_yellow_recolor.json -6732576016603d2d039c31d1f38d4423f254e580 data/industrialforegoing/recipes/latex_processing_unit.json +1b271bc61262eb71c394869c48dc610febd3bbc9 data/industrialforegoing/recipes/latex_processing_unit.json 9c783901b9c73d40e8a69557efd916565ab09409 data/industrialforegoing/recipes/machine_frame_pity.json +33f51917bd4c30ea099ae6a87d7b424892801215 data/industrialforegoing/recipes/machine_settings_copier.json 4f2634c9360208c6948a44b0fc9d8737f3fc0524 data/industrialforegoing/recipes/marine_fisher.json 1cd82fc5b83dacfeee89dbbc80e8726a20632a25 data/industrialforegoing/recipes/material_stonework_factory.json e685cce4190d4872918e949cf7fa3a9ecefb0e13 data/industrialforegoing/recipes/meat_feeder.json diff --git a/src/generated/resources/.cache/c06b22f661d5f8690ae5a8441f9d34dce0f7210c b/src/generated/resources/.cache/c06b22f661d5f8690ae5a8441f9d34dce0f7210c index 13eb7e7b5..22b1112ba 100644 --- a/src/generated/resources/.cache/c06b22f661d5f8690ae5a8441f9d34dce0f7210c +++ b/src/generated/resources/.cache/c06b22f661d5f8690ae5a8441f9d34dce0f7210c @@ -1,6 +1,7 @@ -// 1.20.1 2023-07-29T16:46:10.1359 Tags for minecraft:block mod id industrialforegoing +// 1.20.1 2024-06-24T21:25:49.0593931 Tags for minecraft:block mod id industrialforegoing d19fb5f318758fdaef5883eac670afb1d488f5ac data/industrialforegoing/tags/blocks/machine_frame/advanced.json 078014cbf879ad3b7979dfd739a4f4a9f9436050 data/industrialforegoing/tags/blocks/machine_frame/pity.json 3fc18d8c3f4e2763c5bacb8d3a7d34208cb0aac0 data/industrialforegoing/tags/blocks/machine_frame/simple.json 62c1d369f5daa4c5411fce7042ba70e62cc604cc data/industrialforegoing/tags/blocks/machine_frame/supreme.json +978c5cd1bafc1fdb56371e35cc3ce4b6759ab456 data/minecraft/tags/blocks/dirt.json 8c73051e1ec462f521ee0e5ce8dffca2b809994a data/minecraft/tags/blocks/mineable/pickaxe.json diff --git a/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/ores/draconium.json b/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/ores/draconium.json index 544fab2a8..30e42d365 100644 --- a/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/ores/draconium.json +++ b/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/ores/draconium.json @@ -17,7 +17,7 @@ "item": "industrialforegoing:laser_lens10" }, "output": { - "tag": "forge:ores/ores/draconium" + "tag": "forge:ores/draconium" }, "pointer": 0, "rarity": [ diff --git a/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/raw_materials/sheldonite.json b/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/raw_materials/sheldonite.json index 97d652294..e0d618f40 100644 --- a/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/raw_materials/sheldonite.json +++ b/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/raw_materials/sheldonite.json @@ -17,7 +17,7 @@ "item": "industrialforegoing:laser_lens0" }, "output": { - "tag": "forge:ores/raw_materials/sheldonite" + "tag": "forge:raw_materials/sheldonite" }, "pointer": 0, "rarity": [ diff --git a/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/raw_materials/tungsten.json b/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/raw_materials/tungsten.json index 94ee7e681..051a7cb67 100644 --- a/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/raw_materials/tungsten.json +++ b/src/generated/resources/data/industrialforegoing/recipes/laser_drill_ore/raw_materials/tungsten.json @@ -17,7 +17,7 @@ "item": "industrialforegoing:laser_lens15" }, "output": { - "tag": "forge:ores/raw_materials/tungsten" + "tag": "forge:raw_materials/tungsten" }, "pointer": 0, "rarity": [ diff --git a/src/generated/resources/data/industrialforegoing/recipes/machine_settings_copier.json b/src/generated/resources/data/industrialforegoing/recipes/machine_settings_copier.json new file mode 100644 index 000000000..aa885819e --- /dev/null +++ b/src/generated/resources/data/industrialforegoing/recipes/machine_settings_copier.json @@ -0,0 +1,42 @@ +{ + "type": "forge:conditional", + "recipes": [ + { + "conditions": [ + { + "type": "forge:and", + "values": [ + { + "type": "forge:item_exists", + "item": "industrialforegoing:machine_settings_copier" + } + ] + } + ], + "recipe": { + "type": "minecraft:crafting_shaped", + "category": "misc", + "key": { + "L": { + "tag": "forge:plastic" + }, + "P": { + "item": "minecraft:paper" + }, + "R": { + "item": "minecraft:redstone" + } + }, + "pattern": [ + "PLP", + "LRL", + "PRP" + ], + "result": { + "item": "industrialforegoing:machine_settings_copier" + }, + "show_notification": true + } + } + ] +} \ No newline at end of file diff --git a/src/main/java/com/buuz135/industrial/api/IMachineSettings.java b/src/main/java/com/buuz135/industrial/api/IMachineSettings.java new file mode 100644 index 000000000..5501aace7 --- /dev/null +++ b/src/main/java/com/buuz135/industrial/api/IMachineSettings.java @@ -0,0 +1,35 @@ +package com.buuz135.industrial.api; + +import com.hrznstudio.titanium.component.inventory.InventoryComponent; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; + +public interface IMachineSettings { + + public static CompoundTag writeInventory(InventoryComponent component) { + CompoundTag tag = new CompoundTag(); + for (int i = 0; i < component.getSlots(); i++) { + var stack = component.getStackInSlot(i); + if (!stack.isEmpty()) { + tag.put(i + "", stack.save(new CompoundTag())); + } + } + return tag; + } + + public static List readInventory(CompoundTag tag) { + List stacks = new ArrayList<>(); + for (String allKey : tag.getAllKeys()) { + stacks.add(ItemStack.of(tag.getCompound(allKey))); + } + return stacks; + } + + void loadSettings(Player player, CompoundTag tag); + + void saveSettings(Player player, CompoundTag tag); +} diff --git a/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/AnimalBabySeparatorTile.java b/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/AnimalBabySeparatorTile.java index dcb845ec2..a34dfcec0 100644 --- a/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/AnimalBabySeparatorTile.java +++ b/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/AnimalBabySeparatorTile.java @@ -36,7 +36,9 @@ import com.hrznstudio.titanium.component.button.ButtonComponent; import com.hrznstudio.titanium.component.energy.EnergyStorageComponent; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.animal.Animal; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.level.block.state.BlockState; @@ -118,4 +120,15 @@ public AnimalBabySeparatorTile getSelf() { return this; } + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putBoolean("ABS_movingAdults", movingAdults); + super.saveSettings(player, tag); + } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("ABS_movingAdults")) this.movingAdults = tag.getBoolean("ABS_movingAdults"); + super.loadSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/MobCrusherTile.java b/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/MobCrusherTile.java index 0de595b63..542831e88 100644 --- a/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/MobCrusherTile.java +++ b/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/MobCrusherTile.java @@ -44,6 +44,7 @@ import com.hrznstudio.titanium.util.LangUtil; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.damagesource.DamageSource; @@ -53,13 +54,13 @@ import net.minecraft.world.entity.animal.Animal; import net.minecraft.world.entity.boss.wither.WitherBoss; import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; @@ -222,4 +223,18 @@ protected EnergyStorageComponent createEnergyStorage() { public int getMaxProgress() { return MobCrusherConfig.maxProgress; } + + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putBoolean("MC_drops", dropXP); + super.saveSettings(player, tag); + } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("MC_drops")) { + this.dropXP = tag.getBoolean("MC_drops"); + } + super.loadSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/MobDuplicatorTile.java b/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/MobDuplicatorTile.java index 6cfa8a5be..08d182dee 100644 --- a/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/MobDuplicatorTile.java +++ b/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/MobDuplicatorTile.java @@ -17,9 +17,11 @@ import com.hrznstudio.titanium.component.inventory.SidedInventoryComponent; import com.hrznstudio.titanium.item.AugmentWrapper; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ServerLevelAccessor; @@ -161,4 +163,18 @@ public void sync() { public int getMaxProgress() { return MobDuplicatorConfig.maxProgress; } + + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putBoolean("MC_exactCopy", exactCopy); + super.saveSettings(player, tag); + } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("MC_exactCopy")) { + exactCopy = tag.getBoolean("MC_exactCopy"); + } + super.loadSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/PlantSowerTile.java b/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/PlantSowerTile.java index 0039f7aa4..e7c91d559 100644 --- a/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/PlantSowerTile.java +++ b/src/main/java/com/buuz135/industrial/block/agriculturehusbandry/tile/PlantSowerTile.java @@ -36,6 +36,8 @@ import com.hrznstudio.titanium.item.AugmentWrapper; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; @@ -143,4 +145,28 @@ public int getMaxProgress() { public PlantSowerTile getSelf() { return this; } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("PS_locked")) { + input.setLocked(tag.getBoolean("PS_locked")); + } + if (tag.contains("PS_filter")) { + for (String psFilter : tag.getCompound("PS_filter").getAllKeys()) { + input.getFilter()[Integer.parseInt(psFilter)] = ItemStack.of(tag.getCompound("PS_filter").getCompound(psFilter)); + } + } + super.loadSettings(player, tag); + } + + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putBoolean("PS_locked", input.isLocked()); + CompoundTag filterTag = new CompoundTag(); + for (int i = 0; i < input.getFilter().length; i++) { + filterTag.put(i + "", input.getFilter()[i].serializeNBT()); + } + tag.put("PS_filter", filterTag); + super.saveSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/core/tile/DissolutionChamberTile.java b/src/main/java/com/buuz135/industrial/block/core/tile/DissolutionChamberTile.java index f0c5a3bc2..947a4bf46 100644 --- a/src/main/java/com/buuz135/industrial/block/core/tile/DissolutionChamberTile.java +++ b/src/main/java/com/buuz135/industrial/block/core/tile/DissolutionChamberTile.java @@ -34,6 +34,8 @@ import com.hrznstudio.titanium.component.inventory.SidedInventoryComponent; import com.hrznstudio.titanium.util.RecipeUtil; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeType; @@ -178,4 +180,28 @@ public static Pair getSlotPos(int slot) { public DissolutionChamberTile getSelf() { return this; } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("DC_locked")) { + input.setLocked(tag.getBoolean("DC_locked")); + } + if (tag.contains("DC_filter")) { + for (String psFilter : tag.getCompound("DC_filter").getAllKeys()) { + input.getFilter()[Integer.parseInt(psFilter)] = ItemStack.of(tag.getCompound("DC_filter").getCompound(psFilter)); + } + } + super.loadSettings(player, tag); + } + + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putBoolean("DC_locked", input.isLocked()); + CompoundTag filterTag = new CompoundTag(); + for (int i = 0; i < input.getFilter().length; i++) { + filterTag.put(i + "", input.getFilter()[i].serializeNBT()); + } + tag.put("DC_filter", filterTag); + super.saveSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/generator/tile/BioReactorTile.java b/src/main/java/com/buuz135/industrial/block/generator/tile/BioReactorTile.java index 35109c75f..03ad1a83a 100644 --- a/src/main/java/com/buuz135/industrial/block/generator/tile/BioReactorTile.java +++ b/src/main/java/com/buuz135/industrial/block/generator/tile/BioReactorTile.java @@ -39,9 +39,11 @@ import com.hrznstudio.titanium.component.progress.ProgressBarComponent; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.tags.ItemTags; import net.minecraft.tags.TagKey; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -176,4 +178,28 @@ public int getMaxProgress() { public BioReactorTile getSelf() { return this; } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("BR_locked")) { + input.setLocked(tag.getBoolean("BR_locked")); + } + if (tag.contains("BR_filter")) { + for (String psFilter : tag.getCompound("BR_filter").getAllKeys()) { + input.getFilter()[Integer.parseInt(psFilter)] = ItemStack.of(tag.getCompound("BR_filter").getCompound(psFilter)); + } + } + super.loadSettings(player, tag); + } + + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putBoolean("BR_locked", input.isLocked()); + CompoundTag filterTag = new CompoundTag(); + for (int i = 0; i < input.getFilter().length; i++) { + filterTag.put(i + "", input.getFilter()[i].serializeNBT()); + } + tag.put("BR_filter", filterTag); + super.saveSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/misc/tile/EnchantmentExtractorTile.java b/src/main/java/com/buuz135/industrial/block/misc/tile/EnchantmentExtractorTile.java index 15ff13e3d..40f2ea986 100644 --- a/src/main/java/com/buuz135/industrial/block/misc/tile/EnchantmentExtractorTile.java +++ b/src/main/java/com/buuz135/industrial/block/misc/tile/EnchantmentExtractorTile.java @@ -42,6 +42,8 @@ import com.hrznstudio.titanium.util.LangUtil; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AnvilMenu; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; @@ -234,4 +236,15 @@ private ItemStack removeEnchantments(ItemStack stack, int damage, int count) { return itemstack; } + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("EE_extractEnchants")) extractEnchants = tag.getBoolean("EE_extractEnchants"); + super.loadSettings(player, tag); + } + + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putBoolean("EE_extractEnchants", extractEnchants); + super.saveSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/DyeMixerTile.java b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/DyeMixerTile.java index aea134388..ddff0abbe 100644 --- a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/DyeMixerTile.java +++ b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/DyeMixerTile.java @@ -37,7 +37,9 @@ import com.hrznstudio.titanium.util.FacingUtil; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.DyeItem; import net.minecraft.world.item.ItemStack; @@ -240,6 +242,20 @@ public DyeMixerTile getSelf() { return this; } + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("DM_dye")) { + dye = tag.getInt("DM_dye"); + } + super.loadSettings(player, tag); + } + + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putInt("DM_dye", dye); + super.saveSettings(player, tag); + } + private static class ColorUsage { private int r; diff --git a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/FermentationStationTile.java b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/FermentationStationTile.java index 6eb169d7d..b1acddf74 100644 --- a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/FermentationStationTile.java +++ b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/FermentationStationTile.java @@ -38,8 +38,10 @@ import com.hrznstudio.titanium.component.fluid.SidedFluidTankComponent; import com.hrznstudio.titanium.container.addon.IContainerAddon; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -213,6 +215,24 @@ public FermentationStationTile getSelf() { return this; } + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putInt("FS_production", this.production); + tag.putInt("FS_seal", this.seal); + super.saveSettings(player, tag); + } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("FS_production")) { + this.production = tag.getInt("FS_production"); + } + if (tag.contains("FS_seal")) { + this.seal = tag.getInt("FS_seal"); + } + super.loadSettings(player, tag); + } + public enum ProductionType { X_2(2, FermentationStationConfig.ticksFor2XProduction, FluidStack.EMPTY, new StateButtonInfo(0, IndustrialAssetProvider.FERMENTATION_PROCESSING_TWO, "text.industrialforegoing.tooltip.fermentation_station.processing_two")), //10 Seg diff --git a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/FluidLaserBaseTile.java b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/FluidLaserBaseTile.java index 68da3bba3..0ad3c38a7 100644 --- a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/FluidLaserBaseTile.java +++ b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/FluidLaserBaseTile.java @@ -45,9 +45,10 @@ import com.hrznstudio.titanium.util.RecipeUtil; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeType; @@ -193,4 +194,17 @@ public boolean canAcceptAugment(ItemStack augment) { return super.canAcceptAugment(augment); } + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putInt("FL_miningDepth", miningDepth); + super.saveSettings(player, tag); + } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("FL_miningDepth")) { + this.miningDepth = tag.getInt("FL_miningDepth"); + } + super.loadSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/MaterialStoneWorkFactoryTile.java b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/MaterialStoneWorkFactoryTile.java index 6facc254d..24dcd2d70 100644 --- a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/MaterialStoneWorkFactoryTile.java +++ b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/MaterialStoneWorkFactoryTile.java @@ -43,14 +43,14 @@ import com.hrznstudio.titanium.util.AssetUtil; import com.hrznstudio.titanium.util.LangUtil; import com.hrznstudio.titanium.util.RecipeUtil; -import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -397,6 +397,36 @@ public int getMaxProgress() { return maxProgress; } + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putString("MSWF_generatorRecipe", this.generatorRecipe); + tag.putInt("MSWF_firstRecipeId", firstRecipeId); + tag.putInt("MSWF_secondRecipeId", secondRecipeId); + tag.putInt("MSWF_thirdRecipeId", thirdRecipeId); + tag.putInt("MSWF_fourthRecipeId", fourthRecipeId); + super.saveSettings(player, tag); + } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("MSWF_generatorRecipe")) { + this.generatorRecipe = tag.getString("MSWF_generatorRecipe"); + } + if (tag.contains("MSWF_firstRecipeId")) { + this.firstRecipeId = tag.getInt("MSWF_firstRecipeId"); + } + if (tag.contains("MSWF_secondRecipeId")) { + this.secondRecipeId = tag.getInt("MSWF_secondRecipeId"); + } + if (tag.contains("MSWF_thirdRecipeId")) { + this.thirdRecipeId = tag.getInt("MSWF_thirdRecipeId"); + } + if (tag.contains("MSWF_fourthRecipeId")) { + this.fourthRecipeId = tag.getInt("MSWF_fourthRecipeId"); + } + super.loadSettings(player, tag); + } + public static class StoneWorkAction { private final ItemStack icon; diff --git a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/OreLaserBaseTile.java b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/OreLaserBaseTile.java index 83af1a634..d55e8183b 100644 --- a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/OreLaserBaseTile.java +++ b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/OreLaserBaseTile.java @@ -47,8 +47,10 @@ import it.unimi.dsi.fastutil.objects.ObjectIntPair; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.util.random.WeightedRandom; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.RecipeType; @@ -208,4 +210,18 @@ public boolean canAcceptAugment(ItemStack augment) { return super.canAcceptAugment(augment); } + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putInt("OL_miningDepth", miningDepth); + super.saveSettings(player, tag); + } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("OL_miningDepth")) { + this.miningDepth = tag.getInt("OL_miningDepth"); + } + super.loadSettings(player, tag); + } + } diff --git a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/PotionBrewerTile.java b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/PotionBrewerTile.java index 8608668f9..70ad7afe7 100644 --- a/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/PotionBrewerTile.java +++ b/src/main/java/com/buuz135/industrial/block/resourceproduction/tile/PotionBrewerTile.java @@ -40,7 +40,9 @@ import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; +import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -226,5 +228,28 @@ private void brewPotions(int slot) { } } + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains("BR_locked")) { + brewingItems.setLocked(tag.getBoolean("BR_locked")); + } + if (tag.contains("BR_filter")) { + for (String psFilter : tag.getCompound("BR_filter").getAllKeys()) { + brewingItems.getFilter()[Integer.parseInt(psFilter)] = ItemStack.of(tag.getCompound("BR_filter").getCompound(psFilter)); + } + } + super.loadSettings(player, tag); + } + + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.putBoolean("BR_locked", brewingItems.isLocked()); + CompoundTag filterTag = new CompoundTag(); + for (int i = 0; i < brewingItems.getFilter().length; i++) { + filterTag.put(i + "", brewingItems.getFilter()[i].serializeNBT()); + } + tag.put("BR_filter", filterTag); + super.saveSettings(player, tag); + } } diff --git a/src/main/java/com/buuz135/industrial/block/tile/IndustrialMachineTile.java b/src/main/java/com/buuz135/industrial/block/tile/IndustrialMachineTile.java index f7eb0eb05..40bae986c 100644 --- a/src/main/java/com/buuz135/industrial/block/tile/IndustrialMachineTile.java +++ b/src/main/java/com/buuz135/industrial/block/tile/IndustrialMachineTile.java @@ -22,11 +22,13 @@ package com.buuz135.industrial.block.tile; +import com.buuz135.industrial.api.IMachineSettings; import com.buuz135.industrial.item.addon.ProcessingAddonItem; import com.buuz135.industrial.item.addon.RangeAddonItem; import com.buuz135.industrial.proxy.client.IndustrialAssetProvider; import com.hrznstudio.titanium.annotation.Save; import com.hrznstudio.titanium.api.augment.AugmentTypes; +import com.hrznstudio.titanium.api.filter.IFilter; import com.hrznstudio.titanium.api.redstone.IRedstoneReader; import com.hrznstudio.titanium.api.redstone.IRedstoneState; import com.hrznstudio.titanium.block.BasicTileBlock; @@ -38,9 +40,17 @@ import com.hrznstudio.titanium.component.bundle.TankInteractionBundle; import com.hrznstudio.titanium.component.button.RedstoneControlButtonComponent; import com.hrznstudio.titanium.component.fluid.FluidTankComponent; +import com.hrznstudio.titanium.component.fluid.SidedFluidTankComponent; +import com.hrznstudio.titanium.component.inventory.InventoryComponent; +import com.hrznstudio.titanium.component.inventory.SidedInventoryComponent; +import com.hrznstudio.titanium.component.sideness.IFacingComponent; import com.hrznstudio.titanium.item.AugmentWrapper; +import com.hrznstudio.titanium.nbthandler.NBTManager; +import com.hrznstudio.titanium.util.FacingUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.nbt.CompoundTag; +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.Block; @@ -49,10 +59,17 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.capabilities.ForgeCapabilities; +import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.registries.RegistryObject; import org.apache.commons.lang3.tuple.Pair; -public abstract class IndustrialMachineTile> extends MachineTile implements IRedstoneReader { +public abstract class IndustrialMachineTile> extends MachineTile implements IRedstoneReader, IMachineSettings { + + private static String settingsAddons = "MACHINE_ADDONS"; + private static String redstoneMode = "REDSTONE_MODE"; + private static String sidenessTank = "SIDENESS_TANK"; + private static String sidenessInventory = "SIDENESS_INVENTORY"; + private static String filter = "FILTER"; @Save private TankInteractionBundle tankBundle; @@ -91,7 +108,7 @@ public boolean canAcceptAugment(ItemStack augment) { if (AugmentWrapper.hasType(augment, RangeAddonItem.RANGE)) { return !hasAugmentInstalled(RangeAddonItem.RANGE); } - return super.canAcceptAugment(augment); + return false; } public RedstoneManager getRedstoneManager() { @@ -126,36 +143,93 @@ public IAssetProvider getAssetProvider() { @Override public void clientTick(Level level, BlockPos pos, BlockState state, T blockEntity) { super.clientTick(level, pos, state, blockEntity); - /* - if (isSoulPowered() && level.random.nextDouble() < 0.3D){ - double posX = pos.getX(); - double posZ = pos.getZ(); - double offset = 0.1; - if (level.random.nextBoolean()){ - posZ += level.random.nextDouble(); - if (level.random.nextBoolean()){ - posX += 1 + offset; - }else { - posX -= offset; + } + + @Override + public void loadSettings(Player player, CompoundTag tag) { + if (tag.contains(settingsAddons)) { + var stacks = IMachineSettings.readInventory(tag.getCompound(settingsAddons)); + for (var stack : stacks) { + if (this.canAcceptAugment(stack)) { + for (ItemStack stackPlayer : player.inventory.items) { + if (ItemStack.isSameItem(stack, stackPlayer)) { + var copiedStack = ItemHandlerHelper.copyStackWithSize(stackPlayer, 1); + if (ItemHandlerHelper.insertItem(this.getAugmentInventory(), copiedStack, false).isEmpty()) { + stackPlayer.shrink(1); + } + break; + } + } + } + } + } + if (tag.contains(redstoneMode)) { + NBTManager.getInstance().readTileEntity(this, tag.getCompound(redstoneMode)); + } + if (tag.contains(sidenessInventory)) { + for (InventoryComponent inventoryHandler : this.getMultiInventoryComponent().getInventoryHandlers()) { + if (inventoryHandler instanceof SidedInventoryComponent sided) { + if (tag.getCompound(sidenessInventory).contains(sided.getName())) { + CompoundTag intermediateTag = tag.getCompound(sidenessInventory).getCompound(sided.getName()); + for (String allKey : intermediateTag.getAllKeys()) { + sided.getFacingModes().put(FacingUtil.Sideness.valueOf(allKey), IFacingComponent.FaceMode.valueOf(intermediateTag.getString(allKey))); + } + } } - } else { - posX += level.random.nextDouble(); - if (level.random.nextBoolean()){ - posZ += 1 + offset; - }else { - posZ -= offset; + } + } + if (tag.contains(sidenessTank)) { + for (FluidTankComponent fluidTankComponent : this.getMultiTankComponent().getTanks()) { + if (fluidTankComponent instanceof SidedFluidTankComponent sided) { + if (tag.getCompound(sidenessTank).contains(sided.getName())) { + CompoundTag intermediateTag = tag.getCompound(sidenessTank).getCompound(sided.getName()); + for (String allKey : intermediateTag.getAllKeys()) { + sided.getFacingModes().put(FacingUtil.Sideness.valueOf(allKey), IFacingComponent.FaceMode.valueOf(intermediateTag.getString(allKey))); + } + } } } - this.level.addParticle(ParticleTypes.SCULK_SOUL, posX, pos.getY()+0.1, posZ, 0,0.045,0); - }*/ - } - - public boolean canBeSoulPowered() { - return false; + } + if (tag.contains(filter)) { + for (IFilter iFilter : this.getMultiFilterComponent().getFilters()) { + if (tag.getCompound(filter).contains(iFilter.getName())) { + iFilter.deserializeNBT(tag.getCompound(filter).getCompound(iFilter.getName())); + } + } + } + markForUpdate(); } - public boolean isSoulPowered() { - return true; + @Override + public void saveSettings(Player player, CompoundTag tag) { + tag.put(settingsAddons, IMachineSettings.writeInventory(this.getAugmentInventory())); + tag.put(redstoneMode, NBTManager.getInstance().writeTileEntityObject(this, redstoneManager, new CompoundTag())); + CompoundTag sideInvTag = new CompoundTag(); + for (InventoryComponent inventoryHandler : this.getMultiInventoryComponent().getInventoryHandlers()) { + if (inventoryHandler instanceof SidedInventoryComponent sided) { + CompoundTag intermediateTag = new CompoundTag(); + for (FacingUtil.Sideness facing : sided.getFacingModes().keySet()) { + intermediateTag.putString(facing.name(), sided.getFacingModes().get(facing).name()); + } + sideInvTag.put(sided.getName(), intermediateTag); + } + } + tag.put(sidenessInventory, sideInvTag); + CompoundTag sideTankTag = new CompoundTag(); + for (FluidTankComponent fluidTankComponent : this.getMultiTankComponent().getTanks()) { + if (fluidTankComponent instanceof SidedFluidTankComponent sided) { + CompoundTag intermediateTag = new CompoundTag(); + for (FacingUtil.Sideness facing : sided.getFacingModes().keySet()) { + intermediateTag.putString(facing.name(), sided.getFacingModes().get(facing).name()); + } + sideTankTag.put(sided.getName(), intermediateTag); + } + } + tag.put(sidenessTank, sideTankTag); + CompoundTag filterTag = new CompoundTag(); + for (IFilter iFilter : this.getMultiFilterComponent().getFilters()) { + filterTag.put(iFilter.getName(), iFilter.serializeNBT()); + } + tag.put(filter, filterTag); } - } diff --git a/src/main/java/com/buuz135/industrial/item/MachineSettingCopier.java b/src/main/java/com/buuz135/industrial/item/MachineSettingCopier.java new file mode 100644 index 000000000..336ce635f --- /dev/null +++ b/src/main/java/com/buuz135/industrial/item/MachineSettingCopier.java @@ -0,0 +1,92 @@ +package com.buuz135.industrial.item; + +import com.buuz135.industrial.api.IMachineSettings; +import com.buuz135.industrial.utils.IndustrialTags; +import com.hrznstudio.titanium.item.BasicItem; +import com.hrznstudio.titanium.recipe.generator.TitaniumShapedRecipeBuilder; +import com.hrznstudio.titanium.tab.TitaniumTab; +import net.minecraft.ChatFormatting; +import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.InteractionResultHolder; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.Level; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.Consumer; + +public class MachineSettingCopier extends IFCustomItem { + + public MachineSettingCopier(TitaniumTab tab) { + super("machine_settings_copier", tab, new Properties().stacksTo(1)); + } + + @Override + public void registerRecipe(Consumer consumer) { + TitaniumShapedRecipeBuilder.shapedRecipe(this) + .pattern("PLP").pattern("LRL").pattern("PRP") + .define('P', Items.PAPER) + .define('R', Items.REDSTONE) + .define('L', IndustrialTags.Items.PLASTIC) + .save(consumer); + } + + @Override + public boolean hasTooltipDetails(@Nullable BasicItem.Key key) { + return key == null; + } + + @Override + public void addTooltipDetails(@Nullable BasicItem.Key key, ItemStack stack, List tooltip, boolean advanced) { + super.addTooltipDetails(key, stack, tooltip, advanced); + if (stack.hasTag()) { + tooltip.add(Component.translatable("text.industrialforegoing.machine_settings_copier.settings_stored").withStyle(ChatFormatting.GOLD)); + tooltip.add(Component.translatable("text.industrialforegoing.machine_settings_copier.settings_clear").withStyle(ChatFormatting.GRAY)); + } else { + tooltip.add(Component.translatable("text.industrialforegoing.machine_settings_copier.settings_can_copy").withStyle(ChatFormatting.GRAY)); + } + } + + @Override + public InteractionResult useOn(UseOnContext context) { + var tile = context.getLevel().getBlockEntity(context.getClickedPos()); + var player = context.getPlayer(); + var stack = context.getItemInHand(); + if (tile instanceof IMachineSettings machineSettings) { + if (stack.hasTag()) { + if (!context.getLevel().isClientSide()) machineSettings.loadSettings(player, stack.getTag()); + player.playSound(SoundEvents.ANVIL_USE, 0.1F, 1.0F); + player.displayClientMessage(Component.translatable("text.industrialforegoing.machine_settings_copier.settings_stored"), true); + return InteractionResult.SUCCESS; + } else { + if (!context.getLevel().isClientSide()) { + CompoundTag tag = new CompoundTag(); + machineSettings.saveSettings(player, tag); + stack.setTag(tag); + } + player.playSound(SoundEvents.ARROW_HIT_PLAYER, 0.5F, 1.0F); + player.displayClientMessage(Component.translatable("text.industrialforegoing.machine_settings_copier.settings_copied"), true); + return InteractionResult.SUCCESS; + } + } + return super.useOn(context); + } + + @Override + public InteractionResultHolder use(Level p_41432_, Player player, InteractionHand hand) { + if (player.isShiftKeyDown() && player.getItemInHand(hand).hasTag()) { + player.getItemInHand(hand).setTag(null); + player.playSound(SoundEvents.FIRE_EXTINGUISH, 0.5F, 1.0F); + return InteractionResultHolder.pass(player.getItemInHand(hand)); + } + return super.use(p_41432_, player, hand); + } +} diff --git a/src/main/java/com/buuz135/industrial/module/ModuleCore.java b/src/main/java/com/buuz135/industrial/module/ModuleCore.java index adbb903ff..2b297c70b 100644 --- a/src/main/java/com/buuz135/industrial/module/ModuleCore.java +++ b/src/main/java/com/buuz135/industrial/module/ModuleCore.java @@ -30,10 +30,7 @@ import com.buuz135.industrial.block.core.tile.FluidExtractorTile; import com.buuz135.industrial.fluid.OreFluidInstance; import com.buuz135.industrial.fluid.OreTitaniumFluidType; -import com.buuz135.industrial.item.FertilizerItem; -import com.buuz135.industrial.item.ItemStraw; -import com.buuz135.industrial.item.LaserLensItem; -import com.buuz135.industrial.item.RecipelessCustomItem; +import com.buuz135.industrial.item.*; import com.buuz135.industrial.item.addon.EfficiencyAddonItem; import com.buuz135.industrial.item.addon.ProcessingAddonItem; import com.buuz135.industrial.item.addon.RangeAddonItem; @@ -51,17 +48,15 @@ import net.minecraft.ChatFormatting; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffects; -import net.minecraft.world.item.*; +import net.minecraft.world.item.DyeColor; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Rarity; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.event.TickEvent; import net.minecraftforge.fluids.FluidType; -import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.RegistryObject; import org.apache.commons.lang3.tuple.Pair; @@ -97,6 +92,7 @@ public class ModuleCore implements IModule { public static RegistryObject EFFICIENCY_ADDON_2; public static RegistryObject PROCESSING_ADDON_1; public static RegistryObject PROCESSING_ADDON_2; + public static RegistryObject MACHINE_SETTINGS_COPIER; public static TitaniumFluidInstance LATEX; public static TitaniumFluidInstance MEAT; @@ -164,6 +160,7 @@ public void generateFeatures(DeferredRegistryHelper helper) { EFFICIENCY_ADDON_2 = helper.registerGeneric(ForgeRegistries.ITEMS.getRegistryKey(), "efficiency_addon_2", () -> new EfficiencyAddonItem(2, TAB_CORE)); PROCESSING_ADDON_1 = helper.registerGeneric(ForgeRegistries.ITEMS.getRegistryKey(), "processing_addon_1", () -> new ProcessingAddonItem(1, TAB_CORE)); PROCESSING_ADDON_2 = helper.registerGeneric(ForgeRegistries.ITEMS.getRegistryKey(), "processing_addon_2", () -> new ProcessingAddonItem(2, TAB_CORE)); + MACHINE_SETTINGS_COPIER = helper.registerGeneric(ForgeRegistries.ITEMS.getRegistryKey(), "machine_settings_copier", () -> new MachineSettingCopier(TAB_CORE)); LATEX = new TitaniumFluidInstance(helper, "latex", FluidType.Properties.create().density(1000), new ClientFluidTypeExtensions(new ResourceLocation(Reference.MOD_ID, "block/fluids/latex_still"), new ResourceLocation(Reference.MOD_ID, "block/fluids/latex_flow")), TAB_CORE); MEAT = new TitaniumFluidInstance(helper, "meat", FluidType.Properties.create().density(1000), new ClientFluidTypeExtensions(new ResourceLocation(Reference.MOD_ID, "block/fluids/meat_still"), new ResourceLocation(Reference.MOD_ID, "block/fluids/meat_flow")), TAB_CORE); diff --git a/src/main/java/com/buuz135/industrial/proxy/client/ClientProxy.java b/src/main/java/com/buuz135/industrial/proxy/client/ClientProxy.java index fa4d96e41..72a3f7a14 100644 --- a/src/main/java/com/buuz135/industrial/proxy/client/ClientProxy.java +++ b/src/main/java/com/buuz135/industrial/proxy/client/ClientProxy.java @@ -170,6 +170,9 @@ public void run() { } return 2f; }); + ItemProperties.register(ModuleCore.MACHINE_SETTINGS_COPIER.get(), new ResourceLocation(Reference.MOD_ID, "stored"), (stack, world, entity, number) -> { + return stack.hasTag() ? 1 : 0; + }); } @SubscribeEvent diff --git a/src/main/java/com/buuz135/industrial/recipe/provider/IndustrialRecipeProvider.java b/src/main/java/com/buuz135/industrial/recipe/provider/IndustrialRecipeProvider.java index 761b72a78..dd9b30c90 100644 --- a/src/main/java/com/buuz135/industrial/recipe/provider/IndustrialRecipeProvider.java +++ b/src/main/java/com/buuz135/industrial/recipe/provider/IndustrialRecipeProvider.java @@ -89,6 +89,7 @@ public void register(Consumer consumer) { ((IRecipeProvider) ModuleCore.EFFICIENCY_ADDON_2.get()).registerRecipe(consumer); ((IRecipeProvider) ModuleCore.PROCESSING_ADDON_1.get()).registerRecipe(consumer); ((IRecipeProvider) ModuleCore.PROCESSING_ADDON_2.get()).registerRecipe(consumer); + ((IRecipeProvider) ModuleCore.MACHINE_SETTINGS_COPIER.get()).registerRecipe(consumer); TitaniumShapelessRecipeBuilder.shapelessRecipe(ModuleCore.DRY_RUBBER.get()).requires(ModuleCore.TINY_DRY_RUBBER.get(), 9).save(consumer); SimpleCookingRecipeBuilder.smelting(Ingredient.of(ModuleCore.DRY_RUBBER.get()), RecipeCategory.MISC, ModuleCore.PLASTIC.get(), 0.3f, 200).unlockedBy("has_plastic", this.has(ModuleCore.DRY_RUBBER.get())).save(consumer); TitaniumShapedRecipeBuilder.shapedRecipe(ModuleCore.PITY.get()) diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index ca16425c6..27d216f91 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -29,7 +29,7 @@ IF: You need to automate all the things [[dependencies.industrialforegoing]] #optional modId = "titanium" #mandatory mandatory = true #mandatory -versionRange = "[3.8.25,)" #mandatory +versionRange = "[3.8.32,)" #mandatory ordering = "NONE" side = "BOTH" [[dependencies.industrialforegoing]] #optional diff --git a/src/main/resources/assets/industrialforegoing/lang/en_us.json b/src/main/resources/assets/industrialforegoing/lang/en_us.json index 9215a478a..d615a10e0 100644 --- a/src/main/resources/assets/industrialforegoing/lang/en_us.json +++ b/src/main/resources/assets/industrialforegoing/lang/en_us.json @@ -395,6 +395,7 @@ "item.industrialforegoing.item_transporter_type": "Item Transporter", "item.industrialforegoing.fluid_transporter_type": "Fluid Transporter", "item.industrialforegoing.world_transporter_type": "World Transporter", + "item.industrialforegoing.machine_settings_copier": "Machine Settings Copier", "tooltip.titanium.facing_handler.lens": "Laser Lens", "tooltip.titanium.facing_handler.fuel_input": "Fuel Input", "tooltip.titanium.facing_handler.input_fluid": "Fluid Input", @@ -581,5 +582,9 @@ "industrialforegoing.subtitle.nuke_arming": "Infinity Nuke being armed", "industrialforegoing.subtitle.nuke_charging": "Infinity Nuke is charging", "industrialforegoing.subtitle.nuke_explosion": "Embrace Infinity Nuke's death and destruction", - "entity.industrialforegoing.infinity_nuke": "Infinity Nuke" + "entity.industrialforegoing.infinity_nuke": "Infinity Nuke", + "text.industrialforegoing.machine_settings_copier.settings_stored": "Settings Stored", + "text.industrialforegoing.machine_settings_copier.settings_copied": "Settings Copied", + "text.industrialforegoing.machine_settings_copier.settings_clear": "* Sneak Right Click to clear the copied settings", + "text.industrialforegoing.machine_settings_copier.settings_can_copy": "* Sneak Right Click a machine to copy the machine settings" } diff --git a/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier.json b/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier.json new file mode 100644 index 000000000..0b8fcdd1e --- /dev/null +++ b/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier.json @@ -0,0 +1,20 @@ +{ + "parent": "industrialforegoing:item/item", + "textures": { + "layer0": "industrialforegoing:item/machine_setting_copier" + }, + "overrides": [ + { + "predicate": { + "industrialforegoing:stored": 0 + }, + "model": "industrialforegoing:item/machine_settings_copier_empty" + }, + { + "predicate": { + "industrialforegoing:stored": 1 + }, + "model": "industrialforegoing:item/machine_settings_copier_stored" + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier_empty.json b/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier_empty.json new file mode 100644 index 000000000..1677e7325 --- /dev/null +++ b/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier_empty.json @@ -0,0 +1,6 @@ +{ + "parent": "industrialforegoing:item/item", + "textures": { + "layer0": "industrialforegoing:item/machine_setting_copier" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier_stored.json b/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier_stored.json new file mode 100644 index 000000000..24844df42 --- /dev/null +++ b/src/main/resources/assets/industrialforegoing/models/item/machine_settings_copier_stored.json @@ -0,0 +1,6 @@ +{ + "parent": "industrialforegoing:item/item", + "textures": { + "layer0": "industrialforegoing:item/machine_setting_copier_stored" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/industrialforegoing/textures/item/machine_setting_copier.png b/src/main/resources/assets/industrialforegoing/textures/item/machine_setting_copier.png new file mode 100644 index 0000000000000000000000000000000000000000..903b4c56e60fb0d73c2d5fe821e7db4b63381efb GIT binary patch literal 397 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GG!XV7ZFl&wk0|TSI zr;B5VMQ`$-|Nrfofxy}IatKFrW8=fu)AM=m*u?O>cmQM-e0#Dk$c+sMj{X1t-#Em? z_wW4KQhf^<KnkjQ{THqFH88|C{OX;DT8f+V~J%myZyxuPV;9jEB^fR7Y z4_{yqZoata5L1Dr8XMb{0|(i{_Ez^g?XUaIc$FbXv5&uli~GRWgo=gRD^%Osj<5Y4 zkdeY*&hTu_qd1R}F4pWrq9?I+4VDLeGg!hlgi^Lrdku z!q;|eWxSpiyu!}knA#W({=fO?mmtvFyo1GZmBgOH-8}Pz*5BE6TtQ9eM8VT*wr$_q zqS(a3#MX;P!sC>Jqg{*3u6x``c+E^^cizr>yK4v`0BAVf zFad(alI@)>RuL?gD(}4B832Y5f`-!-x3%+F!#Z@{dOSC;jkI1YKiqHB{Q2~v@(4ku zT-=Dj^XE!VYIX6Zb`)!nH5v0(R;{HVYEBZ~zr9HG{CSih$?wx>4jJ{|*qCa*P7>f98{MBUjW=o9HkLujIuFlqJ4l#43Lnl2$m zAoYAyugG79ljv7P_5aD#OB{||Y|CUga&enYDuo<_>5NJt2f$!DqvSZ)mdTg@6DP1O zQx!{&!x$(5V_DNq)%O}n-&vQXLq48hvE<-z-?%tE;TQFhdOCLr$qfJi002ovPDHLk FV1i0StjYiY literal 0 HcmV?d00001