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 00000000..d5b15676 Binary files /dev/null and b/src/main/resources/assets/naturesaura/textures/block/chorus_generator.png differ 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 00000000..36b7a3e4 Binary files /dev/null and b/src/main/resources/assets/naturesaura/textures/block/chorus_generator_top.png differ