From d719b8595889fba8d1ee641e949593154bf4db6a Mon Sep 17 00:00:00 2001 From: WayofTime <WayofTime@users.noreply.github.com> Date: Sat, 2 Jan 2021 12:13:51 -0500 Subject: [PATCH] Fixed NPE in Blood Altar and added some WIP blocks Also included is a fix for the Blood Altar not receiving piped in fluids, as well as standardizing the Blood Altar's capabilities. --- changelog.txt | 3 + src/generated/resources/.cache/cache | 8 + .../blockstates/deforester_charge.json | 29 +++ .../bloodmagic/blockstates/shaped_charge.json | 29 +++ .../models/block/deforester_charge.json | 11 + .../models/block/shaped_charge.json | 11 + .../models/item/deforester_charge.json | 3 + .../bloodmagic/models/item/shaped_charge.json | 3 + .../loot_tables/blocks/deforester_charge.json | 19 ++ .../loot_tables/blocks/shaped_charge.json | 19 ++ .../java/wayoftime/bloodmagic/BloodMagic.java | 4 + .../bloodmagic/altar/BloodAltar.java | 6 +- .../common/block/BlockDeforesterCharge.java | 20 ++ .../common/block/BlockShapedExplosive.java | 107 ++++++++ .../common/block/BloodMagicBlocks.java | 6 +- .../common/data/GeneratorBlockStates.java | 20 ++ .../common/data/GeneratorItemModels.java | 5 +- .../common/data/GeneratorLootTable.java | 3 + .../common/item/BloodMagicItems.java | 3 + .../wayoftime/bloodmagic/tile/TileAltar.java | 16 +- .../bloodmagic/tile/TileDeforesterCharge.java | 233 ++++++++++++++++++ .../bloodmagic/tile/TileShapedExplosive.java | 195 +++++++++++++++ .../models/block/sub/shaped_charge.json | 136 ++++++++++ 23 files changed, 883 insertions(+), 6 deletions(-) create mode 100644 src/generated/resources/assets/bloodmagic/blockstates/deforester_charge.json create mode 100644 src/generated/resources/assets/bloodmagic/blockstates/shaped_charge.json create mode 100644 src/generated/resources/assets/bloodmagic/models/block/deforester_charge.json create mode 100644 src/generated/resources/assets/bloodmagic/models/block/shaped_charge.json create mode 100644 src/generated/resources/assets/bloodmagic/models/item/deforester_charge.json create mode 100644 src/generated/resources/assets/bloodmagic/models/item/shaped_charge.json create mode 100644 src/generated/resources/data/bloodmagic/loot_tables/blocks/deforester_charge.json create mode 100644 src/generated/resources/data/bloodmagic/loot_tables/blocks/shaped_charge.json create mode 100644 src/main/java/wayoftime/bloodmagic/common/block/BlockDeforesterCharge.java create mode 100644 src/main/java/wayoftime/bloodmagic/common/block/BlockShapedExplosive.java create mode 100644 src/main/java/wayoftime/bloodmagic/tile/TileDeforesterCharge.java create mode 100644 src/main/java/wayoftime/bloodmagic/tile/TileShapedExplosive.java create mode 100644 src/main/resources/assets/bloodmagic/models/block/sub/shaped_charge.json diff --git a/changelog.txt b/changelog.txt index 422e1c07..5ea7f5e1 100644 --- a/changelog.txt +++ b/changelog.txt @@ -5,6 +5,9 @@ Version 3.0.4 - Fixed the following Living Armour upgrades so that they are now obtainable: - Experienced - Body Builder + +- Fixed NPE in Blood Altar when trying to interact with the contained Fluids +- Also fixed bug that prevented the Altar from accepting fluids piped in as inputs. - Added new alchemy arrays: - Two arrays, which changes the current daylight cycle to day and night. diff --git a/src/generated/resources/.cache/cache b/src/generated/resources/.cache/cache index cdb6a6e5..124de597 100644 --- a/src/generated/resources/.cache/cache +++ b/src/generated/resources/.cache/cache @@ -9,6 +9,7 @@ cb435652c27b4978d8db83af2fd531ccaa82ada7 assets/bloodmagic/blockstates/accelerat 631b579c38652efbcd9e5771d09ad6e476f3ba00 assets/bloodmagic/blockstates/chargingrune.json a35188b0244bf9808098c7d49d0af9bd32cef297 assets/bloodmagic/blockstates/corrosivedemoncrystal.json b943c6433f295c168841aec3c3f62e525c5c9cc9 assets/bloodmagic/blockstates/creeping_doubt.json +a54ab8dfd36a593829dc33644c5f9dbccaaadaf3 assets/bloodmagic/blockstates/deforester_charge.json b696f680545dffa4d3fbcc83b4b81ab58ac69aef assets/bloodmagic/blockstates/destructivedemoncrystal.json 6bd58d1d02a40416cec29409dee7ef80038b26d5 assets/bloodmagic/blockstates/dislocationrune.json 0b7d0241c379d0b3a8a4fa2dae79d4f998800a1f assets/bloodmagic/blockstates/dungeon_brick1.json @@ -46,6 +47,7 @@ a2eaa9166258d7179d9e5099200f777bb9edf613 assets/bloodmagic/blockstates/rawdemonc 90daa355e528ab8a6582f796951201882f3c56da assets/bloodmagic/blockstates/ritualstone.json 285618c1a8ec36e36d479f577190579ae7616529 assets/bloodmagic/blockstates/sacrificerune.json b03040d7a168653bf8df3600033b8fde2383db30 assets/bloodmagic/blockstates/selfsacrificerune.json +d2e2e78bd859c321a72f40fbb17ca79292d58031 assets/bloodmagic/blockstates/shaped_charge.json 487ffdc02ab7b65aafcb932e3b5cf6ea0500b21d assets/bloodmagic/blockstates/speedrune.json f1ca47098385a955155cab9c2a97219e02d390a0 assets/bloodmagic/blockstates/steadfastdemoncrystal.json 297bc2425f7b07b1a9dd3f7f6649c44f88dbac29 assets/bloodmagic/blockstates/stonebrickpath.json @@ -109,6 +111,7 @@ fe8271e4e815de11cd617179dedface57bd8c696 assets/bloodmagic/models/block/crystal/ 825352d6cdd314dd4cb775062757e2b8eb39f5d7 assets/bloodmagic/models/block/crystal/vengefulcrystal5.json 9603b46cb4ebc567878ca5f54fe96e1199f34d0c assets/bloodmagic/models/block/crystal/vengefulcrystal6.json ecf64f8c06743f0c2752e32a67753c0d5f9f67a1 assets/bloodmagic/models/block/crystal/vengefulcrystal7.json +c75695cf399d96d66914ab7dcfe1fe6bf171d6b9 assets/bloodmagic/models/block/deforester_charge.json 6adbeedc17f649ef47419845a6da0d50cfc76742 assets/bloodmagic/models/block/dislocationrune.json 313607b36c7c30073bbc64d3130f15b5871c5cd3 assets/bloodmagic/models/block/dungeon_brick1.json 55a9c171872cf9fb40c06dc2e9e826223a9096e0 assets/bloodmagic/models/block/dungeon_brick2.json @@ -171,6 +174,7 @@ c3a813b735cd229f8597e41d04465926b2e65fe1 assets/bloodmagic/models/block/orbcapac a8a1d06fcc2f8395530c72d2846133fff37d5537 assets/bloodmagic/models/block/sacrificerune.json 791c9f2e27215ff0a45eed7efe385276bfc09aed assets/bloodmagic/models/block/selfsacrificerune.json d6238c0661560abd991d534ef6c8836f4655a7e7 assets/bloodmagic/models/block/sentientmimic.json +04a1e67d1587be970310912849119903b99412ef assets/bloodmagic/models/block/shaped_charge.json 6556131b1aeb25dc67daf31a1ecdb3ce23e718d4 assets/bloodmagic/models/block/solidclearmimic.json 88b9f25444280d323fff11046d4d3a3af11265e8 assets/bloodmagic/models/block/solidlightmimic.json 23d937795efdb02507d301c459e52cd4b0cfa5cb assets/bloodmagic/models/block/solidopaquemimic.json @@ -214,6 +218,7 @@ a14760b028650f41da69454701c1611e68a33056 assets/bloodmagic/models/item/corrupted 5ffcaf5c5378e51d9474b4e75fb3a9cae946a492 assets/bloodmagic/models/item/crystalline_resonator.json f404148f9df3a61da3c18175885ffa56b2a85a6a assets/bloodmagic/models/item/daggerofsacrifice.json 6b89387f771da9535a0234f1a267af1b6853724d assets/bloodmagic/models/item/defaultcrystal.json +cad1aef333d131d77b7960f5dc295694baeead1c assets/bloodmagic/models/item/deforester_charge.json 9671199681493a396e07d7bcab20137c22d981d5 assets/bloodmagic/models/item/demonslate.json 630d3287fcbdcca0dec3343488a2c868316d83d2 assets/bloodmagic/models/item/demonwillgauge.json a61193ff59b71a79e8e28720dfce4185122a7ec1 assets/bloodmagic/models/item/destructivecrystal.json @@ -310,6 +315,7 @@ b4afc1907cb2463f11579803122bb2af38b1f4ae assets/bloodmagic/models/item/sand_neth b8582a5cd6ca35279e9b35931f1c5ca089b094b8 assets/bloodmagic/models/item/sanguinereverter.json b9fd6c60eba0186ba7ac156c4d126fcf74c21b84 assets/bloodmagic/models/item/seersigil.json cc71421e98ee7ee047a4cfbb6cb69529c2b02d4e assets/bloodmagic/models/item/selfsacrificerune.json +7f0256ef2f219d92882e759677399050b0776d64 assets/bloodmagic/models/item/shaped_charge.json ea5747638d0b5dcc03f008b202cc60a11e0827bb assets/bloodmagic/models/item/sigilofmagnetism.json db0f63198089161b8d4ecfb1ec8a45f7dc5ba83d assets/bloodmagic/models/item/soulaxe.json 9ec68a2dcf04b987c3c5d5c6c52195e3deccacbb assets/bloodmagic/models/item/soulgemcommon.json @@ -454,6 +460,7 @@ f0827ad5bf71c06a71f50aeb0298c04d0cb1a1d9 data/bloodmagic/loot_tables/blocks/bloo 779b809a2a51e6dab46f9e6799249f2f14653ebb data/bloodmagic/loot_tables/blocks/chargingrune.json 0d501e4eb447e84b38250ab1c396abe1218d129c data/bloodmagic/loot_tables/blocks/corrosivedemoncrystal.json e59c93dcc8d42b3ddb71dad1695573b1c284213f data/bloodmagic/loot_tables/blocks/creeping_doubt.json +0d39ff5d795638cdc39302f94acbeebd7779718a data/bloodmagic/loot_tables/blocks/deforester_charge.json 4c9ed83e7e7215f995df35054e96d2f4e5027016 data/bloodmagic/loot_tables/blocks/demoncrucible.json c590b923d28b3d7916932dfcb05091df815f71dd data/bloodmagic/loot_tables/blocks/demoncrystallizer.json b0ce964c69f63aa13350259279e5fe831ae18e2c data/bloodmagic/loot_tables/blocks/destructivedemoncrystal.json @@ -496,6 +503,7 @@ ce5bf03f0ee03205ef6a1b6f512cb5da23addc57 data/bloodmagic/loot_tables/blocks/mimi 26e3f34021426def32602e5ae7755e4672878320 data/bloodmagic/loot_tables/blocks/ritualstone.json e0239eff7762a414a4e4faa0158d844dffb8c1f6 data/bloodmagic/loot_tables/blocks/sacrificerune.json 9b697e37046b6238b3a19eae9113b88010ccff32 data/bloodmagic/loot_tables/blocks/selfsacrificerune.json +4c138f5a496f407fcf8b6bd6bd2117c1bcf062cf data/bloodmagic/loot_tables/blocks/shaped_charge.json f748a5ba8838b50de0502f132fe2a65f4726dae6 data/bloodmagic/loot_tables/blocks/soulforge.json 015e07226fd90935f7ec663f4bcf3873a57a82d1 data/bloodmagic/loot_tables/blocks/speedrune.json 128ec3ee93e927d457beeb8161e80706e9239760 data/bloodmagic/loot_tables/blocks/steadfastdemoncrystal.json diff --git a/src/generated/resources/assets/bloodmagic/blockstates/deforester_charge.json b/src/generated/resources/assets/bloodmagic/blockstates/deforester_charge.json new file mode 100644 index 00000000..bac5692f --- /dev/null +++ b/src/generated/resources/assets/bloodmagic/blockstates/deforester_charge.json @@ -0,0 +1,29 @@ +{ + "variants": { + "attached=down": { + "model": "bloodmagic:block/deforester_charge", + "x": 180 + }, + "attached=up": { + "model": "bloodmagic:block/deforester_charge" + }, + "attached=north": { + "model": "bloodmagic:block/deforester_charge", + "x": 90 + }, + "attached=south": { + "model": "bloodmagic:block/deforester_charge", + "x": 270 + }, + "attached=west": { + "model": "bloodmagic:block/deforester_charge", + "x": 90, + "y": 270 + }, + "attached=east": { + "model": "bloodmagic:block/deforester_charge", + "x": 90, + "y": 90 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/bloodmagic/blockstates/shaped_charge.json b/src/generated/resources/assets/bloodmagic/blockstates/shaped_charge.json new file mode 100644 index 00000000..8b918ec1 --- /dev/null +++ b/src/generated/resources/assets/bloodmagic/blockstates/shaped_charge.json @@ -0,0 +1,29 @@ +{ + "variants": { + "attached=down": { + "model": "bloodmagic:block/shaped_charge", + "x": 180 + }, + "attached=up": { + "model": "bloodmagic:block/shaped_charge" + }, + "attached=north": { + "model": "bloodmagic:block/shaped_charge", + "x": 90 + }, + "attached=south": { + "model": "bloodmagic:block/shaped_charge", + "x": 270 + }, + "attached=west": { + "model": "bloodmagic:block/shaped_charge", + "x": 90, + "y": 270 + }, + "attached=east": { + "model": "bloodmagic:block/shaped_charge", + "x": 90, + "y": 90 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/bloodmagic/models/block/deforester_charge.json b/src/generated/resources/assets/bloodmagic/models/block/deforester_charge.json new file mode 100644 index 00000000..f441dc4e --- /dev/null +++ b/src/generated/resources/assets/bloodmagic/models/block/deforester_charge.json @@ -0,0 +1,11 @@ +{ + "parent": "bloodmagic:block/sub/shaped_charge", + "textures": { + "1": "minecraft:block/oak_log_top", + "3": "minecraft:block/oak_log_top", + "4": "bloodmagic:block/blankrune", + "5": "minecraft:block/oak_planks", + "6": "bloodmagic:models/defaultcrystal", + "particle": "bloodmagic:models/defaultcrystal" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/bloodmagic/models/block/shaped_charge.json b/src/generated/resources/assets/bloodmagic/models/block/shaped_charge.json new file mode 100644 index 00000000..75078a95 --- /dev/null +++ b/src/generated/resources/assets/bloodmagic/models/block/shaped_charge.json @@ -0,0 +1,11 @@ +{ + "parent": "bloodmagic:block/sub/shaped_charge", + "textures": { + "1": "bloodmagic:block/dungeon/dungeon_tile", + "3": "bloodmagic:block/dungeon/dungeon_stone", + "4": "bloodmagic:block/blankrune", + "5": "bloodmagic:block/largebloodstonebrick", + "6": "bloodmagic:models/defaultcrystal", + "particle": "bloodmagic:models/defaultcrystal" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/bloodmagic/models/item/deforester_charge.json b/src/generated/resources/assets/bloodmagic/models/item/deforester_charge.json new file mode 100644 index 00000000..64187a41 --- /dev/null +++ b/src/generated/resources/assets/bloodmagic/models/item/deforester_charge.json @@ -0,0 +1,3 @@ +{ + "parent": "bloodmagic:block/deforester_charge" +} \ No newline at end of file diff --git a/src/generated/resources/assets/bloodmagic/models/item/shaped_charge.json b/src/generated/resources/assets/bloodmagic/models/item/shaped_charge.json new file mode 100644 index 00000000..de035a33 --- /dev/null +++ b/src/generated/resources/assets/bloodmagic/models/item/shaped_charge.json @@ -0,0 +1,3 @@ +{ + "parent": "bloodmagic:block/shaped_charge" +} \ No newline at end of file diff --git a/src/generated/resources/data/bloodmagic/loot_tables/blocks/deforester_charge.json b/src/generated/resources/data/bloodmagic/loot_tables/blocks/deforester_charge.json new file mode 100644 index 00000000..f5d7a8bb --- /dev/null +++ b/src/generated/resources/data/bloodmagic/loot_tables/blocks/deforester_charge.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "bloodmagic:deforester_charge" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/generated/resources/data/bloodmagic/loot_tables/blocks/shaped_charge.json b/src/generated/resources/data/bloodmagic/loot_tables/blocks/shaped_charge.json new file mode 100644 index 00000000..fe0a9cc2 --- /dev/null +++ b/src/generated/resources/data/bloodmagic/loot_tables/blocks/shaped_charge.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "bloodmagic:shaped_charge" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/java/wayoftime/bloodmagic/BloodMagic.java b/src/main/java/wayoftime/bloodmagic/BloodMagic.java index 6334828d..5adf8a38 100644 --- a/src/main/java/wayoftime/bloodmagic/BloodMagic.java +++ b/src/main/java/wayoftime/bloodmagic/BloodMagic.java @@ -64,12 +64,14 @@ import wayoftime.bloodmagic.tile.TileAlchemicalReactionChamber; import wayoftime.bloodmagic.tile.TileAlchemyArray; import wayoftime.bloodmagic.tile.TileAlchemyTable; import wayoftime.bloodmagic.tile.TileAltar; +import wayoftime.bloodmagic.tile.TileDeforesterCharge; import wayoftime.bloodmagic.tile.TileDemonCrucible; import wayoftime.bloodmagic.tile.TileDemonCrystal; import wayoftime.bloodmagic.tile.TileDemonCrystallizer; import wayoftime.bloodmagic.tile.TileIncenseAltar; import wayoftime.bloodmagic.tile.TileMasterRitualStone; import wayoftime.bloodmagic.tile.TileMimic; +import wayoftime.bloodmagic.tile.TileShapedExplosive; import wayoftime.bloodmagic.tile.TileSoulForge; import wayoftime.bloodmagic.util.handler.event.GenericHandler; import wayoftime.bloodmagic.util.handler.event.WillHandler; @@ -186,6 +188,8 @@ public class BloodMagic event.getRegistry().register(TileEntityType.Builder.create(TileDemonCrystallizer::new, BloodMagicBlocks.DEMON_CRYSTALLIZER.get()).build(null).setRegistryName("demoncrystallizer")); event.getRegistry().register(TileEntityType.Builder.create(TileIncenseAltar::new, BloodMagicBlocks.INCENSE_ALTAR.get()).build(null).setRegistryName("incensealtar")); event.getRegistry().register(TileEntityType.Builder.create(TileMimic::new, BloodMagicBlocks.MIMIC.get(), BloodMagicBlocks.ETHEREAL_MIMIC.get()).build(null).setRegistryName("mimic")); + event.getRegistry().register(TileEntityType.Builder.create(TileShapedExplosive::new, BloodMagicBlocks.SHAPED_CHARGE.get()).build(null).setRegistryName("shaped_explosive")); + event.getRegistry().register(TileEntityType.Builder.create(TileDeforesterCharge::new, BloodMagicBlocks.DEFORESTER_CHARGE.get()).build(null).setRegistryName("deforester_charge")); } @SubscribeEvent diff --git a/src/main/java/wayoftime/bloodmagic/altar/BloodAltar.java b/src/main/java/wayoftime/bloodmagic/altar/BloodAltar.java index f5f64b80..c978293b 100644 --- a/src/main/java/wayoftime/bloodmagic/altar/BloodAltar.java +++ b/src/main/java/wayoftime/bloodmagic/altar/BloodAltar.java @@ -684,7 +684,7 @@ public class BloodAltar// implements IFluidHandler return Math.min(bufferCapacity - fluidInput.getAmount(), resource.getAmount()); } - if (fluidInput == null) + if (fluidInput == null || fluidInput.isEmpty()) { fluidInput = new FluidStack(resource, Math.min(bufferCapacity, resource.getAmount())); @@ -713,7 +713,7 @@ public class BloodAltar// implements IFluidHandler { if (resource == null || !resource.isFluidEqual(fluidOutput)) { - return null; + return FluidStack.EMPTY; } return drain(resource.getAmount(), doDrain); } @@ -722,7 +722,7 @@ public class BloodAltar// implements IFluidHandler { if (fluidOutput == null) { - return null; + return FluidStack.EMPTY; } int drained = maxDrain; diff --git a/src/main/java/wayoftime/bloodmagic/common/block/BlockDeforesterCharge.java b/src/main/java/wayoftime/bloodmagic/common/block/BlockDeforesterCharge.java new file mode 100644 index 00000000..beefd606 --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/common/block/BlockDeforesterCharge.java @@ -0,0 +1,20 @@ +package wayoftime.bloodmagic.common.block; + +import net.minecraft.block.BlockState; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.IBlockReader; +import wayoftime.bloodmagic.tile.TileDeforesterCharge; + +public class BlockDeforesterCharge extends BlockShapedExplosive +{ + public BlockDeforesterCharge(int explosionSize, Properties properties) + { + super(explosionSize, properties); + } + + @Override + public TileEntity createTileEntity(BlockState state, IBlockReader world) + { + return new TileDeforesterCharge(); + } +} diff --git a/src/main/java/wayoftime/bloodmagic/common/block/BlockShapedExplosive.java b/src/main/java/wayoftime/bloodmagic/common/block/BlockShapedExplosive.java new file mode 100644 index 00000000..f41bf2ea --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/common/block/BlockShapedExplosive.java @@ -0,0 +1,107 @@ +package wayoftime.bloodmagic.common.block; + +import javax.annotation.Nullable; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.item.BlockItemUseContext; +import net.minecraft.state.EnumProperty; +import net.minecraft.state.StateContainer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Direction; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.world.IBlockReader; +import net.minecraft.world.IWorld; +import net.minecraft.world.IWorldReader; +import wayoftime.bloodmagic.tile.TileShapedExplosive; + +public class BlockShapedExplosive extends Block +{ + private static final VoxelShape UP = Block.makeCuboidShape(2, 0, 2, 14, 7, 14); + private static final VoxelShape DOWN = Block.makeCuboidShape(2, 9, 2, 14, 16, 14); + private static final VoxelShape NORTH = Block.makeCuboidShape(2, 2, 7, 14, 14, 16); + private static final VoxelShape SOUTH = Block.makeCuboidShape(2, 2, 0, 14, 14, 7); + private static final VoxelShape EAST = Block.makeCuboidShape(0, 2, 2, 7, 14, 14); + private static final VoxelShape WEST = Block.makeCuboidShape(16, 2, 2, 9, 14, 14); + + public static final EnumProperty<Direction> ATTACHED = EnumProperty.create("attached", Direction.class); + protected final int explosionSize; + + public BlockShapedExplosive(int explosionSize, Properties properties) + { + super(properties); + this.explosionSize = explosionSize; + + this.setDefaultState(this.stateContainer.getBaseState().with(ATTACHED, Direction.UP)); + } + + public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) + { + return facing.getOpposite() == stateIn.get(ATTACHED) && !stateIn.isValidPosition(worldIn, currentPos) + ? Blocks.AIR.getDefaultState() + : stateIn; + } + + @Nullable + public BlockState getStateForPlacement(BlockItemUseContext context) + { + BlockState blockstate = this.getDefaultState(); + IWorldReader iworldreader = context.getWorld(); + BlockPos blockpos = context.getPos(); + Direction[] adirection = context.getNearestLookingDirections(); + + for (Direction direction : adirection) + { + Direction direction1 = direction.getOpposite(); + blockstate = blockstate.with(ATTACHED, direction1); + if (blockstate.isValidPosition(iworldreader, blockpos)) + { + return blockstate; + } + } + + return null; + } + + @Override + protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) + { + builder.add(ATTACHED); + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) + { + switch (state.get(ATTACHED)) + { + case DOWN: + return DOWN; + case NORTH: + return NORTH; + case SOUTH: + return SOUTH; + case EAST: + return EAST; + case WEST: + return WEST; + case UP: + default: + return UP; + } + } + + @Override + public boolean hasTileEntity(BlockState state) + { + return true; + } + + @Override + public TileEntity createTileEntity(BlockState state, IBlockReader world) + { + return new TileShapedExplosive(); + } +} diff --git a/src/main/java/wayoftime/bloodmagic/common/block/BloodMagicBlocks.java b/src/main/java/wayoftime/bloodmagic/common/block/BloodMagicBlocks.java index 5b32fd7a..120ebb55 100644 --- a/src/main/java/wayoftime/bloodmagic/common/block/BloodMagicBlocks.java +++ b/src/main/java/wayoftime/bloodmagic/common/block/BloodMagicBlocks.java @@ -29,6 +29,7 @@ import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; import wayoftime.bloodmagic.BloodMagic; +import wayoftime.bloodmagic.api.compat.EnumDemonWillType; import wayoftime.bloodmagic.block.enums.BloodRuneType; import wayoftime.bloodmagic.common.block.base.BlockPillarCap; import wayoftime.bloodmagic.common.item.BloodMagicItems; @@ -36,7 +37,6 @@ import wayoftime.bloodmagic.ritual.EnumRuneType; import wayoftime.bloodmagic.tile.container.ContainerAlchemicalReactionChamber; import wayoftime.bloodmagic.tile.container.ContainerAlchemyTable; import wayoftime.bloodmagic.tile.container.ContainerSoulForge; -import wayoftime.bloodmagic.api.compat.EnumDemonWillType; public class BloodMagicBlocks { @@ -171,6 +171,10 @@ public class BloodMagicBlocks { return false; } + + public static final RegistryObject<Block> SHAPED_CHARGE = BLOCKS.register("shaped_charge", () -> new BlockShapedExplosive(3, Properties.create(Material.IRON).hardnessAndResistance(5.0F, 6.0F).sound(SoundType.METAL).harvestTool(ToolType.PICKAXE).harvestLevel(1).setRequiresTool())); + public static final RegistryObject<Block> DEFORESTER_CHARGE = BLOCKS.register("deforester_charge", () -> new BlockDeforesterCharge(3, Properties.create(Material.IRON).hardnessAndResistance(5.0F, 6.0F).sound(SoundType.METAL).harvestTool(ToolType.PICKAXE).harvestLevel(1).setRequiresTool())); + // //// private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Function<RegistryObject<T>, Supplier<? extends Item>> itemCreator) //// { diff --git a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorBlockStates.java b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorBlockStates.java index 10a0ecf9..6384393e 100644 --- a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorBlockStates.java +++ b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorBlockStates.java @@ -25,6 +25,7 @@ import net.minecraftforge.fml.RegistryObject; import wayoftime.bloodmagic.BloodMagic; import wayoftime.bloodmagic.common.block.BlockAlchemicalReactionChamber; import wayoftime.bloodmagic.common.block.BlockDemonCrystal; +import wayoftime.bloodmagic.common.block.BlockShapedExplosive; import wayoftime.bloodmagic.common.block.BloodMagicBlocks; import wayoftime.bloodmagic.common.block.base.BlockPillarCap; @@ -90,6 +91,25 @@ public class GeneratorBlockStates extends BlockStateProvider buildCubeAllWithTextureName("solidopaquemimic"); buildCrop(BloodMagicBlocks.GROWING_DOUBT.get(), CropsBlock.AGE, 7, BloodMagic.rl("block/creeping_doubt_1"), BloodMagic.rl("block/creeping_doubt_2"), BloodMagic.rl("block/creeping_doubt_3"), BloodMagic.rl("block/creeping_doubt_4"), BloodMagic.rl("block/creeping_doubt_5"), BloodMagic.rl("block/creeping_doubt_6"), BloodMagic.rl("block/creeping_doubt_7"), BloodMagic.rl("block/creeping_doubt_8")); + + buildOrientable(BloodMagicBlocks.SHAPED_CHARGE.get(), "shaped_charge", modLoc("block/sub/shaped_charge"), modLoc("block/dungeon/dungeon_stone"), modLoc("block/dungeon/dungeon_tile"), modLoc("block/blankrune"), modLoc("block/largebloodstonebrick"), modLoc("models/defaultcrystal")); + buildOrientable(BloodMagicBlocks.DEFORESTER_CHARGE.get(), "deforester_charge", modLoc("block/sub/shaped_charge"), new ResourceLocation("block/oak_log_top"), new ResourceLocation("block/oak_log_top"), modLoc("block/blankrune"), new ResourceLocation("block/oak_planks"), modLoc("models/defaultcrystal")); + } + + private void buildOrientable(Block block, String name, ResourceLocation modelPath, ResourceLocation base, ResourceLocation edges, ResourceLocation centerCap, ResourceLocation binding, ResourceLocation core) + { +// ModelFile furnace_off = models().orientableWithBottom("alchemicalreactionchamber", BloodMagic.rl("block/arc_side"), BloodMagic.rl("block/arc_front"), BloodMagic.rl("block/arc_bottom"), BloodMagic.rl("block/arc_top")); +// getVariantBuilder(block).addModels(block.getDefaultState().with(BlockAlchemicalReactionChamber.FACING, Direction.NORTH).with(BlockAlchemicalReactionChamber.LIT, false), furnaceModel); + ModelFile model = models().withExistingParent(name, modelPath).texture("1", edges).texture("3", base).texture("4", centerCap).texture("5", binding).texture("6", core).texture("particle", core); + + VariantBlockStateBuilder builder = getVariantBuilder(block); + + builder.partialState().with(BlockShapedExplosive.ATTACHED, Direction.UP).modelForState().modelFile(model).addModel(); + builder.partialState().with(BlockShapedExplosive.ATTACHED, Direction.DOWN).modelForState().modelFile(model).rotationX(180).addModel(); + builder.partialState().with(BlockShapedExplosive.ATTACHED, Direction.EAST).modelForState().modelFile(model).rotationX(90).rotationY(90).addModel(); + builder.partialState().with(BlockShapedExplosive.ATTACHED, Direction.WEST).modelForState().modelFile(model).rotationX(90).rotationY(270).addModel(); + builder.partialState().with(BlockShapedExplosive.ATTACHED, Direction.NORTH).modelForState().modelFile(model).rotationX(90).addModel(); + builder.partialState().with(BlockShapedExplosive.ATTACHED, Direction.SOUTH).modelForState().modelFile(model).rotationX(270).addModel(); } private void buildCrop(Block block, IntegerProperty prop, int maxAge, ResourceLocation... textures) diff --git a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorItemModels.java b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorItemModels.java index 0f2a9a83..3d681b2a 100644 --- a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorItemModels.java +++ b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorItemModels.java @@ -9,9 +9,9 @@ import net.minecraftforge.client.model.generators.ModelFile; import net.minecraftforge.common.data.ExistingFileHelper; import net.minecraftforge.fml.RegistryObject; import wayoftime.bloodmagic.BloodMagic; +import wayoftime.bloodmagic.api.compat.EnumDemonWillType; import wayoftime.bloodmagic.common.block.BloodMagicBlocks; import wayoftime.bloodmagic.common.item.BloodMagicItems; -import wayoftime.bloodmagic.api.compat.EnumDemonWillType; public class GeneratorItemModels extends ItemModelProvider { @@ -87,6 +87,9 @@ public class GeneratorItemModels extends ItemModelProvider registerCustomFullTexture(BloodMagicBlocks.MIMIC.get(), "solidopaquemimic"); registerCustomFullTexture(BloodMagicBlocks.ETHEREAL_MIMIC.get(), "etherealopaquemimic"); this.crop(BloodMagicBlocks.GROWING_DOUBT.get().getRegistryName().getPath(), modLoc("block/creeping_doubt_8")); + + registerBlockModel(BloodMagicBlocks.SHAPED_CHARGE.get()); + registerBlockModel(BloodMagicBlocks.DEFORESTER_CHARGE.get()); } private void registerCustomFullTexture(Block block, String texturePath) diff --git a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorLootTable.java b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorLootTable.java index bc5550c2..1648b57c 100644 --- a/src/main/java/wayoftime/bloodmagic/common/data/GeneratorLootTable.java +++ b/src/main/java/wayoftime/bloodmagic/common/data/GeneratorLootTable.java @@ -131,6 +131,9 @@ public class GeneratorLootTable extends LootTableProvider registerDropSelfLootTable(BloodMagicBlocks.ETHEREAL_MIMIC.get()); registerCropDropLootTable(BloodMagicBlocks.GROWING_DOUBT.get(), BloodMagicItems.WEAK_BLOOD_SHARD.get()); + + registerDropSelfLootTable(BloodMagicBlocks.SHAPED_CHARGE.get()); + registerDropSelfLootTable(BloodMagicBlocks.DEFORESTER_CHARGE.get()); } private void registerNoDropLootTable(Block block) diff --git a/src/main/java/wayoftime/bloodmagic/common/item/BloodMagicItems.java b/src/main/java/wayoftime/bloodmagic/common/item/BloodMagicItems.java index cc75dc16..04b66411 100644 --- a/src/main/java/wayoftime/bloodmagic/common/item/BloodMagicItems.java +++ b/src/main/java/wayoftime/bloodmagic/common/item/BloodMagicItems.java @@ -96,6 +96,9 @@ public class BloodMagicItems public static final RegistryObject<Item> NETHE_SOIL_ITEM = ITEMS.register("nether_soil", () -> new BlockItem(BloodMagicBlocks.NETHER_SOIL.get(), new Item.Properties().group(BloodMagic.TAB))); public static final RegistryObject<Item> GROWING_DOUBT_ITEM = ITEMS.register("growing_doubt", () -> new BlockItem(BloodMagicBlocks.GROWING_DOUBT.get(), new Item.Properties().group(BloodMagic.TAB))); + + public static final RegistryObject<Item> SHAPED_CHARGE_ITEM = ITEMS.register("shaped_charge", () -> new BlockItem(BloodMagicBlocks.SHAPED_CHARGE.get(), new Item.Properties().group(BloodMagic.TAB))); + public static final RegistryObject<Item> DEFORESTER_CHARGE_ITEM = ITEMS.register("deforester_charge", () -> new BlockItem(BloodMagicBlocks.DEFORESTER_CHARGE.get(), new Item.Properties().group(BloodMagic.TAB))); // TODO: Need to rework the above instantiations for the ItemBlocks so that it's // done with the Blocks. diff --git a/src/main/java/wayoftime/bloodmagic/tile/TileAltar.java b/src/main/java/wayoftime/bloodmagic/tile/TileAltar.java index 6f3c579d..79d66235 100644 --- a/src/main/java/wayoftime/bloodmagic/tile/TileAltar.java +++ b/src/main/java/wayoftime/bloodmagic/tile/TileAltar.java @@ -22,6 +22,8 @@ public class TileAltar extends TileInventory implements IBloodAltar, ITickableTi public static TileEntityType<TileAltar> TYPE; private BloodAltar bloodAltar; + private LazyOptional fluidOptional; + public TileAltar(TileEntityType<?> type) { super(type, 1, "altar"); @@ -220,13 +222,25 @@ public class TileAltar extends TileInventory implements IBloodAltar, ITickableTi // return super.hasCapability(capability, facing); // } + @Override + protected void invalidateCaps() + { + super.invalidateCaps(); + fluidOptional.invalidate(); + fluidOptional = null; + } + @SuppressWarnings("unchecked") @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { - return LazyOptional.of(() -> new BloodAltar.VariableSizeFluidHandler(bloodAltar)).cast(); + if (fluidOptional == null) + { + fluidOptional = LazyOptional.of(() -> new BloodAltar.VariableSizeFluidHandler(bloodAltar)); + } + return fluidOptional.cast(); // return (T) bloodAltar; } diff --git a/src/main/java/wayoftime/bloodmagic/tile/TileDeforesterCharge.java b/src/main/java/wayoftime/bloodmagic/tile/TileDeforesterCharge.java new file mode 100644 index 00000000..8ba3b3a2 --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/tile/TileDeforesterCharge.java @@ -0,0 +1,233 @@ +package wayoftime.bloodmagic.tile; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import com.mojang.datafixers.util.Pair; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.item.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.loot.LootContext; +import net.minecraft.loot.LootParameters; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.particles.ParticleTypes; +import net.minecraft.tags.BlockTags; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.registries.ObjectHolder; +import wayoftime.bloodmagic.common.block.BlockShapedExplosive; +import wayoftime.bloodmagic.tile.base.TileTicking; + +public class TileDeforesterCharge extends TileTicking +{ + @ObjectHolder("bloodmagic:deforester_charge") + public static TileEntityType<TileDeforesterCharge> TYPE; + + private Map<BlockPos, Boolean> treePartsMap; + private List<BlockPos> treePartsCache; + private boolean finishedAnalysis; +// private Iterator<BlockPos> blockPosIterator; + +// private boolean cached = false; + + public double internalCounter = 0; + public int explosionRadius; + public int explosionDepth; + + public int maxLogs = 64; + + public TileDeforesterCharge(TileEntityType<?> type, int explosionRadius, int explosionDepth) + { + super(type); + this.explosionRadius = explosionRadius; + this.explosionDepth = explosionDepth; + } + + public TileDeforesterCharge() + { + this(TYPE, 1, 3); + } + + @Override + public void onUpdate() + { + if (world.isRemote) + { + return; + } +// System.out.println("Counter: " + internalCounter); + + Direction explosiveDirection = this.getBlockState().get(BlockShapedExplosive.ATTACHED).getOpposite(); + BlockState attachedState = world.getBlockState(pos.offset(explosiveDirection)); + if (!BlockTags.LOGS.contains(attachedState.getBlock()) && !BlockTags.LEAVES.contains(attachedState.getBlock())) + { + return; + } + + if (treePartsMap == null) + { + treePartsMap = new HashMap<BlockPos, Boolean>(); + treePartsMap.put(pos.offset(explosiveDirection), false); + treePartsCache = new LinkedList<BlockPos>(); + treePartsCache.add(pos.offset(explosiveDirection)); +// treePartsMap.add(pos.offset(explosiveDirection)); + } + + boolean foundNew = false; + List<BlockPos> newPositions = new LinkedList<BlockPos>(); + for (BlockPos currentPos : treePartsCache) + { + if (!treePartsMap.getOrDefault(currentPos, false)) // If the BlockPos wasn't checked yet + { +// BlockPos currentPos = entry.getKey(); + for (Direction dir : Direction.values()) + { + BlockPos checkPos = currentPos.offset(dir); + if (treePartsMap.containsKey(checkPos)) + { + continue; + } + + BlockState checkState = world.getBlockState(checkPos); + + if (BlockTags.LOGS.contains(checkState.getBlock()) || BlockTags.LEAVES.contains(checkState.getBlock())) + { + treePartsMap.put(checkPos, false); + newPositions.add(checkPos); + foundNew = true; + } + } + + treePartsMap.put(currentPos, true); + } + } + + treePartsCache.addAll(newPositions); + + System.out.println("Found blocks: " + treePartsMap.size()); + + if (foundNew) + { + return; + } + + internalCounter++; + if (internalCounter == 20) + { +// worldIn.playSound((PlayerEntity)null, tntentity.getPosX(), tntentity.getPosY(), tntentity.getPosZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F); + world.playSound((PlayerEntity) null, this.getPos().getX() + 0.5, this.getPos().getY() + 0.5, this.getPos().getZ() + 0.5, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, world.rand.nextFloat() * 0.4F + 0.8F); + ((ServerWorld) this.world).spawnParticle(ParticleTypes.FLAME, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 5, 0.02, 0.03, 0.02, 0); + } + + if (internalCounter == 30) + { + world.playSound((PlayerEntity) null, this.getPos().getX() + 0.5, this.getPos().getY() + 0.5, this.getPos().getZ() + 0.5, SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F); + } + + if (internalCounter < 30) + { + return; + } + + if (world.rand.nextDouble() < 0.3) + { + ((ServerWorld) this.world).spawnParticle(ParticleTypes.SMOKE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 1, 0.0D, 0.0D, 0.0D, 0); + } + + if (internalCounter == 100) + { + world.playSound((PlayerEntity) null, this.getPos().getX() + 0.5, this.getPos().getY() + 0.5, this.getPos().getZ() + 0.5, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F) * 0.7F); + + int numParticles = explosionDepth * (explosionRadius + 1); + + ((ServerWorld) this.world).spawnParticle(ParticleTypes.EXPLOSION, pos.getX() + 0.5 + explosiveDirection.getXOffset(), pos.getY() + 0.5 + explosiveDirection.getYOffset(), pos.getZ() + 0.5 + explosiveDirection.getZOffset(), numParticles, 1.0D, 1.0D, 1.0D, 0); + + ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>(); + + for (BlockPos blockPos : treePartsCache) + { +// BlockPos blockpos = initialPos.offset(explosiveDirection, i).offset(sweepDir1, j).offset(sweepDir2, k); + + BlockState blockstate = this.world.getBlockState(blockPos); + Block block = blockstate.getBlock(); + if (!blockstate.isAir(this.world, blockPos)) + { + BlockPos blockpos1 = blockPos.toImmutable(); +// this.world.getProfiler().startSection("explosion_blocks"); + if (this.world instanceof ServerWorld) + { + TileEntity tileentity = blockstate.hasTileEntity() ? this.world.getTileEntity(blockPos) : null; + LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.world)).withRandom(this.world.rand).withParameter(LootParameters.field_237457_g_, Vector3d.copyCentered(blockPos)).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withNullableParameter(LootParameters.BLOCK_ENTITY, tileentity); +// if (this.mode == Explosion.Mode.DESTROY) { +// lootcontext$builder.withParameter(LootParameters.EXPLOSION_RADIUS, this.size); +// } + + blockstate.getDrops(lootcontext$builder).forEach((stack) -> { + handleExplosionDrops(objectarraylist, stack, blockpos1); + }); + + world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), 3); + +// blockstate.onBlockExploded(this.world, blockpos, null); +// this.world.getProfiler().endSection(); + } + } + } + + for (Pair<ItemStack, BlockPos> pair : objectarraylist) + { + Block.spawnAsEntity(this.world, pair.getSecond(), pair.getFirst()); + } + + world.setBlockState(getPos(), Blocks.AIR.getDefaultState()); + } + } + + private static void handleExplosionDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> dropPositionArray, ItemStack stack, BlockPos pos) + { + int i = dropPositionArray.size(); + + for (int j = 0; j < i; ++j) + { + Pair<ItemStack, BlockPos> pair = dropPositionArray.get(j); + ItemStack itemstack = pair.getFirst(); + if (ItemEntity.canMergeStacks(itemstack, stack)) + { + ItemStack itemstack1 = ItemEntity.mergeStacks(itemstack, stack, 16); + dropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond())); + if (stack.isEmpty()) + { + return; + } + } + } + + dropPositionArray.add(Pair.of(stack, pos)); + } + + @Override + public void deserialize(CompoundNBT tag) + { + internalCounter = tag.getDouble("internalCounter"); + } + + @Override + public CompoundNBT serialize(CompoundNBT tag) + { + tag.putDouble("internalCounter", internalCounter); + return tag; + } +} \ No newline at end of file diff --git a/src/main/java/wayoftime/bloodmagic/tile/TileShapedExplosive.java b/src/main/java/wayoftime/bloodmagic/tile/TileShapedExplosive.java new file mode 100644 index 00000000..c7cedee0 --- /dev/null +++ b/src/main/java/wayoftime/bloodmagic/tile/TileShapedExplosive.java @@ -0,0 +1,195 @@ +package wayoftime.bloodmagic.tile; + +import com.mojang.datafixers.util.Pair; + +import it.unimi.dsi.fastutil.objects.ObjectArrayList; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.item.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.loot.LootContext; +import net.minecraft.loot.LootParameters; +import net.minecraft.nbt.CompoundNBT; +import net.minecraft.particles.ParticleTypes; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityType; +import net.minecraft.util.Direction; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.vector.Vector3d; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.registries.ObjectHolder; +import wayoftime.bloodmagic.common.block.BlockShapedExplosive; +import wayoftime.bloodmagic.tile.base.TileTicking; + +public class TileShapedExplosive extends TileTicking +{ + @ObjectHolder("bloodmagic:shaped_explosive") + public static TileEntityType<TileShapedExplosive> TYPE; + + public double internalCounter = 0; + public int explosionRadius; + public int explosionDepth; + + public TileShapedExplosive(TileEntityType<?> type, int explosionRadius, int explosionDepth) + { + super(type); + this.explosionRadius = explosionRadius; + this.explosionDepth = explosionDepth; + } + + public TileShapedExplosive() + { + this(TYPE, 1, 3); + } + + @Override + public void onUpdate() + { + if (world.isRemote) + { + return; + } +// System.out.println("Counter: " + internalCounter); + + internalCounter++; + if (internalCounter == 20) + { +// worldIn.playSound((PlayerEntity)null, tntentity.getPosX(), tntentity.getPosY(), tntentity.getPosZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F); + world.playSound((PlayerEntity) null, this.getPos().getX() + 0.5, this.getPos().getY() + 0.5, this.getPos().getZ() + 0.5, SoundEvents.ITEM_FLINTANDSTEEL_USE, SoundCategory.BLOCKS, 1.0F, world.rand.nextFloat() * 0.4F + 0.8F); + ((ServerWorld) this.world).spawnParticle(ParticleTypes.FLAME, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 5, 0.02, 0.03, 0.02, 0); + } + + if (internalCounter == 30) + { + world.playSound((PlayerEntity) null, this.getPos().getX() + 0.5, this.getPos().getY() + 0.5, this.getPos().getZ() + 0.5, SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F); + } + + if (internalCounter < 30) + { + return; + } + + if (world.rand.nextDouble() < 0.3) + { + ((ServerWorld) this.world).spawnParticle(ParticleTypes.SMOKE, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 1, 0.0D, 0.0D, 0.0D, 0); + } + + if (internalCounter == 100) + { + world.playSound((PlayerEntity) null, this.getPos().getX() + 0.5, this.getPos().getY() + 0.5, this.getPos().getZ() + 0.5, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F, (1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F) * 0.7F); + + Direction explosiveDirection = this.getBlockState().get(BlockShapedExplosive.ATTACHED).getOpposite(); + Direction sweepDir1 = Direction.UP; + Direction sweepDir2 = Direction.UP; + + int numParticles = explosionDepth * (explosionRadius + 1); + + ((ServerWorld) this.world).spawnParticle(ParticleTypes.EXPLOSION, pos.getX() + 0.5 + explosiveDirection.getXOffset() * explosionDepth / 2d, pos.getY() + 0.5 + explosiveDirection.getYOffset() * explosionDepth / 2d, pos.getZ() + 0.5 + explosiveDirection.getZOffset() * explosionDepth / 2d, numParticles, 1.0D, 1.0D, 1.0D, 0); + + switch (explosiveDirection) + { + case UP: + case DOWN: + sweepDir1 = Direction.NORTH; + sweepDir2 = Direction.EAST; + break; + case EAST: + case WEST: + sweepDir1 = Direction.NORTH; + sweepDir2 = Direction.UP; + break; + case NORTH: + case SOUTH: + sweepDir1 = Direction.EAST; + sweepDir2 = Direction.UP; + break; + } + + ObjectArrayList<Pair<ItemStack, BlockPos>> objectarraylist = new ObjectArrayList<>(); + + BlockPos initialPos = getPos(); + for (int i = 1; i <= explosionDepth; i++) + { + for (int j = -explosionRadius; j <= explosionRadius; j++) + { + for (int k = -explosionRadius; k <= explosionRadius; k++) + { + BlockPos blockpos = initialPos.offset(explosiveDirection, i).offset(sweepDir1, j).offset(sweepDir2, k); + + BlockState blockstate = this.world.getBlockState(blockpos); + Block block = blockstate.getBlock(); + if (!blockstate.isAir(this.world, blockpos)) + { + BlockPos blockpos1 = blockpos.toImmutable(); +// this.world.getProfiler().startSection("explosion_blocks"); + if (this.world instanceof ServerWorld) + { + TileEntity tileentity = blockstate.hasTileEntity() ? this.world.getTileEntity(blockpos) + : null; + LootContext.Builder lootcontext$builder = (new LootContext.Builder((ServerWorld) this.world)).withRandom(this.world.rand).withParameter(LootParameters.field_237457_g_, Vector3d.copyCentered(blockpos)).withParameter(LootParameters.TOOL, ItemStack.EMPTY).withNullableParameter(LootParameters.BLOCK_ENTITY, tileentity); +// if (this.mode == Explosion.Mode.DESTROY) { +// lootcontext$builder.withParameter(LootParameters.EXPLOSION_RADIUS, this.size); +// } + + blockstate.getDrops(lootcontext$builder).forEach((stack) -> { + handleExplosionDrops(objectarraylist, stack, blockpos1); + }); + + world.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 3); + +// blockstate.onBlockExploded(this.world, blockpos, null); +// this.world.getProfiler().endSection(); + } + } + } + } + } + + for (Pair<ItemStack, BlockPos> pair : objectarraylist) + { + Block.spawnAsEntity(this.world, pair.getSecond(), pair.getFirst()); + } + + world.setBlockState(getPos(), Blocks.AIR.getDefaultState()); + } + } + + private static void handleExplosionDrops(ObjectArrayList<Pair<ItemStack, BlockPos>> dropPositionArray, ItemStack stack, BlockPos pos) + { + int i = dropPositionArray.size(); + + for (int j = 0; j < i; ++j) + { + Pair<ItemStack, BlockPos> pair = dropPositionArray.get(j); + ItemStack itemstack = pair.getFirst(); + if (ItemEntity.canMergeStacks(itemstack, stack)) + { + ItemStack itemstack1 = ItemEntity.mergeStacks(itemstack, stack, 16); + dropPositionArray.set(j, Pair.of(itemstack1, pair.getSecond())); + if (stack.isEmpty()) + { + return; + } + } + } + + dropPositionArray.add(Pair.of(stack, pos)); + } + + @Override + public void deserialize(CompoundNBT tag) + { + internalCounter = tag.getDouble("internalCounter"); + } + + @Override + public CompoundNBT serialize(CompoundNBT tag) + { + tag.putDouble("internalCounter", internalCounter); + return tag; + } +} \ No newline at end of file diff --git a/src/main/resources/assets/bloodmagic/models/block/sub/shaped_charge.json b/src/main/resources/assets/bloodmagic/models/block/sub/shaped_charge.json new file mode 100644 index 00000000..f19e2f75 --- /dev/null +++ b/src/main/resources/assets/bloodmagic/models/block/sub/shaped_charge.json @@ -0,0 +1,136 @@ +{ + "parent": "block/block", + "credit": "Made with Blockbench", + "textures": { + "1": "dungeon_tile", + "3": "dungeon_stone", + "4": "blankrune", + "5": "largebloodstonebrick", + "6": "defaultcrystal", + "particle": "dungeon_stone" + }, + "elements": [ + { + "name": "base", + "from": [2, 0, 2], + "to": [14, 2, 14], + "faces": { + "north": {"uv": [0, 6, 10, 8], "texture": "#3"}, + "east": {"uv": [0, 6, 10, 8], "texture": "#3"}, + "south": {"uv": [0, 6, 10, 8], "texture": "#3"}, + "west": {"uv": [8, 14, 18, 16], "texture": "#3"}, + "up": {"uv": [10, 10, 0, 0], "texture": "#3"}, + "down": {"uv": [10, 0, 0, 10], "texture": "#3"} + } + }, + { + "name": "core", + "from": [4, 2, 4], + "to": [12, 5, 12], + "rotation": {"angle": 0, "axis": "y", "origin": [12, 9, 13]}, + "faces": { + "north": {"uv": [4, 5, 12, 8], "texture": "#6"}, + "east": {"uv": [4, 5, 12, 8], "texture": "#6"}, + "south": {"uv": [4, 5, 12, 8], "texture": "#6"}, + "west": {"uv": [4, 5, 12, 8], "texture": "#6"}, + "up": {"uv": [4, 4, 12, 12], "texture": "#6"}, + "down": {"uv": [0, 0, 8, 8], "texture": "#6"} + } + }, + { + "name": "casing1", + "from": [7, 2, 3], + "to": [9, 6, 13], + "rotation": {"angle": 0, "axis": "y", "origin": [15, 10, 11]}, + "faces": { + "north": {"uv": [0, 0, 2, 4], "texture": "#5"}, + "east": {"uv": [0, 0, 10, 4], "texture": "#5"}, + "south": {"uv": [0, 0, 2, 4], "texture": "#5"}, + "west": {"uv": [0, 0, 10, 4], "texture": "#5"}, + "up": {"uv": [0, 0, 2, 10], "texture": "#5"}, + "down": {"uv": [0, 0, 2, 10], "texture": "#5"} + } + }, + { + "name": "casing2", + "from": [3, 2, 7], + "to": [13, 6, 9], + "rotation": {"angle": 0, "axis": "y", "origin": [11, 10, 15]}, + "faces": { + "north": {"uv": [0, 0, 10, 4], "texture": "#5"}, + "east": {"uv": [0, 0, 2, 4], "texture": "#5"}, + "south": {"uv": [0, 0, 10, 4], "texture": "#5"}, + "west": {"uv": [0, 0, 2, 4], "texture": "#5"}, + "up": {"uv": [0, 0, 10, 2], "texture": "#5"}, + "down": {"uv": [0, 0, 10, 2], "texture": "#5"} + } + }, + { + "from": [6, 5, 6], + "to": [10, 7, 10], + "rotation": {"angle": 0, "axis": "y", "origin": [14, 13, 14]}, + "faces": { + "north": {"uv": [0, 0, 4, 2], "texture": "#4"}, + "east": {"uv": [0, 0, 4, 2], "texture": "#4"}, + "south": {"uv": [0, 0, 4, 2], "texture": "#4"}, + "west": {"uv": [0, 0, 4, 2], "texture": "#4"}, + "up": {"uv": [0, 0, 4, 4], "texture": "#4"}, + "down": {"uv": [0, 0, 4, 4], "texture": "#4"} + } + }, + { + "name": "edge1", + "from": [3, 2, 3], + "to": [6, 3, 6], + "rotation": {"angle": 0, "axis": "y", "origin": [14, 8, 9]}, + "faces": { + "north": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "east": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "south": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "west": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "up": {"uv": [5, 5, 8, 8], "rotation": 180, "texture": "#1"}, + "down": {"uv": [5, 5, 8, 8], "rotation": 180, "texture": "#1"} + } + }, + { + "name": "edge2", + "from": [3, 2, 10], + "to": [6, 3, 13], + "rotation": {"angle": 0, "axis": "y", "origin": [14, 8, 16]}, + "faces": { + "north": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "east": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "south": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "west": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "up": {"uv": [5, 5, 8, 8], "rotation": 90, "texture": "#1"}, + "down": {"uv": [5, 5, 8, 8], "rotation": 90, "texture": "#1"} + } + }, + { + "name": "edge3", + "from": [10, 2, 3], + "to": [13, 3, 6], + "faces": { + "north": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "east": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "south": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "west": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "up": {"uv": [5, 5, 8, 8], "rotation": 270, "texture": "#1"}, + "down": {"uv": [5, 5, 8, 8], "rotation": 270, "texture": "#1"} + } + }, + { + "name": "edge4", + "from": [10, 2, 10], + "to": [13, 3, 13], + "faces": { + "north": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "east": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "south": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "west": {"uv": [5, 7, 8, 8], "texture": "#1"}, + "up": {"uv": [5, 5, 8, 8], "texture": "#1"}, + "down": {"uv": [5, 6, 8, 9], "texture": "#1"} + } + } + ] +} \ No newline at end of file