Выдача эффекта на площадь взрыва.

Версия Minecraft
1.7.10
128
12
Всем привет! Думаю многие видели мою тему со спавном взрыва при ломании меча. 
Теперь у меня возник вопрос, а как-же на эту площадь (25.0F) добавить эффект иссушения всем ближайшим игрокам?
Код:
package com.example.examplemod;

import java.util.List;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.divinerpg.utils.TooltipLocalizer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;

public class ebonsword<PlayerDestroyItem> extends ItemSword{
 private static final String world = null;
 private float witherSeconds;
 private float regenerationSeconds;
 private float zalupaseconds;
 private float huiseconds;
 private float p_70060_1_;
 private float p_70060_2_;
 private float p_70060_3_;
 private double p_72876_2_;
 private double p_72876_4_;
 private double p_72876_6_;
 private float p_72876_8_;
 private boolean p_72876_9_;
 
 
 public ebonsword() {
 super(Mybestmod.MADINIT);
 this.setCreativeTab(CreativeTabs.tabCombat);
 this.setTextureName("blockj:RSW");
 this.witherSeconds = 5;
 this.regenerationSeconds = 5;
    this.huiseconds = 5;
    MinecraftForge.EVENT_BUS.register(this);
 }

 

@Override
 public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
 if(entity instanceof EntityLivingBase)((EntityLivingBase)player).addPotionEffect(new PotionEffect(Potion.regeneration.id, (int)(regenerationSeconds*20), 8)); 
 if(entity instanceof EntityLivingBase)((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.wither.id, (int)(witherSeconds*5), 120)); 
 if(entity instanceof EntityLivingBase)((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.hunger.id, (int)(witherSeconds*5), 120)); 
 if(entity instanceof EntityLivingBase)((EntityLivingBase)player).addPotionEffect(new PotionEffect(Potion.field_76443_y.id, 20, 4));
 
 return false; 
 }


 protected void addAdditionalInformation(List list) {
 list.add(TooltipLocalizer.regen(this.regenerationSeconds));
 list.add(TooltipLocalizer.wither(this.witherSeconds)); 
 list.add(TooltipLocalizer.hunger(this.huiseconds)); 
 list.add(TooltipLocalizer.satur(this.zalupaseconds));
}

 @SubscribeEvent
 public void onPlayerDestroyItem(PlayerDestroyItemEvent e) {
 if (e.original.getItem() == Mybestmod.ebonsword) 
 e.entityPlayer.worldObj.createExplosion(
 e.entityPlayer, e.entityPlayer.posX, e.entityPlayer.posY,
 e.entityPlayer.posZ, 25.0F, true);
 
 }


}
 
Решение
Код:
protected void addEffect(World world, int x, int y, int z, int radius, int duration) {
        List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));

        for (EntityPlayer player : players) {
            player.addPotionEffect(new PotionEffect(Potion.wither.id, duration));
        }
    }


x y z - центр взрыва
radius - радиус в котором хотите чтоб наложился эффект
duration - время эффекта
1,111
47
420
Могу ошибаться но вроде у World есть функция типа findEntitiesInAABB в нее ты суеш AxisAlignedBoundingBox центр которого будет в точке взрыва а радиус равен радиусу взрыва. Он тебе выдаст массив сущностей которые на тот момент будут внутри этой зоны. И for-each тебе в помощь. Я бы написал код но я щас не дома.
 
128
12
JustAGod написал(а):
Могу ошибаться но вроде у World есть функция типа findEntitiesInAABB в нее ты суеш AxisAlignedBoundingBox центр которого будет в точке взрыва а радиус равен радиусу взрыва. Он тебе выдаст массив сущностей которые на тот момент будут внутри этой зоны. И for-each тебе в помощь. Я бы написал код но я щас не дома.

Ничего не понял :/
 
1,111
47
420
Код:
protected void addEffect(World world, int x, int y, int z, int radius, int duration) {
        List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));

        for (EntityPlayer player : players) {
            player.addPotionEffect(new PotionEffect(Potion.wither.id, duration));
        }
    }


