use of com.tntmodders.takumi.world.TakumiExplosion in project takumicraft by TNTModders.
the class TakumiEvents method onExplosion.
@SubscribeEvent
public void onExplosion(Detonate event) {
if (!event.getWorld().isRemote) {
event.getAffectedEntities().removeIf(entity -> entity instanceof EntityLivingBase && ((EntityLivingBase) entity).getActiveItemStack().getItem() == TakumiItemCore.TAKUMI_SHIELD);
if (event.getWorld().getBlockState(new BlockPos(event.getExplosion().getPosition())).getBlock() == TakumiBlockCore.ACID_BLOCK) {
IBlockState state = event.getWorld().getBlockState(new BlockPos(event.getExplosion().getPosition()));
int i = state.getValue(BlockTakumiAcid.META) + 1;
event.getAffectedBlocks().forEach(pos -> {
if (i < 16) {
for (EnumFacing facing : EnumFacing.values()) {
BlockPos blockPos = pos.offset(facing);
if (!event.getAffectedBlocks().contains(blockPos) && !event.getWorld().isAirBlock(blockPos) && event.getWorld().getBlockState(blockPos).getBlockHardness(event.getWorld(), blockPos) != -1 && event.getWorld().getBlockState(blockPos).getBlock() != TakumiBlockCore.ACID_BLOCK) {
event.getWorld().setBlockState(blockPos, TakumiBlockCore.ACID_BLOCK.getDefaultState().withProperty(BlockTakumiAcid.META, i));
}
}
}
event.getWorld().setBlockToAir(pos);
});
event.getAffectedBlocks().clear();
}
}
if (event.getExplosion() instanceof TakumiExplosion) {
if (((TakumiExplosion) event.getExplosion()).getExploder() instanceof AbstractEntityTakumiGrenade) {
AbstractEntityTakumiGrenade grenade = (AbstractEntityTakumiGrenade) ((TakumiExplosion) event.getExplosion()).getExploder();
if (grenade.getThrower() != null) {
event.getAffectedEntities().remove(grenade.getThrower());
}
}
if (((TakumiExplosion) event.getExplosion()).getExploder() instanceof EntityTakumiArrow) {
EntityTakumiArrow takumiArrow = (EntityTakumiArrow) ((TakumiExplosion) event.getExplosion()).getExploder();
if (takumiArrow.shootingEntity instanceof EntityStrayCreeper) {
PotionType type = PotionUtils.getPotionFromItem(((EntityLivingBase) takumiArrow.shootingEntity).getHeldItem(EnumHand.OFF_HAND));
for (Entity entity : event.getAffectedEntities()) {
if (entity instanceof EntityLivingBase && entity != takumiArrow.shootingEntity) {
PotionEffect effect = new PotionEffect(type.getEffects().get(0).getPotion(), 400);
((EntityLivingBase) entity).addPotionEffect(effect);
}
}
}
}
if (((TakumiExplosion) event.getExplosion()).getExploder() instanceof EntityTakumiPotion) {
for (Entity entity : event.getAffectedEntities()) {
if (entity instanceof EntityLivingBase) {
List<PotionEffect> effects = PotionUtils.getEffectsFromStack(((EntityPotion) ((TakumiExplosion) event.getExplosion()).getExploder()).getPotion());
for (PotionEffect effect : effects) {
((EntityLivingBase) entity).addPotionEffect(effect);
}
}
}
}
if (((TakumiExplosion) event.getExplosion()).getExploder() instanceof EntityTransHomingBomb) {
event.getAffectedEntities().forEach(entity -> {
if (entity instanceof EntityPlayer) {
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.LEVITATION, 150));
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(TakumiPotionCore.INVERSION, 150));
}
});
}
}
if (event.getExplosion().getExplosivePlacedBy() instanceof ITakumiEntity) {
boolean flg = ((ITakumiEntity) event.getExplosion().getExplosivePlacedBy()).takumiExplodeEvent(event);
if (!flg) {
event.setCanceled(true);
}
}
}
use of com.tntmodders.takumi.world.TakumiExplosion in project takumicraft by TNTModders.
the class TakumiUtils method takumiCreateExplosion.
public static void takumiCreateExplosion(World world, Entity entity, double x, double y, double z, float power, boolean fire, boolean destroy, double amp) {
boolean flg = world instanceof WorldServer;
TakumiExplosion explosion = new TakumiExplosion(world, entity, x, y, z, power, fire, destroy, amp);
if (ForgeEventFactory.onExplosionStart(world, explosion)) {
return;
}
explosion.doExplosionA();
explosion.doExplosionB(!flg);
if (flg) {
if (!fire) {
explosion.clearAffectedBlockPositions();
}
for (EntityPlayer entityplayer : world.playerEntities) {
if (entityplayer.getDistanceSq(x, y, z) < 4096.0D) {
((EntityPlayerMP) entityplayer).connection.sendPacket(new SPacketExplosion(x, y, z, power, explosion.getAffectedBlockPositions(), explosion.getPlayerKnockbackMap().get(entityplayer)));
}
}
}
}
use of com.tntmodders.takumi.world.TakumiExplosion in project takumicraft by TNTModders.
the class EntityLightCreeper method takumiExplodeEvent.
@Override
public boolean takumiExplodeEvent(Detonate event) {
for (Entity entity : event.getAffectedEntities()) {
if (entity instanceof EntityLivingBase) {
((EntityLivingBase) entity).addPotionEffect(new PotionEffect(MobEffects.GLOWING, 400, 0));
}
}
float power = this.getPowered() ? 6f : 3f;
if (event.getExplosion() instanceof TakumiExplosion) {
power = ((TakumiExplosion) event.getExplosion()).getSize();
}
if (power > 0.5) {
for (BlockPos pos : event.getAffectedBlocks()) {
if (!this.world.isRemote && this.world.getBlockState(pos).getBlock().getLightValue(this.world.getBlockState(pos)) > 0.5f && TakumiUtils.takumiGetBlockResistance(this, this.world.getBlockState(pos), pos) != -1) {
this.world.setBlockToAir(pos);
TakumiUtils.takumiCreateExplosion(this.world, this, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, power - 0.2f, false, true);
}
}
}
return true;
}
use of com.tntmodders.takumi.world.TakumiExplosion in project takumicraft by TNTModders.
the class EntityDestructionCreeper method takumiExplodeEvent.
@Override
public boolean takumiExplodeEvent(Detonate event) {
if (!this.world.isRemote) {
float power = this.getPowered() ? 8f : 4f;
if (event.getExplosion() instanceof TakumiExplosion) {
power = ((TakumiExplosion) event.getExplosion()).getSize();
}
if (power > 0.5) {
for (BlockPos pos : event.getAffectedBlocks()) {
if (!this.world.isRemote && this.world.getBlockState(pos).getBlock().hasTileEntity(this.world.getBlockState(pos)) && this.world.getBlockState(pos).getBlock().createTileEntity(this.world, this.world.getBlockState(pos)) instanceof IInventory && TakumiUtils.takumiGetBlockResistance(this, this.world.getBlockState(pos), pos) != -1) {
// this.world.setBlockToAir(pos);
TakumiUtils.takumiCreateExplosion(this.world, this, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, power - 0.15f, false, true);
}
}
}
Map<IBlockState, IRecipe> map = new HashMap<>();
Map<IBlockState, Integer> count = new HashMap<>();
for (BlockPos pos : event.getAffectedBlocks()) {
IBlockState state = this.world.getBlockState(pos);
if (state.getMaterial() != Material.AIR) {
ItemStack stack = state.getBlock().getPickBlock(state, null, this.world, pos, null);
boolean flg = false;
for (IRecipe recipe : Lists.newArrayList(CraftingManager.REGISTRY.iterator())) {
if (recipe.getRecipeOutput().getItem() == stack.getItem() && recipe.getRecipeOutput().getMetadata() == stack.getMetadata()) {
if (!map.containsValue(recipe)) {
map.put(state, recipe);
}
flg = true;
}
}
if (flg) {
if (count.containsKey(state)) {
count.replace(state, count.get(state) + 1);
} else {
count.put(state, 1);
}
}
}
this.world.setBlockToAir(pos);
}
if (!map.isEmpty()) {
for (Entry<IBlockState, IRecipe> entry : Lists.newArrayList(map.entrySet())) {
IRecipe recipe = entry.getValue();
int i = count.get(entry.getKey());
List<ItemStack> stackList = new ArrayList<>();
for (Ingredient ingredient : recipe.getIngredients()) {
for (ItemStack stack : ingredient.getMatchingStacks()) {
if (!stackList.contains(stack)) {
stackList.add(stack);
}
}
}
for (ItemStack stack : stackList) {
stack.setCount(i);
this.world.spawnEntity(new EntityItem(this.world, posX, posY, posZ, stack));
}
}
}
// event.getAffectedBlocks().clear();
event.getAffectedEntities().clear();
}
return true;
}
use of com.tntmodders.takumi.world.TakumiExplosion in project takumicraft by TNTModders.
the class EntityDirtCreeper method takumiExplodeEvent.
@Override
public boolean takumiExplodeEvent(Detonate event) {
float power = this.getPowered() ? 6f : 3f;
if (event.getExplosion() instanceof TakumiExplosion) {
power = ((TakumiExplosion) event.getExplosion()).getSize();
}
if (power > 0.1) {
for (BlockPos pos : event.getAffectedBlocks()) {
String s = this.world.getBlockState(pos).getBlock().getHarvestTool(this.world.getBlockState(pos));
if (!this.world.isRemote && s != null && s.equalsIgnoreCase("shovel") && TakumiUtils.takumiGetBlockResistance(this, this.world.getBlockState(pos), pos) != -1) {
this.world.setBlockToAir(pos);
TakumiUtils.takumiCreateExplosion(this.world, this, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, power - 0.2f, false, true);
}
}
}
return true;
}
Aggregations