Search in sources :

Example 26 with PhaseData

use of org.spongepowered.common.event.tracking.PhaseData in project SpongeCommon by SpongePowered.

the class MixinWorldServer method updateBlocks.

/**
 * @author blood - July 1st, 2016
 * @author gabizou - July 1st, 2016 - Update to 1.10 and cause tracking
 *
 * @reason Added chunk and block tick optimizations, timings, cause tracking, and pre-construction events.
 */
@SuppressWarnings("unchecked")
@Override
@Overwrite
protected void updateBlocks() {
    this.playerCheckLight();
    if (this.worldInfo.getTerrainType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
        Iterator<net.minecraft.world.chunk.Chunk> iterator1 = this.playerChunkMap.getChunkIterator();
        while (iterator1.hasNext()) {
            iterator1.next().onTick(false);
        }
        // Sponge: Add return
        return;
    }
    // else // Sponge - Remove unnecessary else
    // { //
    int i = this.shadow$getGameRules().getInt("randomTickSpeed");
    boolean flag = this.isRaining();
    boolean flag1 = this.isThundering();
    // this.profiler.startSection("pollingChunks"); // Sponge - Don't use the profiler
    // Sponge - get the cause tracker
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    // Sponge: Use SpongeImplHooks for Forge
    for (Iterator<net.minecraft.world.chunk.Chunk> iterator = // this.profiler.endSection()) // Sponge - don't use the profiler
    SpongeImplHooks.getChunkIterator((WorldServer) (Object) this); // this.profiler.endSection()) // Sponge - don't use the profiler
    iterator.hasNext(); ) {
        // this.profiler.startSection("getChunk"); // Sponge - Don't use the profiler
        net.minecraft.world.chunk.Chunk chunk = iterator.next();
        final net.minecraft.world.World world = chunk.getWorld();
        int j = chunk.x * 16;
        int k = chunk.z * 16;
        // this.profiler.endStartSection("checkNextLight"); // Sponge - Don't use the profiler
        // Sponge - Timings
        this.timings.updateBlocksCheckNextLight.startTiming();
        chunk.enqueueRelightChecks();
        // Sponge - Timings
        this.timings.updateBlocksCheckNextLight.stopTiming();
        // this.profiler.endStartSection("tickChunk"); // Sponge - Don't use the profiler
        // Sponge - Timings
        this.timings.updateBlocksChunkTick.startTiming();
        chunk.onTick(false);
        // Sponge - Timings
        this.timings.updateBlocksChunkTick.stopTiming();
        // Sponge start - if surrounding neighbors are not loaded, skip
        if (!((IMixinChunk) chunk).areNeighborsLoaded()) {
            continue;
        }
        // Sponge end
        // this.profiler.endStartSection("thunder"); // Sponge - Don't use the profiler
        // Sponge start
        this.timings.updateBlocksThunder.startTiming();
        // if (this.provider.canDoLightning(chunk) && flag && flag1 && this.rand.nextInt(100000) == 0) // Sponge - Add SpongeImplHooks for forge
        if (this.weatherThunderEnabled && SpongeImplHooks.canDoLightning(this.provider, chunk) && flag && flag1 && this.rand.nextInt(100000) == 0) {
            try (final PhaseContext<?> context = TickPhase.Tick.WEATHER.createPhaseContext().source(this).buildAndSwitch()) {
                // Sponge end
                this.updateLCG = this.updateLCG * 3 + 1013904223;
                int l = this.updateLCG >> 2;
                BlockPos blockpos = this.adjustPosToNearbyEntity(new BlockPos(j + (l & 15), 0, k + (l >> 8 & 15)));
                if (this.isRainingAt(blockpos)) {
                    DifficultyInstance difficultyinstance = this.getDifficultyForLocation(blockpos);
                    // Sponge - create a transform to be used for events
                    final Transform<org.spongepowered.api.world.World> transform = new Transform<>(this, VecHelper.toVector3d(blockpos).toDouble());
                    if (world.getGameRules().getBoolean("doMobSpawning") && this.rand.nextDouble() < (double) difficultyinstance.getAdditionalDifficulty() * 0.01D) {
                        // Sponge Start - Throw construction events
                        try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                            Sponge.getCauseStackManager().pushCause(this.getWeather());
                            Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.WEATHER);
                            ConstructEntityEvent.Pre constructEntityEvent = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), EntityTypes.HORSE, transform);
                            SpongeImpl.postEvent(constructEntityEvent);
                            if (!constructEntityEvent.isCancelled()) {
                                // Sponge End
                                EntitySkeletonHorse entityhorse = new EntitySkeletonHorse((WorldServer) (Object) this);
                                entityhorse.setTrap(true);
                                entityhorse.setGrowingAge(0);
                                entityhorse.setPosition(blockpos.getX(), blockpos.getY(), blockpos.getZ());
                                this.spawnEntity(entityhorse);
                            // Sponge Start - Throw a construct event for the lightning
                            }
                            ConstructEntityEvent.Pre lightning = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), EntityTypes.LIGHTNING, transform);
                            SpongeImpl.postEvent(lightning);
                            if (!lightning.isCancelled()) {
                                LightningEvent.Pre lightningPre = SpongeEventFactory.createLightningEventPre(frame.getCurrentCause());
                                if (!SpongeImpl.postEvent(lightningPre)) {
                                    // Sponge End
                                    this.addWeatherEffect(new EntityLightningBolt(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), true));
                                }
                            }
                        // Sponge - Brackets.
                        }
                    } else {
                        // Sponge start - Throw construction event for lightningbolts
                        try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                            Sponge.getCauseStackManager().pushCause(this.getWeather());
                            Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.WEATHER);
                            ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), EntityTypes.LIGHTNING, transform);
                            SpongeImpl.postEvent(event);
                            if (!event.isCancelled()) {
                                LightningEvent.Pre lightningPre = SpongeEventFactory.createLightningEventPre(frame.getCurrentCause());
                                if (!SpongeImpl.postEvent(lightningPre)) {
                                    // Sponge End
                                    this.addWeatherEffect(new EntityLightningBolt(world, (double) blockpos.getX(), (double) blockpos.getY(), (double) blockpos.getZ(), true));
                                }
                            }
                        // Sponge - Brackets.
                        }
                    }
                }
            }
        // Sponge - brackets
        // Sponge End
        }
        // Sponge - Stop thunder timing
        this.timings.updateBlocksThunder.stopTiming();
        // Sponge - Start thunder timing
        this.timings.updateBlocksIceAndSnow.startTiming();
        // if (this.rand.nextInt(16) == 0) // Sponge - Rewrite to use our boolean, and forge hook
        if (this.weatherIceAndSnowEnabled && SpongeImplHooks.canDoRainSnowIce(this.provider, chunk) && this.rand.nextInt(16) == 0) {
            // Sponge Start - Enter weather phase for snow and ice and flooding.
            try (final PhaseContext<?> context = TickPhase.Tick.WEATHER.createPhaseContext().source(this).buildAndSwitch()) {
                // Sponge End
                this.updateLCG = this.updateLCG * 3 + 1013904223;
                int j2 = this.updateLCG >> 2;
                BlockPos blockpos1 = this.getPrecipitationHeight(new BlockPos(j + (j2 & 15), 0, k + (j2 >> 8 & 15)));
                BlockPos blockpos2 = blockpos1.down();
                if (this.canBlockFreezeNoWater(blockpos2)) {
                    this.setBlockState(blockpos2, Blocks.ICE.getDefaultState());
                }
                if (flag && this.canSnowAt(blockpos1, true)) {
                    this.setBlockState(blockpos1, Blocks.SNOW_LAYER.getDefaultState());
                }
                if (flag && this.getBiome(blockpos2).canRain()) {
                    this.getBlockState(blockpos2).getBlock().fillWithRain((WorldServer) (Object) this, blockpos2);
                }
            }
        // Sponge - brackets
        }
        // Sponge - Stop ice and snow timing
        this.timings.updateBlocksIceAndSnow.stopTiming();
        // Sponge - Start random block tick timing
        this.timings.updateBlocksRandomTick.startTiming();
        if (i > 0) {
            for (ExtendedBlockStorage extendedblockstorage : chunk.getBlockStorageArray()) {
                if (extendedblockstorage != net.minecraft.world.chunk.Chunk.NULL_BLOCK_STORAGE && extendedblockstorage.needsRandomTick()) {
                    for (int i1 = 0; i1 < i; ++i1) {
                        this.updateLCG = this.updateLCG * 3 + 1013904223;
                        int j1 = this.updateLCG >> 2;
                        int k1 = j1 & 15;
                        int l1 = j1 >> 8 & 15;
                        int i2 = j1 >> 16 & 15;
                        IBlockState iblockstate = extendedblockstorage.get(k1, i2, l1);
                        Block block = iblockstate.getBlock();
                        if (block.getTickRandomly()) {
                            // Sponge start - capture random tick
                            // Remove the random tick for cause tracking
                            // block.randomTick(this, new BlockPos(k1 + j, i2 + extendedblockstorage.getYLocation(), l1 + k), iblockstate, this.rand);
                            BlockPos pos = new BlockPos(k1 + j, i2 + extendedblockstorage.getYLocation(), l1 + k);
                            IMixinBlock spongeBlock = (IMixinBlock) block;
                            spongeBlock.getTimingsHandler().startTiming();
                            final PhaseData currentTuple = phaseTracker.getCurrentPhaseData();
                            final IPhaseState phaseState = currentTuple.state;
                            if (phaseState.alreadyCapturingBlockTicks(currentTuple.context)) {
                                block.randomTick(world, pos, iblockstate, this.rand);
                            } else {
                                TrackingUtil.randomTickBlock(phaseTracker, this, block, pos, iblockstate, this.rand);
                            }
                            spongeBlock.getTimingsHandler().stopTiming();
                        // Sponge end
                        }
                    // this.profiler.endSection(); // Sponge - Don't use the profiler
                    }
                }
            }
        }
    }
    // Sponge - Stop random block timing
    this.timings.updateBlocksRandomTick.stopTiming();
