snow creator, part 1

This commit is contained in:
Ellpeck 2020-02-02 22:21:55 +01:00
parent 2a88c1e7ac
commit 93d65914b7
6 changed files with 111 additions and 1 deletions

View file

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

View file

@ -60,6 +60,7 @@ public final class ModBlocks {
public static Block BLAST_FURNACE_BOOSTER; public static Block BLAST_FURNACE_BOOSTER;
public static Block NETHER_WART_MUSHROOM; public static Block NETHER_WART_MUSHROOM;
public static Block ANIMAL_CONTAINER; public static Block ANIMAL_CONTAINER;
public static Block SNOW_CREATOR;
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

@ -34,4 +34,5 @@ public final class ModTileEntities {
public static TileEntityType<TileEntityWoodStand> WOOD_STAND; public static TileEntityType<TileEntityWoodStand> WOOD_STAND;
public static TileEntityType<TileEntityBlastFurnaceBooster> BLAST_FURNACE_BOOSTER; public static TileEntityType<TileEntityBlastFurnaceBooster> BLAST_FURNACE_BOOSTER;
public static TileEntityType<TileEntityAnimalContainer> ANIMAL_CONTAINER; public static TileEntityType<TileEntityAnimalContainer> ANIMAL_CONTAINER;
public static TileEntityType<TileEntitySnowCreator> SNOW_CREATOR;
} }

View file

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

View file

@ -56,6 +56,10 @@ public class ParticleMagic extends Particle {
} else { } else {
this.motionY -= 0.04D * (double) this.particleGravity; this.motionY -= 0.04D * (double) this.particleGravity;
this.move(this.motionX, this.motionY, this.motionZ); 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; float lifeRatio = (float) this.age / (float) this.maxAge;
if (this.fade && lifeRatio > 0.75F) if (this.fade && lifeRatio > 0.75F)

View file

@ -108,7 +108,8 @@ public final class ModRegistry {
new BlockDimensionRail("end", DimensionType.THE_END, DimensionType.OVERWORLD), new BlockDimensionRail("end", DimensionType.THE_END, DimensionType.OVERWORLD),
new BlockBlastFurnaceBooster(), new BlockBlastFurnaceBooster(),
new BlockImpl("nether_wart_mushroom", ModBlocks.prop(Blocks.RED_MUSHROOM_BLOCK)), new BlockImpl("nether_wart_mushroom", ModBlocks.prop(Blocks.RED_MUSHROOM_BLOCK)),
new BlockAnimalContainer() new BlockAnimalContainer(),
new BlockSnowCreator()
); );
if (ModConfig.instance.rfConverter.get()) if (ModConfig.instance.rfConverter.get())