Search in sources :

Example 1 with TakumiExplosion

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);
        }
    }
}
Also used : ITakumiEntity(com.tntmodders.takumi.entity.ITakumiEntity) Entity(net.minecraft.entity.Entity) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) ITakumiEntity(com.tntmodders.takumi.entity.ITakumiEntity) TakumiExplosion(com.tntmodders.takumi.world.TakumiExplosion) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) PotionType(net.minecraft.potion.PotionType) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with TakumiExplosion

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)));
            }
        }
    }
}
Also used : TakumiExplosion(com.tntmodders.takumi.world.TakumiExplosion) SPacketExplosion(net.minecraft.network.play.server.SPacketExplosion) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer)

Example 3 with TakumiExplosion

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;
}
Also used : TakumiExplosion(com.tntmodders.takumi.world.TakumiExplosion) Entity(net.minecraft.entity.Entity) PotionEffect(net.minecraft.potion.PotionEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with TakumiExplosion

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;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IBlockState(net.minecraft.block.state.IBlockState) IRecipe(net.minecraft.item.crafting.IRecipe) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TakumiExplosion(com.tntmodders.takumi.world.TakumiExplosion) Ingredient(net.minecraft.item.crafting.Ingredient) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 5 with TakumiExplosion

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;
}
Also used : TakumiExplosion(com.tntmodders.takumi.world.TakumiExplosion) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

TakumiExplosion (com.tntmodders.takumi.world.TakumiExplosion)9 BlockPos (net.minecraft.util.math.BlockPos)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 IBlockState (net.minecraft.block.state.IBlockState)2 Entity (net.minecraft.entity.Entity)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 IInventory (net.minecraft.inventory.IInventory)2 PotionEffect (net.minecraft.potion.PotionEffect)2 ITakumiEntity (com.tntmodders.takumi.entity.ITakumiEntity)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EntityItem (net.minecraft.entity.item.EntityItem)1 ItemStack (net.minecraft.item.ItemStack)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 Ingredient (net.minecraft.item.crafting.Ingredient)1 SPacketExplosion (net.minecraft.network.play.server.SPacketExplosion)1 PotionType (net.minecraft.potion.PotionType)1 WorldServer (net.minecraft.world.WorldServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1