From e8fee61c9174544e82832aac5b5f666517497147 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Fri, 14 Oct 2022 18:58:04 -0500 Subject: [PATCH] More tiles storing energy... --- src/generated/resources/.cache/cache | 8 ++--- .../blocks/atomic_reconstructor.json | 4 --- .../loot_tables/blocks/coal_generator.json | 13 ++++++++ .../loot_tables/blocks/display_stand.json | 13 ++++++++ .../loot_tables/blocks/oil_generator.json | 13 ++++++++ .../data/LootTableGenerator.java | 22 +++++++------ .../mod/blocks/AABlockItem.java | 32 +++++++++++++++++++ .../mod/blocks/ActuallyBlocks.java | 6 ++-- .../mod/blocks/BlockAtomicReconstructor.java | 18 +++++++++++ .../mod/tile/CustomEnergyStorage.java | 3 +- 10 files changed, 110 insertions(+), 22 deletions(-) diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index ceb4de423..bc67f7f74 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -454,7 +454,7 @@ f657eabc7321de0b05cf92d9ebdd6f5215a685b5 assets/actuallyadditions/models/item/wo 7f8e5e703d9244222706c52d7b24b299e07cb2db assets/actuallyadditions/models/item/worm.json 0b1ab8963077c90a5104b516eab36e56c8a07057 assets/actuallyadditions/models/item/xp_solidifier.json ecf1cc8efe1f425334e8e07a6c747641c714c92c assets/actuallyadditions/sounds.json -214cf5b268cb34e55c2232cc7c694e81f388dc1f data/actuallyadditions/loot_tables/blocks/atomic_reconstructor.json +b679296118ae905d4a15b6bc658cfa7b8048e57f data/actuallyadditions/loot_tables/blocks/atomic_reconstructor.json de3c64d6a363f8e27078d7f7df1a67e4931fd81c data/actuallyadditions/loot_tables/blocks/battery_box.json fb968dc63f2d0a467eff504f3f6ff386080e2433 data/actuallyadditions/loot_tables/blocks/bio_reactor.json a1b62291e361451916e45a97bb499ecb1b6eb595 data/actuallyadditions/loot_tables/blocks/black_quartz_block.json @@ -477,14 +477,14 @@ f3df22f203e8c00ee7ee004bb9b4edfd522f069a data/actuallyadditions/loot_tables/bloc 7b10afffb30390977f1729356e0b4959ccb4cf1c data/actuallyadditions/loot_tables/blocks/chiseled_black_quartz_slab.json 6df5538ba7cf057d19728f8e615862a84b9d4bb1 data/actuallyadditions/loot_tables/blocks/chiseled_black_quartz_stair.json 092e8773d46f16d80d0c489c4a2d2f8bd5a78799 data/actuallyadditions/loot_tables/blocks/chiseled_black_quartz_wall.json -d1f6498ad95f87ca8ad0aa78f356bf4a76f78842 data/actuallyadditions/loot_tables/blocks/coal_generator.json +bf7743c27757cf5b0dbab9b3e15d1d5ca1ece818 data/actuallyadditions/loot_tables/blocks/coal_generator.json 66ee33930c8392b29710ce2bc117f99907e336df data/actuallyadditions/loot_tables/blocks/coffee.json 3285202e3f840d091b8d85dc2c721199fcc96240 data/actuallyadditions/loot_tables/blocks/coffee_machine.json 98c2198bf7df995a8c43f08101eb2021a62e1dec data/actuallyadditions/loot_tables/blocks/crusher.json 93c16ed7d46e44ceafdc32c2a440f98b8c805723 data/actuallyadditions/loot_tables/blocks/crusher_double.json 6336ca572b8d81f6e06b43bb925b48bb915b6574 data/actuallyadditions/loot_tables/blocks/diamatine_crystal_block.json b9ed4007fec7a382a02b08b231f072df6aa40049 data/actuallyadditions/loot_tables/blocks/diamatine_crystal_cluster.json -6097f74352ae6f7ad59736cd6cf4bc545aa8a39d data/actuallyadditions/loot_tables/blocks/display_stand.json +7476dbc0cbb3c1a8ce5a3c1562f73fcfb4adcd10 data/actuallyadditions/loot_tables/blocks/display_stand.json 162331b9fbc67309820a20377575336e63ed3e74 data/actuallyadditions/loot_tables/blocks/dropper.json 3b93e666ae7c49a182e771063901b27da8dcfb3f data/actuallyadditions/loot_tables/blocks/emeradic_crystal_block.json 9fec34737374133601990074c4156334ab3841ad data/actuallyadditions/loot_tables/blocks/emeradic_crystal_cluster.json @@ -547,7 +547,7 @@ d97afdaa98f4202a2fc767599a4e5e34ffbefa71 data/actuallyadditions/loot_tables/bloc a26c16e8bf499948ef947d5e7e2e6691e0c7e1a8 data/actuallyadditions/loot_tables/blocks/lava_factory_controller.json d2cfb9e1d68cfabcf21f2847cf66760b514bb510 data/actuallyadditions/loot_tables/blocks/leaf_generator.json 644aab55582d80b4b1fb9857b1b136b3f50bbe79 data/actuallyadditions/loot_tables/blocks/long_range_breaker.json -c21bd06177fdd1d367bfb58dd241cdfd2134f0d8 data/actuallyadditions/loot_tables/blocks/oil_generator.json +0317d1a12de12767cac13a5a2c9d173198b7e600 data/actuallyadditions/loot_tables/blocks/oil_generator.json 8a49a3773ea9ac5f56b68373671fbf535a33ae0b data/actuallyadditions/loot_tables/blocks/palis_crystal_block.json 101ae500268810b6ec90bfcbbecc6ddfdd843e74 data/actuallyadditions/loot_tables/blocks/palis_crystal_cluster.json 84e7d1632faf9762a0112e3d7ba7e83f49a8707a data/actuallyadditions/loot_tables/blocks/phantom_booster.json diff --git a/src/generated/resources/data/actuallyadditions/loot_tables/blocks/atomic_reconstructor.json b/src/generated/resources/data/actuallyadditions/loot_tables/blocks/atomic_reconstructor.json index e33e318b8..7f8a593e1 100644 --- a/src/generated/resources/data/actuallyadditions/loot_tables/blocks/atomic_reconstructor.json +++ b/src/generated/resources/data/actuallyadditions/loot_tables/blocks/atomic_reconstructor.json @@ -15,10 +15,6 @@ } ], "functions": [ - { - "function": "minecraft:copy_name", - "source": "block_entity" - }, { "function": "minecraft:copy_nbt", "source": "block_entity", diff --git a/src/generated/resources/data/actuallyadditions/loot_tables/blocks/coal_generator.json b/src/generated/resources/data/actuallyadditions/loot_tables/blocks/coal_generator.json index ed10b67ff..dbb3d389d 100644 --- a/src/generated/resources/data/actuallyadditions/loot_tables/blocks/coal_generator.json +++ b/src/generated/resources/data/actuallyadditions/loot_tables/blocks/coal_generator.json @@ -13,6 +13,19 @@ { "condition": "minecraft:survives_explosion" } + ], + "functions": [ + { + "function": "minecraft:copy_nbt", + "source": "block_entity", + "ops": [ + { + "source": "Energy", + "target": "BlockEntityTag.Energy", + "op": "replace" + } + ] + } ] } ] diff --git a/src/generated/resources/data/actuallyadditions/loot_tables/blocks/display_stand.json b/src/generated/resources/data/actuallyadditions/loot_tables/blocks/display_stand.json index 64544d701..77fcb37f1 100644 --- a/src/generated/resources/data/actuallyadditions/loot_tables/blocks/display_stand.json +++ b/src/generated/resources/data/actuallyadditions/loot_tables/blocks/display_stand.json @@ -13,6 +13,19 @@ { "condition": "minecraft:survives_explosion" } + ], + "functions": [ + { + "function": "minecraft:copy_nbt", + "source": "block_entity", + "ops": [ + { + "source": "Energy", + "target": "BlockEntityTag.Energy", + "op": "replace" + } + ] + } ] } ] diff --git a/src/generated/resources/data/actuallyadditions/loot_tables/blocks/oil_generator.json b/src/generated/resources/data/actuallyadditions/loot_tables/blocks/oil_generator.json index 2f672224d..4405208c1 100644 --- a/src/generated/resources/data/actuallyadditions/loot_tables/blocks/oil_generator.json +++ b/src/generated/resources/data/actuallyadditions/loot_tables/blocks/oil_generator.json @@ -13,6 +13,19 @@ { "condition": "minecraft:survives_explosion" } + ], + "functions": [ + { + "function": "minecraft:copy_nbt", + "source": "block_entity", + "ops": [ + { + "source": "Energy", + "target": "BlockEntityTag.Energy", + "op": "replace" + } + ] + } ] } ] diff --git a/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java index 95d03f881..74aeff35e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/data/LootTableGenerator.java @@ -49,6 +49,15 @@ public class LootTableGenerator extends LootTableProvider { public static class Blocks extends BlockLootTables { @Override protected void addTables() { + CopyNbt.Builder copyEnergy = CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY).copy("Energy", "BlockEntityTag.Energy"); + CopyNbt.Builder copyPulseMode = CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY).copy("IsPulseMode", "BlockEntityTag.IsPulseMode"); + + //Special Drops + dropNBT(ActuallyBlocks.ATOMIC_RECONSTRUCTOR, $ -> $.apply(copyEnergy).apply(copyPulseMode)); + dropKeepEnergy(ActuallyBlocks.DISPLAY_STAND); + dropKeepEnergy(ActuallyBlocks.COAL_GENERATOR); + dropKeepEnergy(ActuallyBlocks.OIL_GENERATOR); + this.dropSelf(ActuallyBlocks.BATTERY_BOX.get()); this.dropSelf(ActuallyBlocks.ITEM_INTERFACE_HOPPING.get()); this.dropSelf(ActuallyBlocks.FARMER.get()); @@ -56,17 +65,10 @@ public class LootTableGenerator extends LootTableProvider { this.dropSelf(ActuallyBlocks.EMPOWERER.get()); this.dropSelf(ActuallyBlocks.TINY_TORCH.get()); this.dropSelf(ActuallyBlocks.SHOCK_SUPPRESSOR.get()); - this.dropSelf(ActuallyBlocks.DISPLAY_STAND.get()); this.dropSelf(ActuallyBlocks.PLAYER_INTERFACE.get()); this.dropSelf(ActuallyBlocks.ITEM_INTERFACE.get()); this.dropSelf(ActuallyBlocks.FIREWORK_BOX.get()); this.dropSelf(ActuallyBlocks.VERTICAL_DIGGER.get()); - - dropNBT(ActuallyBlocks.ATOMIC_RECONSTRUCTOR, a -> - a.apply(CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY).copy("Energy", "BlockEntityTag.Energy")) - .apply(CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY).copy("IsPulseMode", "BlockEntityTag.IsPulseMode")) - ); - this.dropSelf(ActuallyBlocks.ENERGIZER.get()); this.dropSelf(ActuallyBlocks.ENERVATOR.get()); this.dropSelf(ActuallyBlocks.LAVA_FACTORY_CONTROLLER.get()); @@ -77,8 +79,6 @@ public class LootTableGenerator extends LootTableProvider { this.dropSelf(ActuallyBlocks.PHANTOM_ENERGYFACE.get()); this.dropSelf(ActuallyBlocks.PHANTOM_REDSTONEFACE.get()); this.dropSelf(ActuallyBlocks.PHANTOM_BREAKER.get()); - this.dropSelf(ActuallyBlocks.COAL_GENERATOR.get()); - this.dropSelf(ActuallyBlocks.OIL_GENERATOR.get()); this.dropSelf(ActuallyBlocks.FERMENTING_BARREL.get()); this.dropSelf(ActuallyBlocks.FEEDER.get()); this.dropSelf(ActuallyBlocks.CRUSHER.get()); @@ -201,12 +201,14 @@ public class LootTableGenerator extends LootTableProvider { private void dropNBT(Supplier blockSupplier, Consumer lootFunctionProvider) { LootPool.Builder lootpool = LootPool.lootPool().setRolls(ConstantRange.exactly(1)).add(ItemLootEntry.lootTableItem(blockSupplier.get())); - lootpool.apply(CopyName.copyName(CopyName.Source.BLOCK_ENTITY)); lootFunctionProvider.accept(lootpool); add(blockSupplier.get(), LootTable.lootTable().withPool(applyExplosionCondition(ActuallyBlocks.ATOMIC_RECONSTRUCTOR.get(), lootpool))); } + private void dropKeepEnergy(Supplier blockSupplier) { + dropNBT(blockSupplier, $ -> $.apply(CopyNbt.copyData(CopyNbt.Source.BLOCK_ENTITY).copy("Energy", "BlockEntityTag.Energy"))); + } /* // This isn't quite right :cry: fortune doesn't change it private void registerCrystal(RegistryObject crystalCluster, RegistryObject crystalShard) { 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 5b75e0acf..c13afa46d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/AABlockItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/AABlockItem.java @@ -1,8 +1,19 @@ package de.ellpeck.actuallyadditions.mod.blocks; import net.minecraft.block.Block; +import net.minecraft.client.util.ITooltipFlag; import net.minecraft.item.BlockItem; import net.minecraft.item.BlockNamedItem; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextFormatting; +import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import java.text.NumberFormat; +import java.util.List; public class AABlockItem extends BlockItem { public AABlockItem(Block blockIn, Properties builder) { @@ -19,4 +30,25 @@ public class AABlockItem extends BlockItem { return this.getOrCreateDescriptionId(); } } + + public static class BlockEntityEnergyItem extends AABlockItem { + public BlockEntityEnergyItem(Block blockIn, Properties builder) { + super(blockIn, builder); + } + + @Override + public void appendHoverText(ItemStack pStack, @Nullable World pLevel, List pTooltip, ITooltipFlag pFlag) { + super.appendHoverText(pStack, pLevel, pTooltip, pFlag); + + if (pStack.hasTag() && pStack.getTag().contains("BlockEntityTag")) { + CompoundNBT BET = pStack.getTag().getCompound("BlockEntityTag"); + int energy = 0; + if (BET.contains("Energy")) { + energy = BET.getInt("Energy"); + } + NumberFormat format = NumberFormat.getInstance(); + pTooltip.add(new TranslationTextComponent("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 5c102c8b8..322676e5d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/ActuallyBlocks.java @@ -67,10 +67,10 @@ public final class ActuallyBlocks { (b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityFermentingBarrel::new); public static final AABlockReg OIL_GENERATOR = new AABlockReg<>("oil_generator", BlockOilGenerator::new, - (b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityOilGenerator::new); + (b) -> new AABlockItem.BlockEntityEnergyItem(b, defaultBlockItemProperties), TileEntityOilGenerator::new); public static final AABlockReg COAL_GENERATOR = new AABlockReg<>("coal_generator", BlockCoalGenerator::new, - (b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityCoalGenerator::new); + (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); @@ -155,7 +155,7 @@ public final class ActuallyBlocks { public static final AABlockReg EMPOWERER = new AABlockReg<>("empowerer", () -> new BlockDisplayStand(true), (b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityEmpowerer::new); public static final AABlockReg DISPLAY_STAND = new AABlockReg<>("display_stand", () -> new BlockDisplayStand(false), - (b) -> new AABlockItem(b, defaultBlockItemProperties), TileEntityDisplayStand::new); + (b) -> new AABlockItem.BlockEntityEnergyItem(b, defaultBlockItemProperties), TileEntityDisplayStand::new); // Interface Blocks public static final AABlockReg PLAYER_INTERFACE = new AABlockReg<>("player_interface", BlockPlayerInterface::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 b324a536e..2cdf0c8d0 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java @@ -29,6 +29,7 @@ import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.nbt.CompoundNBT; import net.minecraft.state.DirectionProperty; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.tileentity.TileEntity; @@ -39,6 +40,7 @@ import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.world.IBlockReader; @@ -48,6 +50,7 @@ import net.minecraftforge.api.distmarker.OnlyIn; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.text.NumberFormat; import java.util.List; import java.util.Random; @@ -158,6 +161,21 @@ public class BlockAtomicReconstructor extends FullyDirectionalBlock.Container im String base = block.getDescriptionId() + ".info."; pTooltip.add(new TranslationTextComponent(base + "1." + this.toPick1).append(" ").append(new TranslationTextComponent(base + "2." + this.toPick2)).withStyle(s -> s.withColor(TextFormatting.GRAY))); + + if (pStack.hasTag() && pStack.getTag().contains("BlockEntityTag")) { + CompoundNBT BET = pStack.getTag().getCompound("BlockEntityTag"); + int energy = 0; + if (BET.contains("Energy")) { + energy = BET.getInt("Energy"); + } + NumberFormat format = NumberFormat.getInstance(); + pTooltip.add(new TranslationTextComponent("misc.actuallyadditions.power_single", format.format(energy))); + + if (BET.contains("IsPulseMode")) { + pTooltip.add(new TranslationTextComponent("info.actuallyadditions.redstoneMode").append(": ") + .append(new TranslationTextComponent(BET.getBoolean("IsPulseMode")?"info.actuallyadditions.redstoneMode.pulse":"info.actuallyadditions.redstoneMode.deactivation").withStyle($ -> $.withColor(TextFormatting.RED)))); + } + } } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java index 53b9c3e5a..e784b4836 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/CustomEnergyStorage.java @@ -61,7 +61,8 @@ public class CustomEnergyStorage extends EnergyStorage { } public void readFromNBT(CompoundNBT compound) { - this.setEnergyStored(compound.getInt("Energy")); + if (compound.contains("Energy")) + this.setEnergyStored(compound.getInt("Energy")); } public void writeToNBT(CompoundNBT compound) {