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));
}
}
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));
}
}
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;
}
}
}
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;
}
}
}
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);
}
Aggregations