use of net.minecraftforge.event.entity.living.LivingDropsEvent in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method createLivingDropItemEvent.
private static LivingDropsEvent createLivingDropItemEvent(Event event) {
DropItemEvent.Destruct spongeEvent = (DropItemEvent.Destruct) event;
Optional<EntityLivingBase> spawnCause = spongeEvent.getCause().first(EntityLivingBase.class);
if (!spawnCause.isPresent()) {
return null;
}
Optional<DamageSource> source = spongeEvent.getCause().first(DamageSource.class);
if (!source.isPresent()) {
return null;
}
List<EntityItem> items = new ArrayList<>();
for (org.spongepowered.api.entity.Entity entity : spongeEvent.getEntities()) {
if (entity instanceof EntityItem) {
items.add((EntityItem) entity);
}
}
LivingDropsEvent forgeEvent = new LivingDropsEvent(spawnCause.get(), (net.minecraft.util.DamageSource) source.get(), items, 0, false);
return forgeEvent;
}
use of net.minecraftforge.event.entity.living.LivingDropsEvent in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method callLivingDropsEvent.
@SuppressWarnings("unchecked")
public static DropItemEvent.Destruct callLivingDropsEvent(Event event) {
DropItemEvent.Destruct spongeEvent = (DropItemEvent.Destruct) event;
final Cause cause = spongeEvent.getCause();
Object source = cause.root();
Optional<DamageSource> damageSource = cause.first(DamageSource.class);
final Optional<Entity> spawnEntity = cause.first(Entity.class);
final Optional<SpawnType> spawnType = cause.getContext().get(EventContextKeys.SPAWN_TYPE);
if (!spawnType.isPresent() || !damageSource.isPresent() || !spawnEntity.isPresent()) {
// Mods expect EntityJoinWorldEvent to trigger
callEntityJoinWorldEvent(spongeEvent);
return spongeEvent;
}
Entity entity = spawnEntity.get();
if (entity == null || !(entity instanceof EntityLivingBase)) {
return spongeEvent;
}
LivingDropsEvent forgeEvent = null;
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
forgeEvent = new PlayerDropsEvent(player, (net.minecraft.util.DamageSource) damageSource.get(), (List<EntityItem>) (List<?>) spongeEvent.getEntities(), ((IMixinEntityLivingBase) entity).getRecentlyHit() > 0);
} else {
forgeEvent = new LivingDropsEvent((EntityLivingBase) entity, (net.minecraft.util.DamageSource) damageSource.get(), (List<EntityItem>) (List<?>) spongeEvent.getEntities(), 0, ((IMixinEntityLivingBase) entity).getRecentlyHit() > 0);
}
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
if (forgeEvent.isCanceled()) {
spongeEvent.setCancelled(true);
} else {
callEntityJoinWorldEvent(spongeEvent);
}
return spongeEvent;
}
Aggregations