Search in sources :

Example 6 with EntityThrowable

use of net.minecraft.entity.projectile.EntityThrowable in project SpongeCommon by SpongePowered.

the class PhaseTracker method spawnEntity.

/**
 * This is the replacement of {@link WorldServer#spawnEntity(net.minecraft.entity.Entity)}
 * where it captures into phases. The causes and relations are processed by the phases.
 *
 * The difference between {@link #spawnEntityWithCause(World, Entity)} is that it bypasses
 * any phases and directly throws a spawn entity event.
 *
 * @param world The world
 * @param entity The entity
 * @return True if the entity spawn was successful
 */
public boolean spawnEntity(World world, Entity entity) {
    checkNotNull(entity, "Entity cannot be null!");
    // Sponge Start - handle construction phases
    if (((IMixinEntity) entity).isInConstructPhase()) {
        ((IMixinEntity) entity).firePostConstructEvents();
    }
    final net.minecraft.entity.Entity minecraftEntity = EntityUtil.toNative(entity);
    final WorldServer minecraftWorld = (WorldServer) world;
    final IMixinWorldServer mixinWorldServer = (IMixinWorldServer) minecraftWorld;
    final PhaseData phaseData = this.stack.peek();
    final IPhaseState<?> phaseState = phaseData.state;
    final PhaseContext<?> context = phaseData.context;
    final boolean isForced = minecraftEntity.forceSpawn || minecraftEntity instanceof EntityPlayer;
    // Certain phases disallow entity spawns (such as block restoration)
    if (!isForced && !phaseState.allowEntitySpawns()) {
        return false;
    }
    // Sponge End - continue with vanilla mechanics
    final int chunkX = MathHelper.floor(minecraftEntity.posX / 16.0D);
    final int chunkZ = MathHelper.floor(minecraftEntity.posZ / 16.0D);
    if (!isForced && !mixinWorldServer.isMinecraftChunkLoaded(chunkX, chunkZ, true)) {
        return false;
    }
    if (minecraftEntity instanceof EntityPlayer) {
        EntityPlayer entityplayer = (EntityPlayer) minecraftEntity;
        minecraftWorld.playerEntities.add(entityplayer);
        minecraftWorld.updateAllPlayersSleepingFlag();
        SpongeImplHooks.firePlayerJoinSpawnEvent((EntityPlayerMP) entityplayer);
    } else {
        // Sponge start - check for vanilla owner
        if (minecraftEntity instanceof IEntityOwnable) {
            IEntityOwnable ownable = (IEntityOwnable) entity;
            net.minecraft.entity.Entity owner = ownable.getOwner();
            if (owner != null && owner instanceof EntityPlayer) {
                context.owner = (User) owner;
                entity.setCreator(ownable.getOwnerId());
            }
        } else if (minecraftEntity instanceof EntityThrowable) {
            EntityThrowable throwable = (EntityThrowable) minecraftEntity;
            EntityLivingBase thrower = throwable.getThrower();
            if (thrower != null) {
                User user = null;
                if (!(thrower instanceof EntityPlayer)) {
                    user = ((IMixinEntity) thrower).getCreatorUser().orElse(null);
                } else {
                    user = (User) thrower;
                }
                if (user != null) {
                    context.owner = user;
                    entity.setCreator(user.getUniqueId());
                }
            }
        }
    // Sponge end
    }
    // capture all entities until the phase is marked for completion.
    if (!isForced) {
        try {
            return ((IPhaseState) phaseState).spawnEntityOrCapture(context, entity, chunkX, chunkZ);
        } catch (Exception | NoClassDefFoundError e) {
            // Just in case something really happened, we should print a nice exception for people to
            // paste us
            this.printExceptionSpawningEntity(context, e);
            return false;
        }
    }
    // Sponge end - continue on with the checks.
    minecraftWorld.getChunkFromChunkCoords(chunkX, chunkZ).addEntity(minecraftEntity);
    minecraftWorld.loadedEntityList.add(minecraftEntity);
    // Sponge - Cannot add onEntityAdded to the access transformer because forge makes it public
    mixinWorldServer.onSpongeEntityAdded(minecraftEntity);
    return true;
}
Also used : EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) User(org.spongepowered.api.entity.living.player.User) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) ReportedException(net.minecraft.util.ReportedException) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IEntityOwnable(net.minecraft.entity.IEntityOwnable)

Example 7 with EntityThrowable

use of net.minecraft.entity.projectile.EntityThrowable in project SpongeCommon by SpongePowered.

the class EntityActivationRange method initializeEntityActivationState.

/**
 * These entities are excluded from Activation range checks.
 *
 * @param entity Entity to check
 * @return boolean If it should always tick.
 */
