Search in sources :

Example 31 with EntityXPOrb

use of net.minecraft.entity.item.EntityXPOrb in project SpongeCommon by SpongePowered.

the class EntityTickPhaseState method unwind.

@SuppressWarnings("unchecked")
@Override
public void unwind(EntityTickContext phaseContext) {
    final Entity tickingEntity = phaseContext.getSource(Entity.class).orElseThrow(TrackingUtil.throwWithContext("Not ticking on an Entity!", phaseContext));
    final Optional<User> creator = phaseContext.getOwner();
    final Optional<User> notifier = phaseContext.getNotifier();
    final User entityCreator = notifier.orElseGet(() -> creator.orElse(null));
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(tickingEntity);
        phaseContext.addNotifierAndOwnerToCauseStack();
        phaseContext.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
            final List<Entity> experience = new ArrayList<Entity>(entities.size());
            final List<Entity> nonExp = new ArrayList<Entity>(entities.size());
            final List<Entity> breeding = new ArrayList<Entity>(entities.size());
            final List<Entity> projectile = new ArrayList<Entity>(entities.size());
            for (Entity entity : entities) {
                if (entity instanceof EntityXPOrb) {
                    experience.add(entity);
                } else if (tickingEntity instanceof Ageable && tickingEntity.getClass() == entity.getClass()) {
                    breeding.add(entity);
                } else if (entity instanceof Projectile) {
                    projectile.add(entity);
                } else {
                    nonExp.add(entity);
                }
            }
            if (!experience.isEmpty()) {
                Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.EXPERIENCE);
                if (EntityUtil.isEntityDead(tickingEntity)) {
                    if (tickingEntity instanceof EntityLivingBase) {
                        CombatEntry entry = ((EntityLivingBase) tickingEntity).getCombatTracker().getBestCombatEntry();
                        if (entry != null) {
                            if (entry.damageSrc != null) {
                                Sponge.getCauseStackManager().addContext(EventContextKeys.LAST_DAMAGE_SOURCE, (DamageSource) entry.damageSrc);
                            }
                        }
                    }
                }
                final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), experience);
                if (!SpongeImpl.postEvent(event)) {
                    for (Entity entity : event.getEntities()) {
                        if (entityCreator != null) {
                            EntityUtil.toMixin(entity).setCreator(entityCreator.getUniqueId());
                        }
                        EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                    }
                }
                Sponge.getCauseStackManager().removeContext(EventContextKeys.LAST_DAMAGE_SOURCE);
            }
            if (!breeding.isEmpty()) {
                Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.BREEDING);
                if (tickingEntity instanceof EntityAnimal) {
                    final EntityPlayer playerInLove = ((EntityAnimal) tickingEntity).getLoveCause();
                    if (playerInLove != null) {
                        Sponge.getCauseStackManager().addContext(EventContextKeys.PLAYER, (Player) playerInLove);
                    }
                }
                SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), breeding);
                if (!SpongeImpl.postEvent(event)) {
                    for (Entity entity : event.getEntities()) {
                        if (entityCreator != null) {
                            EntityUtil.toMixin(entity).setCreator(entityCreator.getUniqueId());
                        }
                        EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                    }
                }
                Sponge.getCauseStackManager().removeContext(EventContextKeys.PLAYER);
            }
            if (!projectile.isEmpty()) {
                Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
                final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), projectile);
                SpongeImpl.postEvent(event);
                if (!event.isCancelled()) {
                    for (Entity entity : event.getEntities()) {
                        if (entityCreator != null) {
                            entity.setCreator(entityCreator.getUniqueId());
                        }
                        EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                    }
                }
            }
            Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PASSIVE);
            final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), nonExp);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                for (Entity entity : event.getEntities()) {
                    if (entityCreator != null) {
                        entity.setCreator(entityCreator.getUniqueId());
                    }
                    EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                }
            }
        });
        phaseContext.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(entities -> {
            final ArrayList<Entity> capturedEntities = new ArrayList<>();
            for (EntityItem entity : entities) {
                capturedEntities.add(EntityUtil.fromNative(entity));
            }
            Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
            final DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), capturedEntities);
            SpongeImpl.postEvent(event);
            if (!event.isCancelled()) {
                for (Entity entity : event.getEntities()) {
                    if (entityCreator != null) {
                        EntityUtil.toMixin(entity).setCreator(entityCreator.getUniqueId());
                    }
                    EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                }
            }
        });
        phaseContext.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blockSnapshots -> TrackingUtil.processBlockCaptures(blockSnapshots, this, phaseContext));
        phaseContext.getBlockItemDropSupplier().acceptIfNotEmpty(map -> {
            final List<BlockSnapshot> capturedBlocks = phaseContext.getCapturedBlocks();
            for (BlockSnapshot snapshot : capturedBlocks) {
                final BlockPos blockPos = ((IMixinLocation) (Object) snapshot.getLocation().get()).getBlockPos();
                final Collection<EntityItem> entityItems = map.get(blockPos);
                if (!entityItems.isEmpty()) {
                    Sponge.getCauseStackManager().pushCause(snapshot);
                    Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
                    final List<Entity> items = entityItems.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
                    final DropItemEvent.Destruct event = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), items);
                    SpongeImpl.postEvent(event);
                    if (!event.isCancelled()) {
                        for (Entity entity : event.getEntities()) {
                            creator.ifPresent(user -> entity.setCreator(user.getUniqueId()));
                            EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
                        }
                    }
                    Sponge.getCauseStackManager().popCause();
                }
            }
        });
        phaseContext.getCapturedItemStackSupplier().acceptAndClearIfNotEmpty(drops -> {
            final List<EntityItem> items = drops.stream().map(drop -> drop.create(EntityUtil.getMinecraftWorld(tickingEntity))).collect(Collectors.toList());
            Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
            final List<Entity> entities = (List<Entity>) (List<?>) items;
            if (!entities.isEmpty()) {
                DropItemEvent.Custom event = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
                SpongeImpl.postEvent(event);
                if (!event.isCancelled()) {
                    for (Entity droppedItem : event.getEntities()) {
                        EntityUtil.getMixinWorld(droppedItem).forceSpawnEntity(droppedItem);
                    }
                }
            }
        });
        this.fireMovementEvents(EntityUtil.toNative(tickingEntity));
    }
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) EntityItemFrame(net.minecraft.entity.item.EntityItemFrame) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ExplosionContext(org.spongepowered.common.event.tracking.phase.general.ExplosionContext) Vector3d(com.flowpowered.math.vector.Vector3d) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) ArrayList(java.util.ArrayList) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb) CombatEntry(net.minecraft.util.CombatEntry) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) Ageable(org.spongepowered.api.entity.living.Ageable) EntityHanging(net.minecraft.entity.EntityHanging) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Transaction(org.spongepowered.api.data.Transaction) Nullable(javax.annotation.Nullable) EntityItem(net.minecraft.entity.item.EntityItem) User(org.spongepowered.api.entity.living.player.User) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) BlockPos(net.minecraft.util.math.BlockPos) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) IProjectile(net.minecraft.entity.IProjectile) InternalSpawnTypes(org.spongepowered.common.registry.type.event.InternalSpawnTypes) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) BlockChange(org.spongepowered.common.world.BlockChange) EntityUtil(org.spongepowered.common.entity.EntityUtil) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) List(java.util.List) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Transform(org.spongepowered.api.entity.Transform) World(org.spongepowered.api.world.World) VecHelper(org.spongepowered.common.util.VecHelper) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) Projectile(org.spongepowered.api.entity.projectile.Projectile) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) MoveEntityEvent(org.spongepowered.api.event.entity.MoveEntityEvent) Entity(org.spongepowered.api.entity.Entity) User(org.spongepowered.api.entity.living.player.User) ArrayList(java.util.ArrayList) CombatEntry(net.minecraft.util.CombatEntry) Ageable(org.spongepowered.api.entity.living.Ageable) CauseStackManager(org.spongepowered.api.event.CauseStackManager) BlockPos(net.minecraft.util.math.BlockPos) ArrayList(java.util.ArrayList) List(java.util.List) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) EntityItem(net.minecraft.entity.item.EntityItem) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) IProjectile(net.minecraft.entity.IProjectile) Projectile(org.spongepowered.api.entity.projectile.Projectile) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 32 with EntityXPOrb

