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;
|
2019-03-31 23:53:53 +02:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.render.RenderProjectileGenerator;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketHandler;
|
|
|
|
import de.ellpeck.naturesaura.packet.PacketParticles;
|
|
|
|
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;
|
2019-03-31 23:53:53 +02:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
2019-03-12 19:34:59 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.entity.EntityList;
|
2019-03-31 23:53:53 +02:00
|
|
|
import net.minecraft.init.SoundEvents;
|
2019-03-12 19:34:59 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
2019-03-31 23:53:53 +02:00
|
|
|
import net.minecraft.util.SoundCategory;
|
|
|
|
import net.minecraft.util.Tuple;
|
2019-03-12 19:34:59 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.RayTraceResult;
|
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.entity.ProjectileImpactEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
2019-03-31 23:53:53 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
2019-03-12 19:34:59 +01:00
|
|
|
|
2019-03-31 23:53:53 +02:00
|
|
|
public class BlockProjectileGenerator extends BlockContainerImpl implements ITESRProvider {
|
2019-03-12 19:34:59 +01:00
|
|
|
public BlockProjectileGenerator() {
|
|
|
|
super(Material.ROCK, "projectile_generator", TileEntityProjectileGenerator.class, "projectile_generator");
|
|
|
|
this.setSoundType(SoundType.STONE);
|
|
|
|
this.setHardness(2.5F);
|
|
|
|
|
|
|
|
MinecraftForge.EVENT_BUS.register(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void onProjectileImpact(ProjectileImpactEvent event) {
|
|
|
|
Entity entity = event.getEntity();
|
|
|
|
if (entity.world.isRemote)
|
|
|
|
return;
|
|
|
|
RayTraceResult ray = event.getRayTraceResult();
|
|
|
|
BlockPos pos = ray.getBlockPos();
|
|
|
|
if (pos == null)
|
|
|
|
return;
|
|
|
|
TileEntity tile = entity.world.getTileEntity(pos);
|
|
|
|
if (!(tile instanceof TileEntityProjectileGenerator))
|
|
|
|
return;
|
|
|
|
TileEntityProjectileGenerator generator = (TileEntityProjectileGenerator) tile;
|
|
|
|
if (generator.nextSide != ray.sideHit)
|
|
|
|
return;
|
|
|
|
ResourceLocation name = EntityList.getKey(entity);
|
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);
|
|
|
|
|
2019-03-31 23:53:53 +02: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()));
|
|
|
|
entity.world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_ENDEREYE_LAUNCH, SoundCategory.BLOCKS, 0.8F, 1F);
|
|
|
|
|
2019-03-12 19:34:59 +01:00
|
|
|
generator.nextSide = generator.nextSide.rotateY();
|
|
|
|
generator.sendToClients();
|
|
|
|
|
|
|
|
entity.setDead();
|
|
|
|
event.setCanceled(true);
|
|
|
|
}
|
2019-03-31 23:53:53 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isFullCube(IBlockState state) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOpaqueCube(IBlockState state) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public Tuple<Class, TileEntitySpecialRenderer> getTESR() {
|
|
|
|
return new Tuple<>(TileEntityProjectileGenerator.class, new RenderProjectileGenerator());
|
|
|
|
}
|
2019-03-12 19:34:59 +01:00
|
|
|
}
|