2019-03-12 19:34:59 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.TileEntityProjectileGenerator;
|
2020-01-23 19:20:47 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.render.RenderProjectileGenerator;
|
2020-01-22 23:21:52 +01:00
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
2020-01-23 19:20:47 +01:00
|
|
|
import de.ellpeck.naturesaura.reg.ITESRProvider;
|
2019-03-12 19:34:59 +01:00
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
2020-01-23 19:20:47 +01:00
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
|
2019-03-12 19:34:59 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2019-03-31 23:53:53 +02:00
|
|
|
import net.minecraft.util.SoundCategory;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.util.SoundEvents;
|
2020-01-23 19:20:47 +01:00
|
|
|
import net.minecraft.util.Tuple;
|
2019-03-12 19:34:59 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
2020-01-22 23:21:52 +01:00
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
2020-01-23 19:20:47 +01:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
2019-03-12 19:34:59 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.ProjectileImpactEvent;
|
2019-10-20 22:30:49 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
2019-03-12 19:34:59 +01:00
|
|
|
|
2020-01-23 19:20:47 +01:00
|
|
|
public class BlockProjectileGenerator extends BlockContainerImpl implements ITESRProvider {
|
2019-03-12 19:34:59 +01:00
|
|
|
public BlockProjectileGenerator() {
|
2020-01-22 01:32:26 +01:00
|
|
|
super("projectile_generator", TileEntityProjectileGenerator::new, ModBlocks.prop(Material.ROCK).hardnessAndResistance(2.5F).sound(SoundType.STONE));
|
2019-03-12 19:34:59 +01:00
|
|
|
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onProjectileImpact(ProjectileImpactEvent event) {
|
|
|
|
Entity entity = event.getEntity();
|
|
|
|
if (entity.world.isRemote)
|
|
|
|
return;
|
2020-01-22 23:21:52 +01:00
|
|
|
RayTraceResult ray = event.getRayTraceResult();
|
|
|
|
if (!(ray instanceof BlockRayTraceResult))
|
|
|
|
return;
|
|
|
|
BlockRayTraceResult blockRay = (BlockRayTraceResult) ray;
|
|
|
|
BlockPos pos = blockRay.getPos();
|
2019-03-12 19:34:59 +01:00
|
|
|
if (pos == null)
|
|
|
|
return;
|
|
|
|
TileEntity tile = entity.world.getTileEntity(pos);
|
|
|
|
if (!(tile instanceof TileEntityProjectileGenerator))
|
|
|
|
return;
|
|
|
|
TileEntityProjectileGenerator generator = (TileEntityProjectileGenerator) tile;
|
2020-01-22 23:21:52 +01:00
|
|
|
if (generator.nextSide != blockRay.getFace())
|
2019-03-12 19:34:59 +01:00
|
|
|
return;
|
2020-01-24 17:05:41 +01:00
|
|
|
Integer amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(entity.getType());
|
2019-04-06 17:16:42 +02:00
|
|
|
if (amount == null || amount <= 0)
|
2019-03-12 19:34:59 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
BlockPos spot = IAuraChunk.getLowestSpot(entity.world, pos, 35, pos);
|
|
|
|
IAuraChunk.getAuraChunk(entity.world, spot).storeAura(spot, amount);
|
|
|
|
|
2020-01-22 23:21:52 +01:00
|
|
|
PacketHandler.sendToAllAround(entity.world, pos, 32,
|
|
|
|
new PacketParticles((float) entity.posX, (float) entity.posY, (float) entity.posZ, 26, pos.getX(), pos.getY(), pos.getZ()));
|
2020-01-21 21:04:44 +01:00
|
|
|
entity.world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ENDER_EYE_LAUNCH, SoundCategory.BLOCKS, 0.8F, 1F);
|
2019-03-31 23:53:53 +02:00
|
|
|
|
2019-03-12 19:34:59 +01:00
|
|
|
generator.nextSide = generator.nextSide.rotateY();
|
|
|
|
generator.sendToClients();
|
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
entity.remove();
|
2019-03-12 19:34:59 +01:00
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
2019-03-31 23:53:53 +02:00
|
|
|
|
2020-01-23 19:20:47 +01:00
|
|
|
@Override
|
2019-10-20 22:30:49 +02:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
|
|
|
public Tuple<Class, TileEntityRenderer> getTESR() {
|
2019-03-31 23:53:53 +02:00
|
|
|
return new Tuple<>(TileEntityProjectileGenerator.class, new RenderProjectileGenerator());
|
2020-01-23 19:20:47 +01:00
|
|
|
}
|
2019-03-12 19:34:59 +01:00
|
|
|
}
|