// this.profiler.endSection(); // Sponge - Don't use the profiler
// } // Sponge- Remove unecessary else
}
Also used : DifficultyInstance(net.minecraft.world.DifficultyInstance) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt) World(net.minecraft.world.World) IMixinBlock(org.spongepowered.common.interfaces.block.IMixinBlock) CauseStackManager(org.spongepowered.api.event.CauseStackManager) EntitySkeletonHorse(net.minecraft.entity.passive.EntitySkeletonHorse) BlockPos(net.minecraft.util.math.BlockPos) IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos) Chunk(net.minecraft.world.chunk.Chunk) IBlockState(net.minecraft.block.state.IBlockState) PhaseData(org.spongepowered.common.event.tracking.PhaseData) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) World(net.minecraft.world.World) LightningEvent(org.spongepowered.api.event.action.LightningEvent) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) ExtendedBlockStorage(net.minecraft.world.chunk.storage.ExtendedBlockStorage) ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) StackFrame(org.spongepowered.api.event.CauseStackManager.StackFrame) Block(net.minecraft.block.Block) EnumSkyBlock(net.minecraft.world.EnumSkyBlock) IMixinBlock(org.spongepowered.common.interfaces.block.IMixinBlock) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Transform(org.spongepowered.api.entity.Transform) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 27 with PhaseData