use of net.minecraft.entity.item.EntityXPOrb in project MorePlanets by SteveKunG.

the class EntityNibiruVillager method useRecipe.

@Override
public void useRecipe(MerchantRecipe recipe) {
    recipe.incrementToolUses();
    this.livingSoundTime = -this.getTalkInterval();
    this.playSound(SoundEvents.ENTITY_VILLAGER_YES, this.getSoundVolume(), this.getSoundPitch());
    int i = 3 + this.rand.nextInt(4);
    if (recipe.getToolUses() == 1 || this.rand.nextInt(5) == 0) {
        this.timeUntilReset = 40;
        this.needsInitilization = true;
        this.isWillingToMate = true;
        if (this.buyingPlayer != null) {
            this.lastBuyingPlayer = this.buyingPlayer.getUniqueID();
        } else {
            this.lastBuyingPlayer = null;
        }
        i += 5;
    }
    if (recipe.getItemToBuy().getItem() == Items.EMERALD) {
        this.wealth += recipe.getItemToBuy().getCount();
    }
    if (recipe.getRewardsExp()) {
        this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY + 0.5D, this.posZ, i));
    }
}
Also used : EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 33 with EntityXPOrb

use of net.minecraft.entity.item.EntityXPOrb in project MorePlanets by SteveKunG.