public static boolean initializeEntityActivationState(Entity entity) {
    if (((IMixinWorld) entity.world).isFake()) {
        return true;
    }
    // types that should always be active
    if (entity instanceof EntityPlayer && !SpongeImplHooks.isFakePlayer(entity) || entity instanceof EntityThrowable || entity instanceof EntityDragon || entity instanceof MultiPartEntityPart || entity instanceof EntityWither || entity instanceof EntityFireball || entity instanceof EntityWeatherEffect || entity instanceof EntityTNTPrimed || entity instanceof EntityEnderCrystal || entity instanceof EntityFireworkRocket || // Always tick falling blocks
    entity instanceof EntityFallingBlock) {
        return true;
    }
    EntityActivationRangeCategory config = ((IMixinWorldServer) entity.world).getActiveConfig().getConfig().getEntityActivationRange();
    EntityType type = ((org.spongepowered.api.entity.Entity) entity).getType();
    IModData_Activation spongeEntity = (IModData_Activation) entity;
    if (type == EntityTypes.UNKNOWN || !(type instanceof SpongeEntityType)) {
        return false;
    }
    final SpongeEntityType spongeType = (SpongeEntityType) type;
    final byte activationType = spongeEntity.getActivationType();
    if (!spongeType.isActivationRangeInitialized()) {
        addEntityToConfig(entity.world, spongeType, activationType);
        spongeType.setActivationRangeInitialized(true);
    }
    EntityActivationModCategory entityMod = config.getModList().get(spongeType.getModId().toLowerCase());
    int defaultActivationRange = config.getDefaultRanges().get(activationTypeMappings.get(activationType));
    if (entityMod == null) {
        // use default activation range
        spongeEntity.setActivationRange(defaultActivationRange);
        if (defaultActivationRange <= 0) {
            return true;
        }
        return false;
    } else if (!entityMod.isEnabled()) {
        spongeEntity.setActivationRange(defaultActivationRange);
        return true;
    }
    Integer defaultModActivationRange = entityMod.getDefaultRanges().get(activationTypeMappings.get(activationType));
    Integer entityActivationRange = entityMod.getEntityList().get(type.getName().toLowerCase());
    if (defaultModActivationRange != null && entityActivationRange == null) {
        spongeEntity.setActivationRange(defaultModActivationRange);
        if (defaultModActivationRange <= 0) {
            return true;
        }
        return false;
    } else if (entityActivationRange != null) {
        spongeEntity.setActivationRange(entityActivationRange);
        if (entityActivationRange <= 0) {
            return true;
        }
    }
    return false;
}
Also used : EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) EntityDragon(net.minecraft.entity.boss.EntityDragon) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) Entity(net.minecraft.entity.Entity) IModData_Activation(org.spongepowered.common.mixin.plugin.entityactivation.interfaces.IModData_Activation) EntityFallingBlock(net.minecraft.entity.item.EntityFallingBlock) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) EntityWeatherEffect(net.minecraft.entity.effect.EntityWeatherEffect) EntityEnderCrystal(net.minecraft.entity.item.EntityEnderCrystal) MultiPartEntityPart(net.minecraft.entity.MultiPartEntityPart) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityType(org.spongepowered.api.entity.EntityType) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) EntityFireworkRocket(net.minecraft.entity.item.EntityFireworkRocket) SpongeEntityType(org.spongepowered.common.entity.SpongeEntityType) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityWither(net.minecraft.entity.boss.EntityWither) EntityActivationRangeCategory(org.spongepowered.common.config.category.EntityActivationRangeCategory) EntityActivationModCategory(org.spongepowered.common.config.category.EntityActivationModCategory) EntityFireball(net.minecraft.entity.projectile.EntityFireball)

Example 8 with EntityThrowable

use of net.minecraft.entity.projectile.EntityThrowable in project ClaySoldiersMod by SanAndreasP.

the class EntityClayMan method throwSomethingAtEnemy.

public void throwSomethingAtEnemy(EntityLivingBase entity, Class<? extends ISoldierProjectile<? extends EntityThrowable>> projClass, boolean homing) {
    double d = entity.posX - posX;
    double d1 = entity.posZ - posZ;
    try {
        ISoldierProjectile<? extends EntityThrowable> projectile = projClass.getConstructor(World.class, EntityLivingBase.class).newInstance(this.worldObj, this);
        projectile.initProjectile(entity, homing, this.getClayTeam());
        EntityThrowable throwable = projectile.getProjectileEntity();
        throwable.posY += 0.1D;
        double d2 = (entity.posY + entity.getEyeHeight()) - 0.10000000298023224D - throwable.posY;
        float f1 = MathHelper.sqrt_double(d * d + d1 * d1) * 0.2F;
        this.worldObj.spawnEntityInWorld(throwable);
        throwable.setThrowableHeading(d, d2 + f1, d1, 0.6F, 12.0F);
        this.attackTime = 30;
        this.hasAttacked = true;
    } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        FMLLog.log(ClaySoldiersMod.MOD_LOG, Level.ERROR, "%1$s cannot be instantiated! %1$s is not thrown to target!", projClass.getName());
        e.printStackTrace();
    }
}
Also used : EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) EntityLivingBase(net.minecraft.entity.EntityLivingBase) World(net.minecraft.world.World) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 9 with EntityThrowable

