chorus generator, part 1

This commit is contained in:
Ellpeck 2020-05-04 23:39:57 +02:00
parent fd2c663653
commit 1c3e3dfd2a
13 changed files with 185 additions and 1 deletions

View file

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "naturesaura:block/chorus_generator"
}
}
}

View file

@ -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"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "naturesaura:block/chorus_generator"
}

View file

@ -0,0 +1,19 @@
{
"type": "minecraft:block",
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "minecraft:item",
"name": "naturesaura:chorus_generator"
}
],
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
]
}
]
}

View file

@ -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")));
}
}

View file

@ -68,6 +68,7 @@ public final class ModBlocks {
public static Block TAINTED_GOLD_BLOCK; public static Block TAINTED_GOLD_BLOCK;
public static Block NETHER_GRASS; public static Block NETHER_GRASS;
public static Block LIGHT; public static Block LIGHT;
public static Block CHORUS_GENERATOR;
public static Block.Properties prop(Material material, MaterialColor color) { public static Block.Properties prop(Material material, MaterialColor color) {
return Block.Properties.create(material, color); return Block.Properties.create(material, color);

View file

@ -38,4 +38,5 @@ public final class ModTileEntities {
public static TileEntityType<TileEntityItemDistributor> ITEM_DISTRIBUTOR; public static TileEntityType<TileEntityItemDistributor> ITEM_DISTRIBUTOR;
public static TileEntityType<TileEntityAuraBloom> AURA_BLOOM; public static TileEntityType<TileEntityAuraBloom> AURA_BLOOM;
public static TileEntityType<TileEntityAuraBloom> AURA_CACTUS; public static TileEntityType<TileEntityAuraBloom> AURA_CACTUS;
public static TileEntityType<TileEntityChorusGenerator> CHORUS_GENERATOR;
} }

View file

@ -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<BlockPos> 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<BlockPos> 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<BlockPos> 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);
}
}
}

View file

@ -485,6 +485,25 @@ public class PacketParticles {
message.posX + 0.5F, message.posY + 0.5F, message.posZ + 0.5F, message.posX + 0.5F, message.posY + 0.5F, message.posZ + 0.5F,
0.25F, color, 0.5F + world.rand.nextFloat() 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<PacketParticles, World> action; public final BiConsumer<PacketParticles, World> action;

View file

@ -136,7 +136,8 @@ public final class ModRegistry {
createFlowerPot(temp), createFlowerPot(temp),
new BlockImpl("tainted_gold_block", ModBlocks.prop(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(3F)), new BlockImpl("tainted_gold_block", ModBlocks.prop(Material.IRON).sound(SoundType.METAL).hardnessAndResistance(3F)),
new BlockNetherGrass(), new BlockNetherGrass(),
new BlockLight() new BlockLight(),
new BlockChorusGenerator()
); );
if (ModConfig.instance.rfConverter.get()) if (ModConfig.instance.rfConverter.get())

View file

@ -63,6 +63,7 @@
"block.naturesaura.aura_cactus": "Aura Cactus", "block.naturesaura.aura_cactus": "Aura Cactus",
"block.naturesaura.tainted_gold_block": "Tainted Gold Block", "block.naturesaura.tainted_gold_block": "Tainted Gold Block",
"block.naturesaura.nether_grass": "Grassy Netherrack", "block.naturesaura.nether_grass": "Grassy Netherrack",
"block.naturesaura.chorus_generator": "Reaper of the Ender Heights",
"item.naturesaura.eye": "Environmental Eye", "item.naturesaura.eye": "Environmental Eye",
"item.naturesaura.eye_improved": "Environmental Ocular", "item.naturesaura.eye_improved": "Environmental Ocular",
"item.naturesaura.gold_fiber": "Brilliant Fiber", "item.naturesaura.gold_fiber": "Brilliant Fiber",

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B