NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/BlockChunkLoader.java

81 lines
3.1 KiB
Java
Raw Normal View History

2019-03-19 17:21:06 +01:00
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
2019-03-19 17:21:06 +01:00
import de.ellpeck.naturesaura.api.render.IVisualizable;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityChunkLoader;
2020-01-29 00:40:28 +01:00
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
2020-01-21 21:04:44 +01:00
import net.minecraft.block.BlockState;
2019-03-19 17:21:06 +01:00
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
2019-11-04 19:08:49 +01:00
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.world.IBlockReader;
2019-03-19 17:21:06 +01:00
import net.minecraft.world.World;
2019-10-20 22:30:49 +02:00
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
2019-03-19 17:21:06 +01:00
import java.util.Random;
2019-03-19 17:21:06 +01:00
2020-01-29 00:40:28 +01:00
public class BlockChunkLoader extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
2019-03-19 17:21:06 +01:00
2019-11-04 19:08:49 +01:00
private static final VoxelShape SHAPE = makeCuboidShape(4, 4, 4, 12, 12, 12);
2019-03-31 11:38:07 +02:00
2019-03-19 17:21:06 +01:00
public BlockChunkLoader() {
2020-01-22 01:32:26 +01:00
super("chunk_loader", TileEntityChunkLoader::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(3F).sound(SoundType.STONE));
2019-03-19 17:21:06 +01:00
}
@Override
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
2019-03-19 17:21:06 +01:00
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityChunkLoader) {
int range = ((TileEntityChunkLoader) tile).range();
if (range > 0) {
return new AxisAlignedBB(
(pos.getX() - range) >> 4 << 4,
0,
(pos.getZ() - range) >> 4 << 4,
((pos.getX() + range) >> 4 << 4) + 16,
world.getHeight(),
((pos.getZ() + range) >> 4 << 4) + 16);
}
}
return null;
}
@Override
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
2019-11-04 19:08:49 +01:00
public void animateTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
TileEntity tile = worldIn.getTileEntity(pos);
if (tile instanceof TileEntityChunkLoader) {
int range = ((TileEntityChunkLoader) tile).range();
for (int i = MathHelper.ceil(range / 8F); i > 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + worldIn.rand.nextFloat(), pos.getY() + worldIn.rand.nextFloat(), pos.getZ() + worldIn.rand.nextFloat(),
0, 0, 0, 0xa12dff, 1F + worldIn.rand.nextFloat(), 100, 0, false, true);
}
}
}
2019-03-19 17:21:06 +01:00
@Override
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
2019-03-19 17:21:06 +01:00
public int getVisualizationColor(World world, BlockPos pos) {
return 0xc159f9;
}
2019-03-31 11:38:07 +02:00
@Override
2019-11-04 19:08:49 +01:00
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
return SHAPE;
2019-03-31 11:38:07 +02:00
}
2020-01-29 00:40:28 +01:00
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().getExistingFile(generator.modLoc(this.getBaseName())));
}
2019-03-19 17:21:06 +01:00
}