the class EntityVeinFloater method onDeathUpdate.

@Override
protected void onDeathUpdate() {
    this.world.playEvent(1010, this.getPosition(), 0);
    ++this.deathTicks;
    if (this.deathTicks >= 180 && this.deathTicks <= 200) {
        float f = (this.rand.nextFloat() - 0.5F) * 5.5F;
        float f1 = (this.rand.nextFloat() - 0.5F) * 28.0F;
        float f2 = (this.rand.nextFloat() - 0.5F) * 5.5F;
        this.world.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.posX + f, this.posY + 2.0D + f1, this.posZ + f2, 0.0D, 0.0D, 0.0D);
    }
    int i;
    int j;
    if (!this.world.isRemote) {
        if (this.deathTicks >= 180 && this.deathTicks % 5 == 0) {
            GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_PLAY_SOUND_EXPLODE, GCCoreUtil.getDimensionID(this.world), new Object[] {}), new TargetPoint(GCCoreUtil.getDimensionID(this.world), this.posX, this.posY, this.posZ, 40.0D));
        }
        if (this.deathTicks > 150 && this.deathTicks % 5 == 0) {
            i = 200;
            while (i > 0) {
                j = EntityXPOrb.getXPSplit(i);
                i -= j;
                this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY, this.posZ, j));
            }
        }
        if (this.deathTicks == 40) {
            GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_PLAY_SOUND_BOSS_DEATH, GCCoreUtil.getDimensionID(this.world), new Object[] { this.getSoundPitch() - 0.1F }), new TargetPoint(GCCoreUtil.getDimensionID(this.world), this.posX, this.posY, this.posZ, 40.0D));
        }
    }
    if (this.deathTicks == 200 && !this.world.isRemote) {
        i = 200;
        while (i > 0) {
            j = EntityXPOrb.getXPSplit(i);
            i -= j;
            this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY, this.posZ, j));
        }
        this.entityDropItem(new ItemStack(NibiruItems.NIBIRU_DUNGEON_KEY, 1, this.rand.nextBoolean() ? 1 : 2), 0.5F);
        this.setDead();
        if (this.spawner != null) {
            this.spawner.isBossDefeated = true;
            this.spawner.boss = null;
            this.spawner.spawned = false;
        }
    }
}
Also used : PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 34 with EntityXPOrb

use of net.minecraft.entity.item.EntityXPOrb in project MorePlanets by SteveKunG.

the class EntityInfectedCrystallizeSlimeBoss method onDeathUpdate.

