2019-03-19 17:21:06 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2021-01-11 23:39:19 +01:00
|
|
|
import de.ellpeck.naturesaura.ModConfig;
|
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2019-03-31 12:28:59 +02:00
|
|
|
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;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.core.BlockPos;
|
|
|
|
import net.minecraft.util.Mth;
|
2022-06-27 15:24:04 +02:00
|
|
|
import net.minecraft.util.RandomSource;
|
2021-12-15 14:26:42 +01:00
|
|
|
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;
|
2021-12-15 14:26:42 +01:00
|
|
|
import net.minecraft.world.level.block.SoundType;
|
|
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
|
|
import net.minecraft.world.level.material.Material;
|
|
|
|
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() {
|
2021-12-19 15:32:45 +01:00
|
|
|
super("chunk_loader", BlockEntityChunkLoader.class, Properties.of(Material.STONE).strength(3F).sound(SoundType.STONE));
|
2019-03-19 17:21:06 +01:00
|
|
|
}
|
|
|
|
|
2020-02-05 14:30:17 +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)
|
2021-12-15 14:26:42 +01:00
|
|
|
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) {
|
2021-12-15 14:26:42 +01:00
|
|
|
return new AABB(
|
2022-06-27 15:24:04 +02:00
|
|
|
pos.getX() - range >> 4 << 4,
|
2023-02-06 11:21:22 +01:00
|
|
|
level.getMinBuildHeight(),
|
2022-06-27 15:24:04 +02:00
|
|
|
pos.getZ() - range >> 4 << 4,
|
|
|
|
(pos.getX() + range >> 4 << 4) + 16,
|
2023-02-06 11:21:22 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-31 12:28:59 +02:00
|
|
|
@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) {
|
2021-01-11 23:39:19 +01:00
|
|
|
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--) {
|
2019-03-31 12:28:59 +02:00
|
|
|
NaturesAuraAPI.instance().spawnMagicParticle(
|
2021-12-15 14:26:42 +01:00
|
|
|
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-31 12:28:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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")
|
2021-12-15 14:26:42 +01:00
|
|
|
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
|
|
|
|
2021-01-11 23:39:19 +01:00
|
|
|
@Override
|
2021-12-15 14:26:42 +01:00
|
|
|
public String getDescriptionId() {
|
|
|
|
return ModConfig.instance.chunkLoader.get() ? super.getDescriptionId() : "block." + NaturesAura.MOD_ID + "." + this.getBaseName() + ".disabled";
|
2021-01-11 23:39:19 +01: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
|
|
|
}
|