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

93 lines
3.6 KiB
Java
Raw Normal View History

2019-03-19 17:21:06 +01:00
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.ModConfig;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
2019-03-19 17:21:06 +01:00
import de.ellpeck.naturesaura.api.render.IVisualizable;
2021-12-04 15:40:09 +01:00
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityChunkLoader;
2020-01-29 00:40:28 +01:00
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
2022-06-27 15:24:04 +02:00
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
2022-06-27 15:24:04 +02:00
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
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
2020-01-29 00:40:28 +01:00
public class BlockChunkLoader extends BlockContainerImpl implements IVisualizable, ICustomBlockState {
2019-03-19 17:21:06 +01:00
2022-06-27 15:24:04 +02:00
private static final VoxelShape SHAPE = Block.box(4, 4, 4, 12, 12, 12);
2019-03-31 11:38:07 +02:00
2019-03-19 17:21:06 +01:00
public BlockChunkLoader() {
2023-07-08 12:32:27 +02:00
super("chunk_loader", BlockEntityChunkLoader.class, Properties.of().strength(3F).sound(SoundType.STONE));
2019-03-19 17:21:06 +01:00
}
@Override
protected boolean hasWaterlogging() {
return true;
}
2019-03-19 17:21:06 +01:00
@Override
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
public AABB getVisualizationBounds(Level level, BlockPos pos) {
2021-12-15 16:30:22 +01:00
var tile = level.getBlockEntity(pos);
2021-12-04 15:40:09 +01:00
if (tile instanceof BlockEntityChunkLoader) {
2021-12-15 16:30:22 +01:00
var range = ((BlockEntityChunkLoader) tile).range();
2019-03-19 17:21:06 +01:00
if (range > 0) {
return new AABB(
2022-06-27 15:24:04 +02:00
pos.getX() - range >> 4 << 4,
level.getMinBuildHeight(),
2022-06-27 15:24:04 +02:00
pos.getZ() - range >> 4 << 4,
(pos.getX() + range >> 4 << 4) + 16,
level.getMaxBuildHeight(),
2022-06-27 15:24:04 +02:00
(pos.getZ() + range >> 4 << 4) + 16);
2019-03-19 17:21:06 +01:00
}
}
return null;
}
@Override
2019-10-20 22:30:49 +02:00
@OnlyIn(Dist.CLIENT)
2022-06-27 15:24:04 +02:00
public void animateTick(BlockState stateIn, Level levelIn, BlockPos pos, RandomSource rand) {
if (!ModConfig.instance.chunkLoader.get())
return;
2021-12-15 16:30:22 +01:00
var tile = levelIn.getBlockEntity(pos);
2023-02-16 19:03:26 +01:00
if (tile instanceof BlockEntityChunkLoader loader && loader.canUseRightNow(loader.getAuraUsed())) {
for (var i = Mth.ceil(loader.range() / 8F); i > 0; i--) {
NaturesAuraAPI.instance().spawnMagicParticle(
pos.getX() + levelIn.random.nextFloat(), pos.getY() + levelIn.random.nextFloat(), pos.getZ() + levelIn.random.nextFloat(),
0, 0, 0, 0xa12dff, 1F + levelIn.random.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)
2021-12-04 15:40:09 +01:00
public int getVisualizationColor(Level level, BlockPos pos) {
2019-03-19 17:21:06 +01:00
return 0xc159f9;
}
2019-03-31 11:38:07 +02:00
@Override
2023-02-15 23:45:50 +01:00
@SuppressWarnings("deprecation")
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context) {
2022-06-27 15:24:04 +02:00
return BlockChunkLoader.SHAPE;
2019-03-31 11:38:07 +02:00
}
2020-01-29 00:40:28 +01:00
@Override
public String getDescriptionId() {
return ModConfig.instance.chunkLoader.get() ? super.getDescriptionId() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
}
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
}