2019-03-19 17:21:06 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
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;
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityChunkLoader;
|
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
2019-03-31 11:38:07 +02:00
|
|
|
import net.minecraft.block.state.BlockFaceShape;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.nbt.CompoundNBT;
|
2019-03-19 17:21:06 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.util.Direction;
|
2019-03-19 17:21:06 +01:00
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-03-31 12:28:59 +02:00
|
|
|
import net.minecraft.util.math.MathHelper;
|
2019-03-31 11:38:07 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
2019-03-19 17:21:06 +01:00
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.ForgeChunkManager;
|
|
|
|
import net.minecraftforge.common.ForgeChunkManager.Ticket;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
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.List;
|
2019-03-31 12:28:59 +02:00
|
|
|
import java.util.Random;
|
2019-03-19 17:21:06 +01:00
|
|
|
|
|
|
|
public class BlockChunkLoader extends BlockContainerImpl implements IVisualizable {
|
|
|
|
|
2019-03-31 11:38:07 +02:00
|
|
|
private static final AxisAlignedBB BOUND_BOX = new AxisAlignedBB(4 / 16F, 4 / 16F, 4 / 16F, 12 / 16F, 12 / 16F, 12 / 16F);
|
|
|
|
|
2019-03-19 17:21:06 +01:00
|
|
|
public BlockChunkLoader() {
|
|
|
|
super(Material.ROCK, "chunk_loader", TileEntityChunkLoader.class, "chunk_loader");
|
|
|
|
this.setSoundType(SoundType.STONE);
|
|
|
|
this.setHardness(3F);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInit(FMLInitializationEvent event) {
|
|
|
|
super.onInit(event);
|
|
|
|
ForgeChunkManager.setForcedChunkLoadingCallback(NaturesAura.instance, new ChunkLoadingCallback());
|
|
|
|
}
|
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
2019-03-31 12:28:59 +02:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public void randomDisplayTick(BlockState stateIn, World worldIn, BlockPos pos, Random rand) {
|
2019-03-31 12:28:59 +02:00
|
|
|
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-10-20 22:30:49 +02:00
|
|
|
public AxisAlignedBB getBoundingBox(BlockState state, IBlockAccess source, BlockPos pos) {
|
2019-03-31 11:38:07 +02:00
|
|
|
return BOUND_BOX;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isFullCube(BlockState state) {
|
2019-03-31 11:38:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isOpaqueCube(BlockState state) {
|
2019-03-31 11:38:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isNormalCube(BlockState state, IBlockAccess world, BlockPos pos) {
|
2019-03-31 11:38:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, BlockState state, BlockPos pos, Direction face) {
|
2019-03-31 11:38:07 +02:00
|
|
|
return BlockFaceShape.UNDEFINED;
|
|
|
|
}
|
|
|
|
|
2019-03-19 17:21:06 +01:00
|
|
|
public static class ChunkLoadingCallback implements ForgeChunkManager.LoadingCallback {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void ticketsLoaded(List<Ticket> tickets, World world) {
|
|
|
|
for (Ticket ticket : tickets) {
|
2019-10-20 22:30:49 +02:00
|
|
|
CompoundNBT data = ticket.getModData();
|
2019-03-19 17:21:06 +01:00
|
|
|
BlockPos pos = BlockPos.fromLong(data.getLong("pos"));
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (!(tile instanceof TileEntityChunkLoader))
|
|
|
|
continue;
|
|
|
|
TileEntityChunkLoader loader = (TileEntityChunkLoader) tile;
|
|
|
|
loader.updateTicket(ticket);
|
|
|
|
loader.loadChunks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|