x y z - центр взрыва
radius - радиус в котором хотите чтоб наложился эффект
duration - время эффекта
 
128
12
JustAGod написал(а):
Код:
protected void addEffect(World world, int x, int y, int z, int radius, int duration) {
        List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));

        for (EntityPlayer player : players) {
            player.addPotionEffect(new PotionEffect(Potion.wither.id, duration));
        }
    }


x y z - центр взрыва
radius - радиус в котором хотите чтоб наложился эффект
duration - время эффекта


Ничего не выходит.
 
586
32
136
STFlowerG написал(а):
JustAGod написал(а):
Код:
protected void addEffect(World world, int x, int y, int z, int radius, int duration) {
        List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));

        for (EntityPlayer player : players) {
            player.addPotionEffect(new PotionEffect(Potion.wither.id, duration));
        }
    }


x y z - центр взрыва
radius - радиус в котором хотите чтоб наложился эффект
duration - время эффекта


Ничего не выходит.


Всё прекрасно работает...


STFlowerG написал(а):
JustAGod написал(а):
Код:
protected void addEffect(World world, int x, int y, int z, int radius, int duration) {
        List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));

        for (EntityPlayer player : players) {
            player.addPotionEffect(new PotionEffect(Potion.wither.id, duration));
        }
    }


x y z - центр взрыва
radius - радиус в котором хотите чтоб наложился эффект
duration - время эффекта


Ничего не выходит.


Всё прекрасно работает...
 
128
12
Thunder написал(а):
А где ты метод то этот вызываешь если у тебя не работает?

Я без понятия как изменять это 
Код:
package com.example.examplemod;

import java.util.List;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.divinerpg.utils.TooltipLocalizer;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;

public class ebonsword<PlayerDestroyItem> extends ItemSword{
 private static final String world = null;
 private float witherSeconds;
 private float regenerationSeconds;
 private float zalupaseconds;
 private float huiseconds;
 private float p_70060_1_;
 private float p_70060_2_;
 private float p_70060_3_;
 private double p_72876_2_;
 private double p_72876_4_;
 private double p_72876_6_;
 private float p_72876_8_;
 private boolean p_72876_9_;
 
 
 public ebonsword() {
 super(Mybestmod.MADINIT);
 this.setCreativeTab(CreativeTabs.tabCombat);
 this.setTextureName("blockj:RSW");
 this.witherSeconds = 5;
 this.regenerationSeconds = 5;
    this.huiseconds = 5;
    MinecraftForge.EVENT_BUS.register(this);
 }

 

@Override
 public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
 if(entity instanceof EntityLivingBase)((EntityLivingBase)player).addPotionEffect(new PotionEffect(Potion.regeneration.id, (int)(regenerationSeconds*20), 8)); 
 if(entity instanceof EntityLivingBase)((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.wither.id, (int)(witherSeconds*5), 120)); 
 if(entity instanceof EntityLivingBase)((EntityLivingBase)entity).addPotionEffect(new PotionEffect(Potion.hunger.id, (int)(witherSeconds*5), 120)); 
 if(entity instanceof EntityLivingBase)((EntityLivingBase)player).addPotionEffect(new PotionEffect(Potion.field_76443_y.id, 20, 4));
 
 return false; 
 }


 protected void addAdditionalInformation(List list) {
 list.add(TooltipLocalizer.regen(this.regenerationSeconds));
 list.add(TooltipLocalizer.wither(this.witherSeconds)); 
 list.add(TooltipLocalizer.hunger(this.huiseconds)); 
 list.add(TooltipLocalizer.satur(this.zalupaseconds));
}

 @SubscribeEvent
 public void onPlayerDestroyItem(PlayerDestroyItemEvent e) {
 if (e.original.getItem() == Mybestmod.ebonsword) 
 e.entityPlayer.worldObj.createExplosion(
 e.entityPlayer, e.entityPlayer.posX, e.entityPlayer.posY,
 e.entityPlayer.posZ, 25.0F, true);
       
 }
 protected void addEffect(World world, int x, int y, int z, int radius, int duration) {
       List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));

       for (EntityPlayer player : players) {
           player.addPotionEffect(new PotionEffect(Potion.wither.id, duration));
       }
   }
}
 
