2018-11-24 15:06:18 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.Helper;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
2019-01-28 15:43:21 +01:00
|
|
|
import de.ellpeck.naturesaura.api.render.IVisualizable;
|
2018-11-24 15:06:18 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntitySpawnLamp;
|
2018-11-27 21:38:42 +01:00
|
|
|
import net.minecraft.block.SoundType;
|
2018-11-24 15:06:18 +01:00
|
|
|
import net.minecraft.block.material.Material;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraft.entity.MobEntity;
|
2019-01-27 13:57:34 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2018-11-24 15:06:18 +01:00
|
|
|
import net.minecraft.util.BlockRenderLayer;
|
|
|
|
import net.minecraft.util.math.AxisAlignedBB;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2019-01-27 13:57:34 +01:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2019-11-04 19:08:49 +01:00
|
|
|
import net.minecraft.world.IWorld;
|
2018-11-24 15:06:18 +01:00
|
|
|
import net.minecraft.world.World;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2018-11-24 15:06:18 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.eventbus.api.Event;
|
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2018-11-24 15:06:18 +01:00
|
|
|
|
2019-01-28 15:43:21 +01:00
|
|
|
public class BlockSpawnLamp extends BlockContainerImpl implements IVisualizable {
|
2018-11-24 15:06:18 +01:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
// TODO bounding box
|
2018-11-24 15:06:18 +01:00
|
|
|
private static final AxisAlignedBB AABB = new AxisAlignedBB(4 / 16F, 0F, 4 / 16F, 12 / 16F, 13 / 16F, 12 / 16F);
|
|
|
|
|
|
|
|
public BlockSpawnLamp() {
|
2020-01-21 21:04:44 +01:00
|
|
|
super("spawn_lamp", TileEntitySpawnLamp.class, "spawn_lamp", ModBlocks.prop(Material.IRON).hardnessAndResistance(3F).lightValue(15).sound(SoundType.METAL));
|
2018-11-24 15:06:18 +01:00
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onSpawn(LivingSpawnEvent.CheckSpawn event) {
|
|
|
|
if (event.getSpawner() != null)
|
|
|
|
return;
|
2019-11-04 19:08:49 +01:00
|
|
|
IWorld world = event.getWorld();
|
2018-11-24 15:06:18 +01:00
|
|
|
BlockPos pos = new BlockPos(event.getX(), event.getY(), event.getZ());
|
|
|
|
Helper.getTileEntitiesInArea(world, pos, 48, tile -> {
|
|
|
|
if (!(tile instanceof TileEntitySpawnLamp))
|
|
|
|
return false;
|
|
|
|
TileEntitySpawnLamp lamp = (TileEntitySpawnLamp) tile;
|
|
|
|
int range = lamp.getRadius();
|
|
|
|
if (range <= 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
BlockPos lampPos = lamp.getPos();
|
2019-01-27 13:57:34 +01:00
|
|
|
if (!new AxisAlignedBB(lampPos).grow(range).contains(new Vec3d(pos)))
|
2018-11-24 15:06:18 +01:00
|
|
|
return false;
|
|
|
|
|
2019-10-20 22:30:49 +02:00
|
|
|
MobEntity entity = (MobEntity) event.getEntityLiving();
|
2020-01-21 21:04:44 +01:00
|
|
|
if (entity.canSpawn(world, event.getSpawnReason()) && entity.isNotColliding(world)) {
|
2018-11-24 15:06:18 +01:00
|
|
|
BlockPos spot = IAuraChunk.getHighestSpot(world, lampPos, 32, lampPos);
|
2019-01-29 11:46:38 +01:00
|
|
|
IAuraChunk.getAuraChunk(world, spot).drainAura(spot, 200);
|
2018-11-24 15:06:18 +01:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
// TODO particles
|
|
|
|
/*PacketHandler.sendToAllAround(world, lampPos, 32,
|
|
|
|
new PacketParticles(lampPos.getX(), lampPos.getY(), lampPos.getZ(), 15));*/
|
2018-11-24 15:06:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
event.setResult(Event.Result.DENY);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
/* @Override
|
|
|
|
public AxisAlignedBB getBoundingBox(BlockState state, IWorld source, BlockPos pos) {
|
2018-11-24 15:06:18 +01:00
|
|
|
return AABB;
|
2020-01-21 21:04:44 +01:00
|
|
|
}*/
|
2018-11-24 15:06:18 +01:00
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2018-11-24 15:06:18 +01:00
|
|
|
public BlockRenderLayer getRenderLayer() {
|
|
|
|
return BlockRenderLayer.CUTOUT;
|
|
|
|
}
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
/* @Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isFullCube(BlockState state) {
|
2018-11-24 15:06:18 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isOpaqueCube(BlockState state) {
|
2018-11-24 15:06:18 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isNormalCube(BlockState state, IBlockAccess world, BlockPos pos) {
|
2018-11-24 15:06:18 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public boolean isSideSolid(BlockState baseState, IBlockAccess world, BlockPos pos, Direction side) {
|
2018-11-24 15:06:18 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
public BlockFaceShape getBlockFaceShape(IBlockAccess worldIn, BlockState state, BlockPos pos, Direction face) {
|
2018-11-24 15:06:18 +01:00
|
|
|
return BlockFaceShape.UNDEFINED;
|
2020-01-21 21:04:44 +01:00
|
|
|
}*/
|
2019-01-27 13:57:34 +01:00
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-01-27 13:57:34 +01:00
|
|
|
public AxisAlignedBB getVisualizationBounds(World world, BlockPos pos) {
|
|
|
|
TileEntity tile = world.getTileEntity(pos);
|
|
|
|
if (tile instanceof TileEntitySpawnLamp) {
|
|
|
|
int radius = ((TileEntitySpawnLamp) tile).getRadius();
|
|
|
|
if (radius > 0)
|
|
|
|
return new AxisAlignedBB(pos).grow(radius);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2019-01-27 13:57:34 +01:00
|
|
|
public int getVisualizationColor(World world, BlockPos pos) {
|
|
|
|
return 0x825ee5;
|
|
|
|
}
|
2018-11-24 15:06:18 +01:00
|
|
|
}
|