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;
|
|
|
|
import net.minecraft.block.SoundType;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
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;
|
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;
|
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;
|
2020-01-21 21:04:44 +01:00
|
|
|
import net.minecraftforge.registries.ForgeRegistries;
|
2019-03-12 19:34:59 +01:00
|
|
|
|
2020-01-21 21:04:44 +01:00
|
|
|
public class BlockProjectileGenerator extends BlockContainerImpl/* implements ITESRProvider*/ {
|
2019-03-12 19:34:59 +01:00
|
|
|
public BlockProjectileGenerator() {
|
2019-11-04 19:08:49 +01:00
|
|
|
super("projectile_generator", TileEntityProjectileGenerator.class, "projectile_generator", 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-21 21:04:44 +01:00
|
|
|
BlockRayTraceResult ray = (BlockRayTraceResult) event.getRayTraceResult();
|
|
|
|
BlockPos pos = ray.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-21 21:04:44 +01:00
|
|
|
if (generator.nextSide != ray.getFace())
|
2019-03-12 19:34:59 +01:00
|
|
|
return;
|
2020-01-21 21:04:44 +01:00
|
|
|
ResourceLocation name = ForgeRegistries.ENTITIES.getKey(entity.getType());
|
2019-04-06 17:16:42 +02:00
|
|
|
Integer amount = NaturesAuraAPI.PROJECTILE_GENERATIONS.get(name);
|
|
|
|
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-21 21:04:44 +01:00
|
|
|
// TODO particles
|
|
|
|
/* PacketHandler.sendToAllAround(entity.world, pos, 32,
|
|
|
|
new PacketParticles((float) entity.posX, (float) entity.posY, (float) entity.posZ, 26, pos.getX(), pos.getY(), pos.getZ()));*/
|
|
|
|
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-21 21:04:44 +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-21 21:04:44 +01:00
|
|
|
}*/
|
2019-03-12 19:34:59 +01:00
|
|
|
}
|