|
24 | 24 | */
|
25 | 25 | package org.spongepowered.common.event.tracking.phase.entity;
|
26 | 26 |
|
| 27 | +import org.spongepowered.api.Sponge; |
| 28 | +import org.spongepowered.api.entity.Entity; |
| 29 | +import org.spongepowered.api.event.cause.EventContextKeys; |
| 30 | +import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; |
| 31 | +import org.spongepowered.common.event.SpongeCommonEventFactory; |
| 32 | +import org.spongepowered.common.event.tracking.TrackingUtil; |
| 33 | + |
| 34 | +import java.util.ArrayList; |
| 35 | +import java.util.List; |
| 36 | +import java.util.stream.Collectors; |
| 37 | + |
27 | 38 | public final class EntityCollisionState extends EntityPhaseState<BasicEntityContext> {
|
28 | 39 |
|
29 | 40 | @Override
|
30 | 41 | protected BasicEntityContext createNewContext() {
|
31 |
| - return new BasicEntityContext(this); |
| 42 | + return new BasicEntityContext(this).addEntityCaptures(); |
32 | 43 | }
|
33 | 44 |
|
34 | 45 | @Override
|
35 | 46 | public boolean isCollision() {
|
36 | 47 | return true;
|
37 | 48 | }
|
| 49 | + |
| 50 | + @Override |
| 51 | + public void unwind(BasicEntityContext context) { |
| 52 | + context.getCapturedItemsSupplier() |
| 53 | + .acceptAndClearIfNotEmpty(items -> { |
| 54 | + final List<Entity> entities = items.stream() |
| 55 | + .map(entity -> (Entity) entity) |
| 56 | + .collect(Collectors.toList()); |
| 57 | + Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PASSIVE); |
| 58 | + SpongeCommonEventFactory.callDropItemCustom(entities, context); |
| 59 | + }); |
| 60 | + TrackingUtil.processBlockCaptures(context); |
| 61 | + context.getCapturedEntitySupplier() |
| 62 | + .acceptAndClearIfNotEmpty(mc -> { |
| 63 | + final List<Entity> entities = new ArrayList<>(mc); |
| 64 | + Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PASSIVE); |
| 65 | + SpongeCommonEventFactory.callSpawnEntityCustom(entities, context); |
| 66 | + }); |
| 67 | + } |
38 | 68 | }
|
0 commit comments