From c1e274db4f94b3a355f0685d8feb4f02fc134456 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Tue, 5 Nov 2024 20:54:40 -0600 Subject: [PATCH] Fixed some machines not keeping energy when broken. More left todo. --- CHANGELOG.md | 10 ++++++++++ gradle.properties | 2 +- .../59eb3dbb5f86130e09b3c62d89b9525ee01cf52d | 4 ++-- .../loot_table/blocks/leaf_generator.json | 9 +++++++++ .../data/LootTableGenerator.java | 2 +- .../mod/blocks/AABlockItem.java | 11 +++------- .../mod/blocks/ActuallyBlocks.java | 2 +- .../mod/blocks/BlockAtomicReconstructor.java | 20 +++++++------------ .../tile/TileEntityAtomicReconstructor.java | 20 +++++++++++++++++++ .../mod/tile/TileEntityCoalGenerator.java | 17 ++++++++++++++++ .../mod/tile/TileEntityCrusher.java | 17 ++++++++++++++++ .../mod/tile/TileEntityDisplayStand.java | 18 +++++++++++++++++ .../mod/tile/TileEntityLeafGenerator.java | 17 ++++++++++++++++ .../mod/tile/TileEntityOilGenerator.java | 16 +++++++++++++++ .../mod/tile/TileEntityPoweredFurnace.java | 16 +++++++++++++++ 15 files changed, 155 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 191407c08..dcac5da4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +# 1.3.10+mc1.21.1 +* Fixed some machines not holding power when broken, The following machines now keep their stored energy when broken: + * Coal Generator + * Oil Generator + * Leaf eating generator + * Crushers + * Display Stand + * Powered Furnace + * Atomic Reconstructor + # 1.3.9+mc1.21.1 * Change laser rendering to be compatible with Iris * Fix machines in the Engineer House being obtainable when broken diff --git a/gradle.properties b/gradle.properties index beeceb2bd..312ab5bdb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.parallel=true org.gradle.caching=true org.gradle.configuration-cache=false -mod_version=1.3.9 +mod_version=1.3.10 # Forge game_version=1.21.1 diff --git a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d index 58391b51f..86fe288ba 100644 --- a/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d +++ b/src/generated/resources/.cache/59eb3dbb5f86130e09b3c62d89b9525ee01cf52d @@ -1,4 +1,4 @@ -// 1.21.1 2024-10-16T22:24:12.9580535 Loot Tables +// 1.21.1 2024-11-05T20:37:45.5911624 Loot Tables ef11aa79a2f96a47250f46811f8491fd34d627f9 data/actuallyadditions/loot_table/blocks/atomic_reconstructor.json e15c868b26b669c30365bfb93e7d9274e07df16d data/actuallyadditions/loot_table/blocks/battery_box.json 745d64af3b0203a138f9eca7de21ed4988b35c95 data/actuallyadditions/loot_table/blocks/bio_reactor.json @@ -91,7 +91,7 @@ af0cb5ad3473b274da2873d3e08da0f4085e6699 data/actuallyadditions/loot_table/block 04f2ec311197a6e8770d30704448ee6abba70e32 data/actuallyadditions/loot_table/blocks/laser_relay_item_advanced.json 395d67efbd229f614c51bd96f637797f035cc7e3 data/actuallyadditions/loot_table/blocks/lava_factory_casing.json f8a03e56a032e858126f1b1861ea0b759a3e517d data/actuallyadditions/loot_table/blocks/lava_factory_controller.json -82e3d0039b6702d62c5460953426812d798cdc37 data/actuallyadditions/loot_table/blocks/leaf_generator.json +b5acba2bc0fc0ba58b60b1c929bb67a1a8fe96cb data/actuallyadditions/loot_table/blocks/leaf_generator.json 27ba42bb0f2dca72e29393944b61e566d758a2dc data/actuallyadditions/loot_table/blocks/long_range_breaker.json 43113c67b268280ce09b9c90df83f33c15bf2f06 data/actuallyadditions/loot_table/blocks/oil_generator.json f0905fdc46775bb0d7382375b0a1109d125175e7 data/actuallyadditions/loot_table/blocks/palis_crystal_block.json diff --git a/src/generated/resources/data/actuallyadditions/loot_table/blocks/leaf_generator.json b/src/generated/resources/data/actuallyadditions/loot_table/blocks/leaf_generator.json index e8361b0d7..e2d22bf0b 100644 --- a/src/generated/resources/data/actuallyadditions/loot_table/blocks/leaf_generator.json +++ b/src/generated/resources/data/actuallyadditions/loot_table/blocks/leaf_generator.json @@ -14,6 +14,15 @@ "name": "actuallyadditions:leaf_generator" } ], + "functions": [ + { + "function": "minecraft:copy_components", + "include": [ + "actuallyadditions:energy" + ], + "source": "block_entity" + } + ], "rolls": 1.0 } ], diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java index 2888c90e7..269c588a6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java @@ -75,6 +75,7 @@ public class LootTableGenerator extends LootTableProvider { dropKeepEnergy(ActuallyBlocks.DISPLAY_STAND); dropKeepEnergy(ActuallyBlocks.COAL_GENERATOR); dropKeepEnergy(ActuallyBlocks.OIL_GENERATOR); + dropKeepEnergy(ActuallyBlocks.LEAF_GENERATOR); dropKeepEnergy(ActuallyBlocks.CRUSHER); dropKeepEnergy(ActuallyBlocks.CRUSHER_DOUBLE); dropKeepEnergy(ActuallyBlocks.POWERED_FURNACE); @@ -114,7 +115,6 @@ public class LootTableGenerator extends LootTableProvider { this.dropSelf(ActuallyBlocks.PHANTOM_BOOSTER.get()); this.dropSelf(ActuallyBlocks.RANGED_COLLECTOR.get()); this.dropSelf(ActuallyBlocks.LONG_RANGE_BREAKER.get()); - this.dropSelf(ActuallyBlocks.LEAF_GENERATOR.get()); this.dropSelf(ActuallyBlocks.XP_SOLIDIFIER.get()); this.dropSelf(ActuallyBlocks.LASER_RELAY.get()); this.dropSelf(ActuallyBlocks.LASER_RELAY_ADVANCED.get()); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/AABlockItem.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/AABlockItem.java index 3b46ccf8d..8a9ef2b97 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/AABlockItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/AABlockItem.java @@ -1,12 +1,11 @@ package de.ellpeck.actuallyadditions.mod.blocks; -import net.minecraft.core.component.DataComponents; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import net.minecraft.network.chat.Component; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemNameBlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.item.component.CustomData; import net.minecraft.world.level.block.Block; import javax.annotation.Nullable; @@ -38,12 +37,8 @@ public class AABlockItem extends BlockItem { public void appendHoverText(ItemStack pStack, @Nullable TooltipContext pContext, List pTooltip, TooltipFlag pFlag) { super.appendHoverText(pStack, pContext, pTooltip, pFlag); - if (pStack.has(DataComponents.BLOCK_ENTITY_DATA)) { - CustomData customData = pStack.get(DataComponents.BLOCK_ENTITY_DATA); - int energy = 0; - if (customData.contains("Energy")) { - energy = customData.copyTag().getInt("Energy"); - } + if (pStack.has(ActuallyComponents.ENERGY_STORAGE)) { + int energy = pStack.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0); NumberFormat format = NumberFormat.getInstance(); pTooltip.add(Component.translatable("misc.actuallyadditions.power_single", format.format(energy))); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java index 765beb687..530e11e59 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java @@ -126,7 +126,7 @@ public final class ActuallyBlocks { (b) -> new AABlockItem.BlockEntityEnergyItem(b, defaultBlockItemProperties), TileEntityCoalGenerator::new); public static final AABlockReg LEAF_GENERATOR = new AABlockReg<>("leaf_generator", BlockLeafGenerator::new, - (b) -> new AABlockItem(b, defaultBlockItemProperties) , TileEntityLeafGenerator::new); + (b) -> new AABlockItem.BlockEntityEnergyItem(b, defaultBlockItemProperties) , TileEntityLeafGenerator::new); public static final AABlockReg XP_SOLIDIFIER = new AABlockReg<>("xp_solidifier", BlockXPSolidifier::new, (b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityXPSolidifier::new); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java index 288233f09..db3a02908 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java @@ -14,10 +14,10 @@ import de.ellpeck.actuallyadditions.api.lens.ILensItem; import de.ellpeck.actuallyadditions.mod.blocks.base.FullyDirectionalBlock; import de.ellpeck.actuallyadditions.mod.blocks.blockhuds.IBlockHud; import de.ellpeck.actuallyadditions.mod.blocks.blockhuds.ReconstructorHud; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; -import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.util.Mth; import net.minecraft.util.RandomSource; @@ -27,7 +27,6 @@ import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; -import net.minecraft.world.item.component.CustomData; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; @@ -154,19 +153,14 @@ public class BlockAtomicReconstructor extends FullyDirectionalBlock.Container im String base = block.getDescriptionId() + ".info."; pTooltip.add(Component.translatable(base + "1." + this.toPick1).append(" ").append(Component.translatable(base + "2." + this.toPick2)).withStyle(s -> s.withColor(ChatFormatting.GRAY))); - if (pStack.has(DataComponents.CUSTOM_DATA) ) { - CustomData customData = pStack.get(DataComponents.CUSTOM_DATA); - int energy = 0; - if (customData.contains("Energy")) { - energy = customData.copyTag().getInt("Energy"); - } + if (pStack.has(ActuallyComponents.ENERGY_STORAGE) ) { + int energy = pStack.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0); NumberFormat format = NumberFormat.getInstance(); pTooltip.add(Component.translatable("misc.actuallyadditions.power_single", format.format(energy)).withStyle(ChatFormatting.GRAY)); - - if (customData.contains("IsPulseMode")) { - pTooltip.add(Component.translatable("info.actuallyadditions.redstoneMode").append(": ") - .append(Component.translatable(customData.copyTag().getBoolean("IsPulseMode")?"info.actuallyadditions.redstoneMode.pulse":"info.actuallyadditions.redstoneMode.deactivation").withStyle($ -> $.withColor(ChatFormatting.RED)))); - } + } + if (pStack.has(ActuallyComponents.PULSE_MODE)) { + pTooltip.add(Component.translatable("info.actuallyadditions.redstoneMode").append(": ") + .append(Component.translatable(pStack.getOrDefault(ActuallyComponents.PULSE_MODE, false)?"info.actuallyadditions.redstoneMode.pulse":"info.actuallyadditions.redstoneMode.deactivation").withStyle($ -> $.withColor(ChatFormatting.RED)))); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java index 68a6b4fe9..c6acb25d1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.api.lens.ILensItem; import de.ellpeck.actuallyadditions.api.lens.Lens; import de.ellpeck.actuallyadditions.mod.AASounds; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.network.PacketHelperServer; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor; @@ -23,6 +24,7 @@ import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundSource; @@ -33,6 +35,8 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.energy.IEnergyStorage; +import javax.annotation.Nonnull; + public class TileEntityAtomicReconstructor extends TileEntityInventoryBase implements IEnergyDisplay, IAtomicReconstructor { public static final int ENERGY_USE = 1000; @@ -222,4 +226,20 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple public IEnergyStorage getEnergyStorage(Direction facing) { return this.storage; } + + @Override + protected void applyImplicitComponents(@Nonnull DataComponentInput input) { + super.applyImplicitComponents(input); + + storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); + this.isPulseMode = input.getOrDefault(ActuallyComponents.PULSE_MODE, false); + } + + @Override + protected void collectImplicitComponents(@Nonnull DataComponentMap.Builder builder) { + super.collectImplicitComponents(builder); + + builder.set(ActuallyComponents.ENERGY_STORAGE, storage.getEnergyStored()); + builder.set(ActuallyComponents.PULSE_MODE, isPulseMode); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java index 7b5c58066..af9cd9e01 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCoalGenerator.java @@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.crafting.SolidFuelRecipe; import de.ellpeck.actuallyadditions.mod.inventory.ContainerCoalGenerator; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA.IAcceptor; @@ -20,6 +21,7 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -34,6 +36,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.energy.IEnergyStorage; +import javax.annotation.Nonnull; import javax.annotation.Nullable; public class TileEntityCoalGenerator extends TileEntityInventoryBase implements MenuProvider, ISharingEnergyProvider, IEnergyDisplay { @@ -209,4 +212,18 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements public boolean needsHoldShift() { return false; } + + @Override + protected void applyImplicitComponents(@Nonnull DataComponentInput input) { + super.applyImplicitComponents(input); + + storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); + } + + @Override + protected void collectImplicitComponents(@Nonnull DataComponentMap.Builder builder) { + super.collectImplicitComponents(builder); + + builder.set(ActuallyComponents.ENERGY_STORAGE, storage.getEnergyStored()); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java index d8f5e6049..9b7939a32 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityCrusher.java @@ -13,6 +13,7 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.mod.AASounds; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe; import de.ellpeck.actuallyadditions.mod.inventory.CrusherContainer; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; @@ -22,6 +23,7 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundSource; @@ -38,6 +40,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.neoforged.neoforge.energy.IEnergyStorage; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Optional; @@ -289,4 +292,18 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto public AbstractContainerMenu createMenu(int windowId, Inventory playerInventory, Player player) { return new CrusherContainer(windowId, playerInventory, this); } + + @Override + protected void applyImplicitComponents(@Nonnull DataComponentInput input) { + super.applyImplicitComponents(input); + + storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); + } + + @Override + protected void collectImplicitComponents(@Nonnull DataComponentMap.Builder builder) { + super.collectImplicitComponents(builder); + + builder.set(ActuallyComponents.ENERGY_STORAGE, storage.getEnergyStored()); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java index 2c8970a54..0ed2d9cdb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityDisplayStand.java @@ -12,9 +12,11 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.misc.IDisplayStandItem; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.Item; @@ -25,6 +27,8 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.energy.IEnergyStorage; +import javax.annotation.Nonnull; + public class TileEntityDisplayStand extends TileEntityInventoryBase implements IEnergyDisplay { public final CustomEnergyStorage storage = new CustomEnergyStorage(80000, 1000, 0); @@ -114,4 +118,18 @@ public class TileEntityDisplayStand extends TileEntityInventoryBase implements I public ItemStack getStack() { return this.inv.getStackInSlot(0); } + + @Override + protected void applyImplicitComponents(@Nonnull DataComponentInput input) { + super.applyImplicitComponents(input); + + storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); + } + + @Override + protected void collectImplicitComponents(@Nonnull DataComponentMap.Builder builder) { + super.collectImplicitComponents(builder); + + builder.set(ActuallyComponents.ENERGY_STORAGE, storage.getEnergyStored()); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java index 07871b089..b73be8a37 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java @@ -11,11 +11,13 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.network.PacketHelperServer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerLevel; import net.minecraft.tags.BlockTags; @@ -27,6 +29,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.energy.IEnergyStorage; +import javax.annotation.Nonnull; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -137,4 +140,18 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE public IEnergyStorage getEnergyStorage(Direction facing) { return this.storage; } + + @Override + protected void applyImplicitComponents(@Nonnull DataComponentInput input) { + super.applyImplicitComponents(input); + + storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); + } + + @Override + protected void collectImplicitComponents(@Nonnull DataComponentMap.Builder builder) { + super.collectImplicitComponents(builder); + + builder.set(ActuallyComponents.ENERGY_STORAGE, storage.getEnergyStored()); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java index 72e321177..ea47267ec 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java @@ -12,12 +12,14 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.config.CommonConfig; import de.ellpeck.actuallyadditions.mod.crafting.LiquidFuelRecipe; import de.ellpeck.actuallyadditions.mod.inventory.ContainerOilGenerator; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.MenuProvider; @@ -229,4 +231,18 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn public AbstractContainerMenu createMenu(int windowId, Inventory playerInventory, Player player) { return new ContainerOilGenerator(windowId, playerInventory, this); } + + @Override + protected void applyImplicitComponents(@Nonnull DataComponentInput input) { + super.applyImplicitComponents(input); + + storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); + } + + @Override + protected void collectImplicitComponents(@Nonnull DataComponentMap.Builder builder) { + super.collectImplicitComponents(builder); + + builder.set(ActuallyComponents.ENERGY_STORAGE, storage.getEnergyStored()); + } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java index fc21a5406..1712f16d8 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.mod.tile; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents; import de.ellpeck.actuallyadditions.mod.inventory.ContainerFurnaceDouble; import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor; import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA; @@ -20,6 +21,7 @@ import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.world.MenuProvider; @@ -264,4 +266,18 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements public AbstractContainerMenu createMenu(int windowId, @Nonnull Inventory playerInventory, @Nonnull Player player) { return new ContainerFurnaceDouble(windowId, playerInventory, this); } + + @Override + protected void applyImplicitComponents(@Nonnull DataComponentInput input) { + super.applyImplicitComponents(input); + + storage.setEnergyStored(input.getOrDefault(ActuallyComponents.ENERGY_STORAGE, 0)); + } + + @Override + protected void collectImplicitComponents(@Nonnull DataComponentMap.Builder builder) { + super.collectImplicitComponents(builder); + + builder.set(ActuallyComponents.ENERGY_STORAGE, storage.getEnergyStored()); + } }