1,057
50
234
Код:
@SubscribeEvent
public void onPlayerDestroyItem(PlayerDestroyItemEvent e) {
    if (e.original.getItem() == Mybestmod.ebonsword)
    { 
        e.entityPlayer.worldObj.createExplosion(e.entityPlayer, e.entityPlayer.posX, e.entityPlayer.posY,e.entityPlayer.posZ, 25.0F, true);
        this.addEffect(e.entityPlayer.worldObj, e.entityPlayer.posX, e.entityPlayer.posY,
e.entityPlayer.posZ, 15, 2500);
     }
}
 
128
12
BlesseNtumble написал(а):
Код:
@SubscribeEvent
public void onPlayerDestroyItem(PlayerDestroyItemEvent e) {
    if (e.original.getItem() == Mybestmod.ebonsword)
    { 
        e.entityPlayer.worldObj.createExplosion(e.entityPlayer, e.entityPlayer.posX, e.entityPlayer.posY,e.entityPlayer.posZ, 25.0F, true);
        this.addEffect(e.entityPlayer.worldObj, e.entityPlayer.posX, e.entityPlayer.posY,
e.entityPlayer.posZ, 15, 2500);
     }
}
Всё конечно нормально, но-но-но, а где собственно указан эффект?
 
1,111
47
420
JustAGod написал(а):
Код:
protected void addEffect(World world, int x, int y, int z, int radius, int duration) {
        List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));

        for (EntityPlayer player : players) {
            player.addPotionEffect(new PotionEffect(Potion.wither.id, duration));
        }
    }


x y z - центр взрыва
radius - радиус в котором хотите чтоб наложился эффект
duration - время эффекта


Не тупи! Там где Potion.wither, Potion.wither - эффект иссушения. Хош другое, замени wither на что то другое.
 
128
12
JustAGod написал(а):
JustAGod написал(а):
Код:
protected void addEffect(World world, int x, int y, int z, int radius, int duration) {
        List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(x - radius, y - radius, z - radius, x + radius, y + radius, z + radius));

        for (EntityPlayer player : players) {
            player.addPotionEffect(new PotionEffect(Potion.wither.id, duration));
        }
    }


x y z - центр взрыва
radius - радиус в котором хотите чтоб наложился эффект
duration - время эффекта


Не тупи! Там где Potion.wither, Potion.wither - эффект иссушения. Хош другое, замени wither на что то другое.



я про radius, duration, x y z
 
1,111
47
420
Ой да ну шо ты пристал? Написал на коленке.

Конечно, если делать по уму, то следовало бы искать синусами и косинусами либо отлавливать ивент LivingHurtEvent и там уже фильтровать их расстояние от предыдущего взрыва, но мы оба понимаем, что кода уже будет дофига и будет он не таким простым.


Или вообще хук закинуть
 
128
12
MJaroslav написал(а):
А разве в кубаче взрывы кубические? Ваш метод по поиску сущностей ищет в кубе с гранью 'radius*2'.
А, чё я туплю, совсем забыл что value в radius и duration ставится, как *value
 
1,111
47
420
Oldestkon написал(а):
Какие синусы и косинусы? лол?
Entity#getDistance(x, y, z) < R

Лол. Ступил=)


STFlowerG написал(а):
MJaroslav написал(а):
А разве в кубаче взрывы кубические? Ваш метод по поиску сущностей ищет в кубе с гранью 'radius*2'.
А, чё я туплю, совсем забыл что value в radius и duration ставится, как *value

Это щас типо как указатель в C? Или я в Java не шарю?
 
Сверху