@Override
protected void onDeathUpdate() {
    ++this.deathTicks;
    if (this.deathTicks >= 180 && this.deathTicks <= 200) {
        float f = (this.rand.nextFloat() - 0.5F) * 1.5F;
        float f1 = (this.rand.nextFloat() - 0.5F) * 2.0F;
        float f2 = (this.rand.nextFloat() - 0.5F) * 1.5F;
        this.world.spawnParticle(EnumParticleTypes.EXPLOSION_HUGE, this.posX + f, this.posY + 2.0D + f1, this.posZ + f2, 0.0D, 0.0D, 0.0D);
    }
    int i;
    int j;
    if (!this.world.isRemote) {
        if (this.deathTicks >= 180 && this.deathTicks % 5 == 0) {
            GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_PLAY_SOUND_EXPLODE, GCCoreUtil.getDimensionID(this.world), new Object[] {}), new TargetPoint(GCCoreUtil.getDimensionID(this.world), this.posX, this.posY, this.posZ, 40.0D));
        }
        if (this.deathTicks > 150 && this.deathTicks % 5 == 0) {
            i = 120;
            while (i > 0) {
                j = EntityXPOrb.getXPSplit(i);
                i -= j;
                this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY, this.posZ, j));
            }
        }
        if (this.deathTicks == 40) {
            GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_PLAY_SOUND_BOSS_DEATH, GCCoreUtil.getDimensionID(this.world), new Object[] { this.getSoundPitch() - 0.1F }), new TargetPoint(GCCoreUtil.getDimensionID(this.world), this.posX, this.posY, this.posZ, 40.0D));
        }
    }
    if (this.deathTicks == 200 && !this.world.isRemote) {
        i = 120;
        while (i > 0) {
            j = EntityXPOrb.getXPSplit(i);
            i -= j;
            this.world.spawnEntity(new EntityXPOrb(this.world, this.posX, this.posY, this.posZ, j));
        }
        TileEntityTreasureChestMP chest = null;
        if (this.spawner != null && this.spawner.getChestPos() != null) {
            TileEntity chestTest = this.world.getTileEntity(this.spawner.getChestPos());
            if (chestTest != null && chestTest instanceof TileEntityTreasureChestMP) {
                chest = (TileEntityTreasureChestMP) chestTest;
            }
        }
        if (chest == null) {
            chest = TileEntityTreasureChestMP.findClosest(this, 4);
        } else {
            double dist = this.getDistanceSq(chest.getPos().getX() + 0.5, chest.getPos().getY() + 0.5, chest.getPos().getZ() + 0.5);
            if (dist < 1000 * 1000) {
                if (!chest.locked) {
                    chest.locked = true;
                }
                int slot = this.rand.nextInt(chest.getSizeInventory());
                chest.setLootTable(MPLootTables.COMMON_SPACE_DUNGEON, this.rand.nextLong());
                chest.setInventorySlotContents(slot, MPLootTables.getTieredKey(this.rand, 4));
            }
        }
        this.entityDropItem(new ItemStack(DionaItems.DIONA_DUNGEON_KEY, 1, 0), 0.5F);
        this.setDead();
        if (this.spawner != null) {
            this.spawner.isBossDefeated = true;
            this.spawner.boss = null;
            this.spawner.spawned = false;
        }
    }
}
Also used : TileEntityTreasureChestMP(stevekung.mods.moreplanets.util.tileentity.TileEntityTreasureChestMP) TileEntity(net.minecraft.tileentity.TileEntity) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) ItemStack(net.minecraft.item.ItemStack) TargetPoint(net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Example 35 with EntityXPOrb

use of net.minecraft.entity.item.EntityXPOrb in project Bewitchment by Um-Mitternacht.

the class RitualFlames method smeltAndSpawn.

private void smeltAndSpawn(EntityItem e) {
    ItemStack copy = e.getItem().copy();
    ItemStack is = copy.splitStack(1);
    if (rng.nextDouble() < 0.7d) {
        ItemStack result = FurnaceRecipes.instance().getSmeltingResult(is).copy();
        e.getEntityWorld().spawnEntity(new EntityItem(e.getEntityWorld(), e.posX, e.posY, e.posZ, result));
    } else {
        e.getEntityWorld().spawnEntity(new EntityXPOrb(e.getEntityWorld(), e.posX, e.posY, e.posZ, 2));
    }
    e.setItem(copy);
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) EntityXPOrb(net.minecraft.entity.item.EntityXPOrb)

Aggregations

EntityXPOrb (net.minecraft.entity.item.EntityXPOrb)50 EntityItem (net.minecraft.entity.item.EntityItem)17 ItemStack (net.minecraft.item.ItemStack)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)12 TileEntity (net.minecraft.tileentity.TileEntity)11 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)9 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)8 ArrayList (java.util.ArrayList)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 BlockPos (net.minecraft.util.math.BlockPos)5 Entity (org.spongepowered.api.entity.Entity)5 Entity (net.minecraft.entity.Entity)4 User (org.spongepowered.api.entity.living.player.User)4 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)4 Vector3d (com.flowpowered.math.vector.Vector3d)3 Player (org.spongepowered.api.entity.living.player.Player)3 Projectile (org.spongepowered.api.entity.projectile.Projectile)3 CauseStackManager (org.spongepowered.api.event.CauseStackManager)3 GDEvents (androsa.gaiadimension.registry.GDEvents)2 Collection (java.util.Collection)2