use of net.minecraft.entity.projectile.EntityThrowable in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class ItemChakram method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    Entity entity;
    switch(weapon) {
        case Strings.Ashes:
            entity = new EntityAshes(world, player);
            break;
        case Strings.BlazeofGlory:
            entity = new EntityBlazeofGlory(world, player);
            break;
        case Strings.EternalFlames:
            entity = new EntityEternalFlames(world, player);
            break;
        case Strings.Ifrit:
            entity = new EntityIfrit(world, player);
            break;
        case Strings.Prometheus:
            entity = new EntityPrometheus(world, player);
            break;
        case Strings.Prominence:
            entity = new EntityProminence(world, player);
            break;
        case Strings.MoulinRouge:
            entity = new EntityMoulinRouge(world, player);
            break;
        case Strings.FerrisWheel:
            entity = new EntityFerrisWheels(world, player);
            break;
        case Strings.Combustion:
            entity = new EntityCombustion(world, player);
            break;
        case Strings.Burnout:
            entity = new EntityBurnout(world, player);
            break;
        case Strings.OmegaTrinity:
            entity = new EntityOmegaTrinity(world, player);
            break;
        case Strings.Doldrums:
            entity = new EntityDoledrum(world, player);
            break;
        case Strings.Outbreak:
            entity = new EntityOutbreak(world, player);
            break;
        case Strings.Inferno:
            entity = new EntityInferno(world, player);
            break;
        case Strings.SizzlingEdge:
            entity = new EntitySizzlingEdge(world, player);
            break;
        case Strings.DoubleEdge:
            entity = new EntityDoubleEdge(world, player);
            break;
        default:
            entity = new EntityEternalFlames(world, player);
            break;
    }
    if (!player.getCapability(ModCapabilities.PLAYER_STATS, null).getRecharge()) {
        if (!player.isSneaking()) {
            world.playSound(player.posX, player.posY, player.posZ, SoundEvents.ENTITY_GHAST_SHOOT, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F), false);
            world.spawnEntity(entity);
            ((EntityThrowable) entity).setHeadingFromThrower(player, player.rotationPitch, player.rotationYaw, 0, 1f, 1);
            if (!player.getCapability(ModCapabilities.CHEAT_MODE, null).getCheatMode())
                player.getCapability(ModCapabilities.PLAYER_STATS, null).remMP(7);
            player.swingArm(hand);
        }
        return ActionResult.newResult(EnumActionResult.SUCCESS, player.getHeldItemMainhand());
    }
    return ActionResult.newResult(EnumActionResult.FAIL, player.getHeldItemMainhand());
}
Also used : EntityDoledrum(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityDoledrum) Entity(net.minecraft.entity.Entity) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) EntityOmegaTrinity(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityOmegaTrinity) EntityAshes(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityAshes) EntityMoulinRouge(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityMoulinRouge) EntitySizzlingEdge(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntitySizzlingEdge) EntityEternalFlames(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityEternalFlames) EntityIfrit(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityIfrit) EntityBurnout(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityBurnout) EntityCombustion(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityCombustion) EntityFerrisWheels(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityFerrisWheels) EntityInferno(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityInferno) EntityDoubleEdge(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityDoubleEdge) EntityOutbreak(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityOutbreak) EntityBlazeofGlory(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityBlazeofGlory) EntityPrometheus(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityPrometheus) EntityProminence(uk.co.wehavecookies56.kk.common.entity.projectiles.chakrams.EntityProminence)

Aggregations

EntityThrowable (net.minecraft.entity.projectile.EntityThrowable)9 Entity (net.minecraft.entity.Entity)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 EntityArrow (net.minecraft.entity.projectile.EntityArrow)2 World (net.minecraft.world.World)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 Entity (org.spongepowered.api.entity.Entity)2 EntityType (org.spongepowered.api.entity.EntityType)2 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 ItemLivingArmour (WayofTime.bloodmagic.item.armour.ItemLivingArmour)1 LivingArmour (WayofTime.bloodmagic.livingArmour.LivingArmour)1 LivingArmourUpgrade (WayofTime.bloodmagic.livingArmour.LivingArmourUpgrade)1 LivingArmourUpgradeStormTrooper (WayofTime.bloodmagic.livingArmour.downgrade.LivingArmourUpgradeStormTrooper)1 Vector3d (com.flowpowered.math.vector.Vector3d)1 RGBAValues (de.sanandrew.core.manpack.util.helpers.SAPUtils.RGBAValues)1 EntityClayMan (de.sanandrew.mods.claysoldiers.entity.EntityClayMan)1 ArrayList (java.util.ArrayList)1