use of org.spongepowered.common.event.tracking.PhaseData in project SpongeCommon by SpongePowered.

the class MixinWorldServer method setBlock.

@Override
public boolean setBlock(int x, int y, int z, BlockState blockState, BlockChangeFlag flag) {
    checkBlockBounds(x, y, z);
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final PhaseData peek = phaseTracker.getCurrentPhaseData();
    boolean isWorldGen = peek.state.isWorldGeneration();
    boolean handlesOwnCompletion = peek.state.handlesOwnStateCompletion();
    if (!isWorldGen) {
        checkArgument(flag != null, "BlockChangeFlag cannot be null!");
    }
    try (PhaseContext<?> context = isWorldGen || handlesOwnCompletion ? null : PluginPhase.State.BLOCK_WORKER.createPhaseContext().buildAndSwitch()) {
        return setBlockState(new BlockPos(x, y, z), (IBlockState) blockState, flag);
    }
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) PhaseData(org.spongepowered.common.event.tracking.PhaseData) BlockPos(net.minecraft.util.math.BlockPos) IMixinBlockPos(org.spongepowered.common.interfaces.util.math.IMixinBlockPos)

Example 28 with PhaseData

use of org.spongepowered.common.event.tracking.PhaseData in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createChangeBlockEventPre.

public static ChangeBlockEvent.Pre createChangeBlockEventPre(BlockEvent.BreakEvent forgeEvent) {
    final net.minecraft.world.World world = forgeEvent.getWorld();
    if (world.isRemote) {
        return null;
    }
    final BlockPos pos = forgeEvent.getPos();
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final PhaseData data = phaseTracker.getCurrentPhaseData();
    User owner = data.context.getOwner().orElse(null);
    User notifier = data.context.getNotifier().orElse(null);
    EntityPlayer player = forgeEvent.getPlayer();
    if (SpongeImplHooks.isFakePlayer(player)) {
        Sponge.getCauseStackManager().addContext(EventContextKeys.FAKE_PLAYER, EntityUtil.toPlayer(player));
    } else {
        Sponge.getCauseStackManager().pushCause(player);
    }
    if (owner != null) {
        Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, owner);
        if (Sponge.getCauseStackManager().getCurrentCause() == null) {
            Sponge.getCauseStackManager().pushCause(owner);
        }
    } else {
        Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, (User) player);
        if (Sponge.getCauseStackManager().getCurrentCause() == null) {
            Sponge.getCauseStackManager().pushCause(player);
        }
    }
    if (notifier != null) {
        Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier);
    }
    Sponge.getCauseStackManager().addContext(EventContextKeys.PLAYER_BREAK, (World) world);
    return SpongeEventFactory.createChangeBlockEventPre(Sponge.getCauseStackManager().getCurrentCause(), ImmutableList.of(new Location<>((World) world, pos.getX(), pos.getY(), pos.getZ())));
}
Also used : PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) PhaseData(org.spongepowered.common.event.tracking.PhaseData) User(org.spongepowered.api.entity.living.player.User) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) Location(org.spongepowered.api.world.Location) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation)

