From 93d65914b77cb11a6a0346e859107da938a9f591 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 2 Feb 2020 22:21:55 +0100 Subject: [PATCH] snow creator, part 1 --- .../naturesaura/blocks/BlockSnowCreator.java | 34 +++++++++ .../ellpeck/naturesaura/blocks/ModBlocks.java | 1 + .../blocks/tiles/ModTileEntities.java | 1 + .../blocks/tiles/TileEntitySnowCreator.java | 69 +++++++++++++++++++ .../naturesaura/particles/ParticleMagic.java | 4 ++ .../ellpeck/naturesaura/reg/ModRegistry.java | 3 +- 6 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/BlockSnowCreator.java create mode 100644 src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySnowCreator.java diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockSnowCreator.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockSnowCreator.java new file mode 100644 index 00000000..49acd2d4 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockSnowCreator.java @@ -0,0 +1,34 @@ +package de.ellpeck.naturesaura.blocks; + +import de.ellpeck.naturesaura.api.render.IVisualizable; +import de.ellpeck.naturesaura.blocks.tiles.TileEntitySnowCreator; +import net.minecraft.block.Blocks; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; + +public class BlockSnowCreator extends BlockContainerImpl implements IVisualizable { + public BlockSnowCreator() { + super("snow_creator", TileEntitySnowCreator::new, ModBlocks.prop(Blocks.CRAFTING_TABLE)); + } + + @Override + @OnlyIn(Dist.CLIENT) + public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) { + TileEntity tile = world.getTileEntity(pos); + if (tile instanceof TileEntitySnowCreator) { + int radius = ((TileEntitySnowCreator) tile).getRange(); + if (radius > 0) + return new AxisAlignedBB(pos).grow(radius); + } + return null; + } + + @Override + public int getVisualizationColor(World world, BlockPos pos) { + return 0xdbe9ff; + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java index b0e00d28..3cd4cc91 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/ModBlocks.java @@ -60,6 +60,7 @@ public final class ModBlocks { public static Block BLAST_FURNACE_BOOSTER; public static Block NETHER_WART_MUSHROOM; public static Block ANIMAL_CONTAINER; + public static Block SNOW_CREATOR; 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 339dae3b..7190c38d 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/ModTileEntities.java @@ -34,4 +34,5 @@ public final class ModTileEntities { public static TileEntityType WOOD_STAND; public static TileEntityType BLAST_FURNACE_BOOSTER; public static TileEntityType ANIMAL_CONTAINER; + public static TileEntityType SNOW_CREATOR; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySnowCreator.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySnowCreator.java new file mode 100644 index 00000000..1047d836 --- /dev/null +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySnowCreator.java @@ -0,0 +1,69 @@ +package de.ellpeck.naturesaura.blocks.tiles; + +import de.ellpeck.naturesaura.api.NaturesAuraAPI; +import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk; +import net.minecraft.block.Blocks; +import net.minecraft.fluid.Fluid; +import net.minecraft.fluid.Fluids; +import net.minecraft.tileentity.ITickableTileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; +import net.minecraft.world.gen.Heightmap; + +public class TileEntitySnowCreator extends TileEntityImpl implements ITickableTileEntity { + public TileEntitySnowCreator() { + super(ModTileEntities.SNOW_CREATOR); + } + + public int getRange() { + return this.redstonePower * 2; + } + + @Override + public void onRedstonePowerChange(int newPower) { + super.onRedstonePowerChange(newPower); + this.sendToClients(); + } + + @Override + public void tick() { + int range = this.getRange(); + if (range <= 0) + return; + + if (!this.world.isRemote) { + if (this.world.getGameTime() % 10 != 0) + return; + + BlockPos pos = this.pos.add(MathHelper.nextInt(this.world.rand, -range, range), 0, MathHelper.nextInt(this.world.rand, -range, range)); + pos = this.world.getHeight(Heightmap.Type.MOTION_BLOCKING, pos); + BlockPos down = pos.down(); + + Fluid fluid = this.world.getFluidState(down).getFluid(); + if (fluid == Fluids.WATER) { + this.world.setBlockState(down, Blocks.ICE.getDefaultState()); + } else if (Blocks.SNOW.getDefaultState().isValidPosition(this.world, pos)) { + this.world.setBlockState(pos, Blocks.SNOW.getDefaultState()); + } else { + return; + } + + BlockPos auraPos = IAuraChunk.getHighestSpot(this.world, this.pos, 30, this.pos); + IAuraChunk.getAuraChunk(this.world, auraPos).drainAura(auraPos, 300); + } else { + if (this.world.getGameTime() % 30 != 0) + return; + for (int i = range * 5; i >= 0; i--) { + BlockPos randomPos = this.pos.add( + MathHelper.nextInt(this.world.rand, -range, range), + MathHelper.nextInt(this.world.rand, range / 2, range), + MathHelper.nextInt(this.world.rand, -range, range)); + NaturesAuraAPI.instance().spawnMagicParticle( + randomPos.getX() + this.world.rand.nextFloat(), randomPos.getY() + 1, randomPos.getZ() + this.world.rand.nextFloat(), + this.world.rand.nextGaussian() * 0.05, 0, this.world.rand.nextGaussian() * 0.05, + 0xdbe9ff, 1 + this.world.rand.nextFloat() * 1.5F, 10 * range, 0.05F + this.world.rand.nextFloat() * 0.05F, true, true + ); + } + } + } +} diff --git a/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java b/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java index 45c81020..24e7de6d 100644 --- a/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java +++ b/src/main/java/de/ellpeck/naturesaura/particles/ParticleMagic.java @@ -56,6 +56,10 @@ public class ParticleMagic extends Particle { } else { this.motionY -= 0.04D * (double) this.particleGravity; this.move(this.motionX, this.motionY, this.motionZ); + if (Math.abs(this.posY - this.prevPosY) <= 0.01F) { + this.motionX *= 0.7F; + this.motionZ *= 0.7F; + } float lifeRatio = (float) this.age / (float) this.maxAge; if (this.fade && lifeRatio > 0.75F) diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index f32de1c0..635d950a 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -108,7 +108,8 @@ public final class ModRegistry { new BlockDimensionRail("end", DimensionType.THE_END, DimensionType.OVERWORLD), new BlockBlastFurnaceBooster(), new BlockImpl("nether_wart_mushroom", ModBlocks.prop(Blocks.RED_MUSHROOM_BLOCK)), - new BlockAnimalContainer() + new BlockAnimalContainer(), + new BlockSnowCreator() ); if (ModConfig.instance.rfConverter.get())