From 1c3e3dfd2a8a5c4c7610d89fea36fde984ba5999 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 4 May 2020 23:39:57 +0200 Subject: [PATCH] chorus generator, part 1 --- .../blockstates/chorus_generator.json | 7 ++ .../models/block/chorus_generator.json | 8 ++ .../models/item/chorus_generator.json | 3 + .../loot_tables/blocks/chorus_generator.json | 19 ++++ .../blocks/BlockChorusGenerator.java | 23 ++++ .../ellpeck/naturesaura/blocks/ModBlocks.java | 1 + .../blocks/tiles/ModTileEntities.java | 1 + .../tiles/TileEntityChorusGenerator.java | 101 ++++++++++++++++++ .../naturesaura/packet/PacketParticles.java | 19 ++++ .../ellpeck/naturesaura/reg/ModRegistry.java | 3 +- .../assets/naturesaura/lang/en_us.json | 1 + .../textures/block/chorus_generator.png | Bin 0 -> 675 bytes .../textures/block/chorus_generator_top.png | Bin 0 -> 677 bytes 13 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 src/generated/resources/assets/naturesaura/blockstates/chorus_generator.json create mode 100644 src/generated/resources/assets/naturesaura/models/block/chorus_generator.json create mode 100644 src/generated/resources/assets/naturesaura/models/item/chorus_generator.json create mode 100644 src/generated/resources/data/naturesaura/loot_tables/blocks/chorus_generator.json create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/BlockChorusGenerator.java create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityChorusGenerator.java create mode 100644 src/main/resources/assets/naturesaura/textures/block/chorus_generator.png create mode 100644 src/main/resources/assets/naturesaura/textures/block/chorus_generator_top.png diff --git a/src/generated/resources/assets/naturesaura/blockstates/chorus_generator.json b/src/generated/resources/assets/naturesaura/blockstates/chorus_generator.json new file mode 100644 index 00000000..43edd27a --- /dev/null +++ b/src/generated/resources/assets/naturesaura/blockstates/chorus_generator.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "naturesaura:block/chorus_generator" + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/naturesaura/models/block/chorus_generator.json b/src/generated/resources/assets/naturesaura/models/block/chorus_generator.json new file mode 100644 index 00000000..74ae7f7d --- /dev/null +++ b/src/generated/resources/assets/naturesaura/models/block/chorus_generator.json @@ -0,0 +1,8 @@ +{ + "parent": "block/cube_bottom_top", + "textures": { + "side": "naturesaura:block/chorus_generator", + "bottom": "naturesaura:block/chorus_generator", + "top": "naturesaura:block/chorus_generator_top" + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/naturesaura/models/item/chorus_generator.json b/src/generated/resources/assets/naturesaura/models/item/chorus_generator.json new file mode 100644 index 00000000..1937245f --- /dev/null +++ b/src/generated/resources/assets/naturesaura/models/item/chorus_generator.json @@ -0,0 +1,3 @@ +{ + "parent": "naturesaura:block/chorus_generator" +} \ No newline at end of file diff --git a/src/generated/resources/data/naturesaura/loot_tables/blocks/chorus_generator.json b/src/generated/resources/data/naturesaura/loot_tables/blocks/chorus_generator.json new file mode 100644 index 00000000..cb2e8a5e --- /dev/null +++ b/src/generated/resources/data/naturesaura/loot_tables/blocks/chorus_generator.json @@ -0,0 +1,19 @@ +{ + "type": "minecraft:block", + "pools": [ + { + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "naturesaura:chorus_generator" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] + } + ] +} \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockChorusGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockChorusGenerator.java new file mode 100644 index 00000000..a41be5db --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockChorusGenerator.java @@ -0,0 +1,23 @@ +package de.ellpeck.naturesaura.blocks; + +import de.ellpeck.naturesaura.blocks.tiles.TileEntityChorusGenerator; +import de.ellpeck.naturesaura.data.BlockStateGenerator; +import de.ellpeck.naturesaura.reg.ICustomBlockState; +import net.minecraft.block.Blocks; +import net.minecraft.tileentity.TileEntity; + +import java.util.function.Supplier; + +public class BlockChorusGenerator extends BlockContainerImpl implements ICustomBlockState { + public BlockChorusGenerator() { + super("chorus_generator", TileEntityChorusGenerator::new, Properties.from(Blocks.END_STONE)); + } + + @Override + public void generateCustomBlockState(BlockStateGenerator generator) { + generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(), + generator.modLoc("block/" + this.getBaseName()), + generator.modLoc("block/" + this.getBaseName()), + generator.modLoc("block/" + this.getBaseName() + "_top"))); + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index 01d36709..b3966aba 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -68,6 +68,7 @@ public final class ModBlocks { public static Block TAINTED_GOLD_BLOCK; public static Block NETHER_GRASS; public static Block LIGHT; + public static Block CHORUS_GENERATOR; public static Block.Properties prop(Material material, MaterialColor color) { return Block.Properties.create(material, color); diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java index 9f6b6249..e4b6f5d9 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java @@ -38,4 +38,5 @@ public final class ModTileEntities { public static TileEntityType ITEM_DISTRIBUTOR; public static TileEntityType AURA_BLOOM; public static TileEntityType AURA_CACTUS; + public static TileEntityType CHORUS_GENERATOR; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityChorusGenerator.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityChorusGenerator.java new file mode 100644 index 00000000..7be48df3 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityChorusGenerator.java @@ -0,0 +1,101 @@ +package de.ellpeck.naturesaura.blocks.tiles; + +import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import de.ellpeck.naturesaura.chunk.AuraChunk; +import de.ellpeck.naturesaura.packet.PacketHandler; +import de.ellpeck.naturesaura.packet.PacketParticles; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.tileentity.ITickableTileEntity; +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 java.util.*; + +public class TileEntityChorusGenerator extends TileEntityImpl implements ITickableTileEntity { + + private final Deque currentlyBreaking = new ArrayDeque<>(); + private int auraPerBlock; + + public TileEntityChorusGenerator() { + super(ModTileEntities.CHORUS_GENERATOR); + } + + @Override + public void tick() { + if (this.world.isRemote) + return; + if (this.world.getGameTime() % 5 != 0) + return; + if (this.currentlyBreaking.isEmpty()) + return; + BlockPos pos = this.currentlyBreaking.removeLast(); + BlockState state = this.world.getBlockState(pos); + if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER) { + this.currentlyBreaking.clear(); + return; + } + PacketHandler.sendToAllAround(this.world, this.pos, 32, new PacketParticles(this.pos.getX(), this.pos.getY(), this.pos.getZ(), PacketParticles.Type.CHORUS_GENERATOR, pos.getX(), pos.getY(), pos.getZ())); + this.world.removeBlock(pos, false); + this.world.playSound(null, this.pos.getX() + 0.5, this.pos.getY() + 0.5, this.pos.getZ() + 0.5, + SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.BLOCKS, 0.5F, 1F); + + int aura = this.auraPerBlock; + while (aura > 0) { + BlockPos spot = IAuraChunk.getLowestSpot(this.world, this.pos, 35, this.pos); + aura -= IAuraChunk.getAuraChunk(this.world, spot).storeAura(spot, aura); + } + } + + @Override + public void onRedstonePowerChange(int newPower) { + if (this.redstonePower <= 0 && newPower > 0 && this.currentlyBreaking.isEmpty()) { + int range = 2; + xyz: + for (int x = -range; x <= range; x++) { + for (int y = -range; y <= range; y++) { + for (int z = -range; z <= range; z++) { + BlockPos offset = this.pos.add(x, y, z); + BlockState below = this.world.getBlockState(offset.down()); + if (below.getBlock() != Blocks.END_STONE) + continue; + BlockState state = this.world.getBlockState(offset); + if (state.getBlock() != Blocks.CHORUS_PLANT) + continue; + + List plants = new ArrayList<>(); + this.collectChorusPlant(offset, plants); + if (plants.size() <= 1) + continue; + this.currentlyBreaking.addAll(plants); + this.currentlyBreaking.addFirst(offset); + + int aura = plants.size() * plants.size() * 300; + this.auraPerBlock = aura / plants.size(); + + break xyz; + } + } + } + } + super.onRedstonePowerChange(newPower); + } + + private void collectChorusPlant(BlockPos pos, List blocks) { + for (Direction dir : Direction.values()) { + if (dir == Direction.DOWN) + continue; + BlockPos offset = pos.offset(dir); + if (blocks.contains(offset)) + continue; + BlockState state = this.world.getBlockState(offset); + if (state.getBlock() != Blocks.CHORUS_PLANT && state.getBlock() != Blocks.CHORUS_FLOWER) + continue; + blocks.add(offset); + this.collectChorusPlant(offset, blocks); + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java index 75d80105..ecb3a2b1 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java @@ -485,6 +485,25 @@ public class PacketParticles { message.posX + 0.5F, message.posY + 0.5F, message.posZ + 0.5F, 0.25F, color, 0.5F + world.rand.nextFloat() ); + }), + CHORUS_GENERATOR((message, world) -> { + int chorusX = message.data[0]; + int chorusY = message.data[1]; + int chorusZ = message.data[2]; + for (int i = world.rand.nextInt(5) + 3; i >= 0; i--) + NaturesAuraAPI.instance().spawnMagicParticle( + chorusX + world.rand.nextFloat(), chorusY + world.rand.nextFloat(), chorusZ + world.rand.nextFloat(), + 0F, 0F, 0F, + 0xbb0be3, 1F + world.rand.nextFloat(), 50, 0F, false, true); + for (int i = world.rand.nextInt(5) + 5; i >= 0; i--) + NaturesAuraAPI.instance().spawnMagicParticle( + message.posX + 0.25F + world.rand.nextFloat() * 0.5F, + message.posY + 1.01F, + message.posZ + 0.25F + world.rand.nextFloat() * 0.5F, + world.rand.nextGaussian() * 0.01F, + world.rand.nextFloat() * 0.04F + 0.02F, + world.rand.nextGaussian() * 0.01F, + 0x5ccc30, 1F + world.rand.nextFloat() * 1.5F, 40, 0F, false, true); }); public final BiConsumer action; diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index c2c642bf..0ba85e21 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -136,7 +136,8 @@ public final class ModRegistry { createFlowerPot(temp), new BlockImpl("tainted_gold_block", ModBlocks.prop(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(3F)), new BlockNetherGrass(), - new BlockLight() + new BlockLight(), + new BlockChorusGenerator() ); if (ModConfig.instance.rfConverter.get()) diff --git a/src/main/resources/assets/naturesaura/lang/en_us.json b/src/main/resources/assets/naturesaura/lang/en_us.json index ed6e6d4f..8af30095 100644 --- a/src/main/resources/assets/naturesaura/lang/en_us.json +++ b/src/main/resources/assets/naturesaura/lang/en_us.json @@ -63,6 +63,7 @@ "block.naturesaura.aura_cactus": "Aura Cactus", "block.naturesaura.tainted_gold_block": "Tainted Gold Block", "block.naturesaura.nether_grass": "Grassy Netherrack", + "block.naturesaura.chorus_generator": "Reaper of the Ender Heights", "item.naturesaura.eye": "Environmental Eye", "item.naturesaura.eye_improved": "Environmental Ocular", "item.naturesaura.gold_fiber": "Brilliant Fiber", diff --git a/src/main/resources/assets/naturesaura/textures/block/chorus_generator.png b/src/main/resources/assets/naturesaura/textures/block/chorus_generator.png new file mode 100644 index 0000000000000000000000000000000000000000..d5b156766c59369d31ac47f5a96d3743057c71e9 GIT binary patch literal 675 zcmV;U0$lxxP)l$)X+3Ty$-}X&ue0N&?g%nj`T@UZ7TOM4;Q9v`WR9FyxVKEC;lQpmD> zyg>EO1yZ{}2*J2#*%EMjd}Q=EX1T=N&OnUEcOM<06tV!Mb2Ie$2KfH<8-OM7_EQ9x&y5g*r`{D*qsZ{V2*WRi0r>I((m9FR zc@?Q$usW)sRrIES%jYH$KBOV$?2`EP8P0y5(S6UN*qt?q$$o?oHjOQi2p`%OAi&yG zp56|_+CH%srI3Xvc9Xur0mePc)+0Jv9i($JT$HP9E*{+wgT!irI}eU%YK%)L$B!4jBKVB9j0B002ov JPDHLkV1nl%D}(?5 literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/naturesaura/textures/block/chorus_generator_top.png b/src/main/resources/assets/naturesaura/textures/block/chorus_generator_top.png new file mode 100644 index 0000000000000000000000000000000000000000..36b7a3e4ad5d62559db1fc7a9be0334e85c11745 GIT binary patch literal 677 zcmV;W0$TlvP)s-|xT2+wX01gku5_OajApH(Ng+@hp9->we916~QF%JUhj(-Hl)pc=>G>!6bA9 z(&c$dno87{pk9ZS%^*&*16|h<6^WP}!fJQnG&_jrBh;!o@qDBs5cMU9$stObN@k%# zy$+%xQLE|zSnV#BCuBrL;>;;4R=bPEKn8#wZ@;%Gm;}a$#(3~RrPzIRro=tRX5Ajl)Lk1uL6DL`CB6#dY3lPY@M}_sx&gcWb07uMriArDTx$Zp|28 z*$j3N`dn7ShvMgLrgNhJe08b-Oy@@Vbh<#F%ZjK-q|5Vc%vCxF!*(}LvxC_;eu~*5 z$~o1DY5#W}fXn+HHs&e>9{17P3-_+4XdE^=9sms52AElGZU1nx0Kh@xk0F){d}q)$ zfYa< z(k~C&w-36u?}VEq!WuC-WJGQVtVMH(ibP3Mu~;muMRSxi760A{JK-k&y%9>9il|6D zy^$pm)<~D<0a^$pP3^*PnjOrnj&k;bo066yv*2LRHo*N?z7B%#AB1>5g0AaWEEc0Q z0Lv3HF*#(su8q)++z?owEOZSoC4)wt+Y93Ph=HK%y3xv>qkiYV6O=B$0oT)r00000 LNkvXXu0mjfDH1h* literal 0 HcmV?d00001