Example 29 with PhaseData

use of org.spongepowered.common.event.tracking.PhaseData in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createChangeBlockEventBreak.

public static ChangeBlockEvent.Break createChangeBlockEventBreak(BlockEvent.BreakEvent forgeEvent) {
    final BlockPos pos = forgeEvent.getPos();
    final net.minecraft.world.World world = forgeEvent.getWorld();
    if (world.isRemote) {
        return null;
    }
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    final PhaseData data = phaseTracker.getCurrentPhaseData();
    BlockSnapshot originalSnapshot = ((World) forgeEvent.getWorld()).createSnapshot(pos.getX(), pos.getY(), pos.getZ());
    BlockSnapshot finalSnapshot = BlockTypes.AIR.getDefaultState().snapshotFor(new Location<>((World) world, VecHelper.toVector3d(pos)));
    ImmutableList<Transaction<BlockSnapshot>> blockSnapshots = new ImmutableList.Builder<Transaction<BlockSnapshot>>().add(new Transaction<>(originalSnapshot, finalSnapshot)).build();
    User owner = data.context.getOwner().orElse(null);
    User notifier = data.context.getNotifier().orElse(null);
    EntityPlayer player = forgeEvent.getPlayer();
    if (SpongeImplHooks.isFakePlayer(player)) {
        Sponge.getCauseStackManager().addContext(EventContextKeys.FAKE_PLAYER, EntityUtil.toPlayer(player));
    } else if (Sponge.getCauseStackManager().getCurrentCause() == null) {
        Sponge.getCauseStackManager().pushCause(player);
    }
    if (owner != null) {
        Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, owner);
        if (Sponge.getCauseStackManager().getCurrentCause() == null) {
            Sponge.getCauseStackManager().pushCause(owner);
        }
    } else {
        Sponge.getCauseStackManager().addContext(EventContextKeys.OWNER, (User) player);
        if (Sponge.getCauseStackManager().getCurrentCause() == null) {
            Sponge.getCauseStackManager().pushCause(player);
        }
    }
    if (notifier != null) {
        Sponge.getCauseStackManager().addContext(EventContextKeys.NOTIFIER, notifier);
    }
    Sponge.getCauseStackManager().addContext(EventContextKeys.PLAYER_BREAK, (World) world);
    return SpongeEventFactory.createChangeBlockEventBreak(Sponge.getCauseStackManager().getCurrentCause(), blockSnapshots);
}
Also used : PhaseData(org.spongepowered.common.event.tracking.PhaseData) User(org.spongepowered.api.entity.living.player.User) IMixinBlockSnapshot(org.spongepowered.mod.interfaces.IMixinBlockSnapshot) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Transaction(org.spongepowered.api.data.Transaction) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Example 30 with PhaseData

