use of net.minecraft.entity.item.EntityXPOrb in project MorePlanets by SteveKunG.
the class EntityMiniVeinFloater method onDeathUpdate.
@Override
protected void onDeathUpdate() {
++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));
}
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, 6);
}
if (chest != null) {
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, 5));
}
}
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 EntityCheeseCubeEyeBoss 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 = 150;
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));
}
}
this.move(MoverType.SELF, 0.0D, -0.10000000149011612D, 0.0D);
if (this.deathTicks == 200 && !this.world.isRemote) {
i = 150;
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, 5);
}
if (chest != null) {
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, 5));
}
}
this.entityDropItem(new ItemStack(ChalosItems.CHALOS_DUNGEON_KEY, 1, 0), 0.5F);
super.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 SpongeCommon by SpongePowered.
the class MixinNetHandlerPlayServer method processUseEntity.
/**
* @author blood - April 5th, 2016
*
* @reason Due to all the changes we now do for this packet, it is much easier
* to read it all with an overwrite. Information detailing on why each change
* was made can be found in comments below.
*
* @param packetIn The entity use packet
*/
@Overwrite
public void processUseEntity(CPacketUseEntity packetIn) {
// All packets received by server are handled first on the Netty Thread
if (!SpongeImpl.getServer().isCallingFromMinecraftThread()) {
if (packetIn.getAction() == CPacketUseEntity.Action.INTERACT) {
// when INTERACT_AT does not return a successful result.
return;
} else {
// queue packet for main thread
PacketThreadUtil.checkThreadAndEnqueue(packetIn, (NetHandlerPlayServer) (Object) this, this.player.getServerWorld());
return;
}
}
// Sponge end
WorldServer worldserver = this.serverController.getWorld(this.player.dimension);
Entity entity = packetIn.getEntityFromWorld(worldserver);
this.player.markPlayerActive();
if (entity != null) {
boolean flag = this.player.canEntityBeSeen(entity);
// 6 blocks
double d0 = 36.0D;
if (!flag) {
// 1.5 blocks
d0 = 9.0D;
}
if (this.player.getDistanceSq(entity) < d0) {
if (packetIn.getAction() == CPacketUseEntity.Action.INTERACT_AT) {
// Sponge start - Fire interact events
EnumHand hand = packetIn.getHand();
ItemStack itemstack = hand != null ? this.player.getHeldItem(hand) : ItemStack.EMPTY;
Sponge.getCauseStackManager().addContext(EventContextKeys.USED_ITEM, ItemStackUtil.snapshotOf(itemstack));
SpongeCommonEventFactory.lastSecondaryPacketTick = this.serverController.getTickCounter();
// Is interaction allowed with item in hand
if (SpongeCommonEventFactory.callInteractItemEventSecondary(this.player, itemstack, hand, VecHelper.toVector3d(packetIn.getHitVec()), entity).isCancelled() || SpongeCommonEventFactory.callInteractEntityEventSecondary(this.player, entity, hand, VecHelper.toVector3d(entity.getPositionVector().add(packetIn.getHitVec()))).isCancelled()) {
// Restore held item in hand
int index = ((IMixinInventoryPlayer) this.player.inventory).getHeldItemIndex(hand);
Slot slot = this.player.openContainer.getSlotFromInventory(this.player.inventory, index);
sendPacket(new SPacketSetSlot(this.player.openContainer.windowId, slot.slotNumber, itemstack));
// which means that we need to force an update
if (itemstack.getItem() == Items.LEAD) {
// Detach entity again
sendPacket(new SPacketEntityAttach(entity, null));
} else {
// Other cases may involve a specific DataParameter of the entity
// We fix the client state by marking it as dirty so it will be updated on the client the next tick
DataParameter<?> parameter = findModifiedEntityInteractDataParameter(itemstack, entity);
if (parameter != null) {
entity.getDataManager().setDirty(parameter);
}
}
return;
}
// If INTERACT_AT is not successful, run the INTERACT logic
if (entity.applyPlayerInteraction(this.player, packetIn.getHitVec(), hand) != EnumActionResult.SUCCESS) {
this.player.interactOn(entity, hand);
}
// Sponge end
} else if (packetIn.getAction() == CPacketUseEntity.Action.ATTACK) {
// Sponge start - Call interact event
// Will be null in the packet during ATTACK
EnumHand hand = EnumHand.MAIN_HAND;
ItemStack itemstack = this.player.getHeldItem(hand);
SpongeCommonEventFactory.lastPrimaryPacketTick = this.serverController.getTickCounter();
Vector3d hitVec = null;
if (packetIn.getHitVec() == null) {
final RayTraceResult result = SpongeImplHooks.rayTraceEyes(player, SpongeImplHooks.getBlockReachDistance(player));
hitVec = result == null ? null : VecHelper.toVector3d(result.hitVec);
}
if (SpongeCommonEventFactory.callInteractItemEventPrimary(this.player, itemstack, hand, hitVec, entity).isCancelled()) {
((IMixinEntityPlayerMP) this.player).restorePacketItem(hand);
return;
}
if (entity instanceof EntityItem || entity instanceof EntityXPOrb || entity instanceof EntityArrow || entity == this.player) {
this.disconnect(new TextComponentTranslation("multiplayer.disconnect.invalid_entity_attacked"));
this.serverController.logWarning("Player " + this.player.getName() + " tried to attack an invalid entity");
return;
}
// Sponge start
if (entity instanceof Player && !((World) this.player.world).getProperties().isPVPEnabled()) {
// PVP is disabled, ignore
return;
}
if (SpongeCommonEventFactory.callInteractEntityEventPrimary(this.player, entity, hand, hitVec).isCancelled()) {
((IMixinEntityPlayerMP) this.player).restorePacketItem(hand);
return;
}
// Sponge end
this.player.attackTargetEntityWithCurrentItem(entity);
}
}
}
}
use of net.minecraft.entity.item.EntityXPOrb in project SpongeCommon by SpongePowered.
the class InteractionPacketState method unwind.
@Override
public void unwind(BasicPacketContext phaseContext) {
final EntityPlayerMP player = phaseContext.getPacketPlayer();
final ItemStack usedStack = phaseContext.getItemUsed();
final ItemStackSnapshot usedSnapshot = ItemStackUtil.snapshotOf(usedStack);
final Entity spongePlayer = EntityUtil.fromNative(player);
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(spongePlayer);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
final boolean hasBlocks = !phaseContext.getCapturedBlockSupplier().isEmpty();
final List<BlockSnapshot> capturedBlcoks = phaseContext.getCapturedBlocks();
@Nullable final BlockSnapshot firstBlockChange = hasBlocks ? capturedBlcoks.get(0) : null;
if (hasBlocks) {
if (!TrackingUtil.processBlockCaptures(capturedBlcoks, this, phaseContext)) {
// Stop entities like XP from being spawned
return;
}
} else {
phaseContext.getBlockItemDropSupplier().acceptIfNotEmpty(map -> {
if (ShouldFire.DROP_ITEM_EVENT_DESTRUCT) {
for (BlockSnapshot blockChange : capturedBlcoks) {
final Location<World> location = blockChange.getLocation().get();
final Vector3d position = location.getPosition();
final BlockPos blockPos = VecHelper.toBlockPos(position);
final Collection<EntityItem> entityItems = map.get(blockPos);
if (!entityItems.isEmpty()) {
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()) {
processSpawnedEntities(player, event);
}
}
}
} else {
for (BlockSnapshot blockChange : capturedBlcoks) {
final Location<World> location = blockChange.getLocation().get();
final Vector3d position = location.getPosition();
final BlockPos blockPos = VecHelper.toBlockPos(position);
final Collection<EntityItem> entityItems = map.get(blockPos);
if (!entityItems.isEmpty()) {
processEntities(player, (Collection<Entity>) (Collection<?>) entityItems);
}
}
}
});
}
phaseContext.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
final ArrayList<Entity> entities = new ArrayList<>();
for (EntityItem item : items) {
entities.add(EntityUtil.fromNative(item));
}
final DropItemEvent.Dispense dispense = SpongeEventFactory.createDropItemEventDispense(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(dispense);
if (!dispense.isCancelled()) {
processSpawnedEntities(player, dispense);
}
});
phaseContext.getCapturedEntityDropSupplier().acceptIfNotEmpty(map -> {
if (map.isEmpty()) {
return;
}
final PrettyPrinter printer = new PrettyPrinter(80);
printer.add("Processing Interaction").centre().hr();
printer.add("The item stacks captured are: ");
for (Map.Entry<UUID, Collection<ItemDropData>> entry : map.asMap().entrySet()) {
printer.add(" - Entity with UUID: %s", entry.getKey());
for (ItemDropData stack : entry.getValue()) {
printer.add(" - %s", stack);
}
}
printer.trace(System.err);
});
phaseContext.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
final List<Entity> projectiles = new ArrayList<>(entities.size());
final List<Entity> spawnEggs = new ArrayList<>(entities.size());
final List<Entity> xpOrbs = new ArrayList<>(entities.size());
final List<Entity> normalPlacement = new ArrayList<>(entities.size());
final List<Entity> items = new ArrayList<>(entities.size());
for (Entity entity : entities) {
if (entity instanceof Projectile || entity instanceof EntityThrowable) {
projectiles.add(entity);
} else if (usedSnapshot.getType() == ItemTypes.SPAWN_EGG) {
spawnEggs.add(entity);
} else if (entity instanceof EntityItem) {
items.add(entity);
} else if (entity instanceof EntityXPOrb) {
xpOrbs.add(entity);
} else {
normalPlacement.add(entity);
}
}
if (!projectiles.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (CauseStackManager.StackFrame frame2 = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
Sponge.getCauseStackManager().pushCause(usedSnapshot);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), projectiles);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, projectiles);
}
}
if (!spawnEggs.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (CauseStackManager.StackFrame frame2 = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.PROJECTILE);
Sponge.getCauseStackManager().pushCause(usedSnapshot);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), spawnEggs);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, spawnEggs);
}
}
if (!items.isEmpty()) {
if (ShouldFire.DROP_ITEM_EVENT_DISPENSE) {
final DropItemEvent.Dispense dispense = SpongeEventFactory.createDropItemEventDispense(Sponge.getCauseStackManager().getCurrentCause(), items);
if (!SpongeImpl.postEvent(dispense)) {
processSpawnedEntities(player, dispense);
}
} else {
processEntities(player, items);
}
}
if (!xpOrbs.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (final CauseStackManager.StackFrame stackFrame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (firstBlockChange != null) {
stackFrame.pushCause(firstBlockChange);
}
stackFrame.addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.EXPERIENCE);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), xpOrbs);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, xpOrbs);
}
}
if (!normalPlacement.isEmpty()) {
if (ShouldFire.SPAWN_ENTITY_EVENT) {
try (final CauseStackManager.StackFrame stackFrame = Sponge.getCauseStackManager().pushCauseFrame()) {
if (firstBlockChange != null) {
stackFrame.pushCause(firstBlockChange);
}
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), normalPlacement);
if (!SpongeImpl.postEvent(event)) {
processSpawnedEntities(player, event);
}
}
} else {
processEntities(player, normalPlacement);
}
}
});
final IMixinContainer mixinContainer = ContainerUtil.toMixin(player.openContainer);
mixinContainer.setCaptureInventory(false);
mixinContainer.getCapturedTransactions().clear();
}
}
use of net.minecraft.entity.item.EntityXPOrb in project SpongeCommon by SpongePowered.
the class BlockTickPhaseState method spawnEntityOrCapture.
@Override
public boolean spawnEntityOrCapture(BlockTickContext context, Entity entity, int chunkX, int chunkZ) {
final LocatableBlock locatableBlock = getLocatableBlockSourceFromContext(context);
final Optional<User> owner = context.getOwner();
final Optional<User> notifier = context.getNotifier();
final User entityCreator = notifier.orElseGet(() -> owner.orElse(null));
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(locatableBlock);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.EXPERIENCE);
if (notifier.isPresent()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier.get());
}
if (owner.isPresent()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, owner.get());
}
if (entity instanceof EntityXPOrb) {
final ArrayList<Entity> entities = new ArrayList<>(1);
entities.add(entity);
final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(event);
if (!event.isCancelled()) {
for (Entity anEntity : event.getEntities()) {
if (entityCreator != null) {
EntityUtil.toMixin(anEntity).setCreator(entityCreator.getUniqueId());
}
EntityUtil.getMixinWorld(entity).forceSpawnEntity(anEntity);
}
return true;
}
return false;
}
final List<Entity> nonExpEntities = new ArrayList<>(1);
nonExpEntities.add(entity);
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.BLOCK_SPAWNING);
final SpawnEntityEvent spawnEntityEvent = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), nonExpEntities);
SpongeImpl.postEvent(spawnEntityEvent);
if (!spawnEntityEvent.isCancelled()) {
for (Entity anEntity : spawnEntityEvent.getEntities()) {
if (entityCreator != null) {
EntityUtil.toMixin(anEntity).setCreator(entityCreator.getUniqueId());
}
EntityUtil.getMixinWorld(entity).forceSpawnEntity(anEntity);
}
return true;
}
}
return false;
}
Aggregations