use of org.spongepowered.common.event.tracking.PhaseData in project SpongeForge by SpongePowered.

the class MixinItemShears method itemInteractionForEntity.

/**
 * @author gabizou - June 21st, 2016
 * @reason Rewrites the forge handling of this to properly handle
 * when sheared drops are captured by whatever current phase the
 * {@link PhaseTracker} is in.
 *
 * Returns true if the item can be used on the given entity, e.g. shears on sheep.
 */
@Overwrite
@Override
public boolean itemInteractionForEntity(ItemStack itemstack, EntityPlayer player, EntityLivingBase entity, EnumHand hand) {
    if (entity.world.isRemote) {
        return false;
    }
    if (entity instanceof IShearable) {
        IShearable target = (IShearable) entity;
        BlockPos pos = new BlockPos(entity.posX, entity.posY, entity.posZ);
        if (target.isShearable(itemstack, entity.world, pos)) {
            List<ItemStack> drops = target.onSheared(itemstack, entity.world, pos, EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, itemstack));
            // Sponge Start - Handle drops according to the current phase
            final PhaseTracker phaseTracker = PhaseTracker.getInstance();
            final PhaseData currentData = phaseTracker.getCurrentPhaseData();
            final IPhaseState<?> currentState = currentData.state;
            final PhaseContext<?> phaseContext = currentData.context;
            final Random random = EntityUtil.fromNative(entity).getRandom();
            final IMixinEntity mixinEntity = EntityUtil.toMixin(entity);
            final double posX = entity.posX;
            final double posY = entity.posY + 1.0F;
            final double posZ = entity.posZ;
            final Vector3d position = new Vector3d(posX, posY, posZ);
            // Now the real fun begins.
            for (ItemStack drop : drops) {
                final ItemStack item;
                if (!drop.isEmpty()) {
                    try (final CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
                        // FIRST we want to throw the DropItemEvent.PRE
                        final ItemStackSnapshot snapshot = ItemStackUtil.snapshotOf(drop);
                        final List<ItemStackSnapshot> original = new ArrayList<>();
                        original.add(snapshot);
                        Sponge.getCauseStackManager().pushCause(entity);
                        final DropItemEvent.Pre dropEvent = SpongeEventFactory.createDropItemEventPre(Sponge.getCauseStackManager().getCurrentCause(), ImmutableList.of(snapshot), original);
                        if (dropEvent.isCancelled()) {
                            continue;
                        }
                        // SECOND throw the ConstructEntityEvent
                        Transform<World> suggested = new Transform<>(mixinEntity.getWorld(), position);
                        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.DROPPED_ITEM);
                        ConstructEntityEvent.Pre event = SpongeEventFactory.createConstructEntityEventPre(Sponge.getCauseStackManager().getCurrentCause(), EntityTypes.ITEM, suggested);
                        SpongeImpl.postEvent(event);
                        item = event.isCancelled() ? null : ItemStackUtil.fromSnapshotToNative(dropEvent.getDroppedItems().get(0));
                    }
                } else {
                    continue;
                }
                if (item == null) {
                    continue;
                }
                if (!item.isEmpty()) {
                    if (!currentState.ignoresItemPreMerging() && SpongeImpl.getGlobalConfig().getConfig().getOptimizations().doDropsPreMergeItemDrops()) {
                        if (currentState.tracksEntitySpecificDrops()) {
                            final Multimap<UUID, ItemDropData> multimap = phaseContext.getCapturedEntityDropSupplier().get();
                            final Collection<ItemDropData> itemStacks = multimap.get(entity.getUniqueID());
                            SpongeImplHooks.addItemStackToListForSpawning(itemStacks, ItemDropData.item(item).motion(new Vector3d((random.nextFloat() - random.nextFloat()) * 0.1F, random.nextFloat() * 0.05F, (random.nextFloat() - random.nextFloat()) * 0.1F)).position(new Vector3d(posX, posY, posZ)).build());
                            continue;
                        }
                        final List<ItemDropData> itemStacks = phaseContext.getCapturedItemStackSupplier().get();
                        SpongeImplHooks.addItemStackToListForSpawning(itemStacks, ItemDropData.item(item).position(new Vector3d(posX, posY, posZ)).motion(new Vector3d((random.nextFloat() - random.nextFloat()) * 0.1F, random.nextFloat() * 0.05F, (random.nextFloat() - random.nextFloat()) * 0.1F)).build());
                        continue;
                    }
                    EntityItem entityitem = new EntityItem(entity.world, posX, posY, posZ, item);
                    entityitem.setDefaultPickupDelay();
                    entityitem.motionY += random.nextFloat() * 0.05F;
                    entityitem.motionX += (random.nextFloat() - random.nextFloat()) * 0.1F;
                    entityitem.motionZ += (random.nextFloat() - random.nextFloat()) * 0.1F;
                    // FIFTH - Capture the entity maybe?
                    if (currentState.doesCaptureEntityDrops()) {
                        if (currentState.tracksEntitySpecificDrops()) {
                            // We are capturing per entity drop
                            phaseContext.getCapturedEntityItemDropSupplier().get().put(entity.getUniqueID(), entityitem);
                        } else {
                            // We are adding to a general list - usually for EntityPhase.State.DEATH
                            phaseContext.getCapturedItemsSupplier().get().add(entityitem);
                        }
                        // Return the item, even if it wasn't spawned in the world.
                        continue;
                    }
                    // FINALLY - Spawn the entity in the world if all else didn't fail
                    entity.world.spawnEntity(entityitem);
                }
            }
            // Sponge End
            itemstack.damageItem(1, entity);
        }
        return true;
    }
    return false;
}
Also used : ArrayList(java.util.ArrayList) IMixinEntity(org.spongepowered.common.interfaces.entity.IMixinEntity) World(org.spongepowered.api.world.World) Random(java.util.Random) CauseStackManager(org.spongepowered.api.event.CauseStackManager) IShearable(net.minecraftforge.common.IShearable) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) EntityItem(net.minecraft.entity.item.EntityItem) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) PhaseData(org.spongepowered.common.event.tracking.PhaseData) ConstructEntityEvent(org.spongepowered.api.event.entity.ConstructEntityEvent) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Vector3d(com.flowpowered.math.vector.Vector3d) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) ItemStack(net.minecraft.item.ItemStack) Transform(org.spongepowered.api.entity.Transform) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Aggregations

PhaseData (org.spongepowered.common.event.tracking.PhaseData)30 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)22 BlockPos (net.minecraft.util.math.BlockPos)13 IPhaseState (org.spongepowered.common.event.tracking.IPhaseState)10 User (org.spongepowered.api.entity.living.player.User)9 IBlockState (net.minecraft.block.state.IBlockState)8 EntityPlayer (net.minecraft.entity.player.EntityPlayer)8 World (org.spongepowered.api.world.World)8 Overwrite (org.spongepowered.asm.mixin.Overwrite)8 CauseStackManager (org.spongepowered.api.event.CauseStackManager)6 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)6 ItemStack (net.minecraft.item.ItemStack)5 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)5 Transaction (org.spongepowered.api.data.Transaction)5 BlockState (org.spongepowered.api.block.BlockState)4 Inject (org.spongepowered.asm.mixin.injection.Inject)4 Redirect (org.spongepowered.asm.mixin.injection.Redirect)4 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)4 IMixinWorld (org.spongepowered.common.interfaces.world.IMixinWorld)4 Block (net.minecraft.block.Block)3