use of org.spongepowered.mod.interfaces.IMixinEventBus in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method callWorldSaveEvent.
private static SaveWorldEvent callWorldSaveEvent(Event event) {
SaveWorldEvent spongeEvent = (SaveWorldEvent) event;
// Since Forge only uses a single save handler, we need to make sure to pass the overworld's handler.
// This makes sure that mods dont attempt to save/read their data from the wrong location.
((IMixinWorld) spongeEvent.getTargetWorld()).setCallingWorldEvent(true);
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(new WorldEvent.Save((net.minecraft.world.World) spongeEvent.getTargetWorld()), true);
((IMixinWorld) spongeEvent.getTargetWorld()).setCallingWorldEvent(false);
return spongeEvent;
}
use of org.spongepowered.mod.interfaces.IMixinEventBus in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method createPlayerInteractEvent.
// Bulk Event Handling
private static InteractBlockEvent createPlayerInteractEvent(Event event) {
InteractBlockEvent spongeEvent = (InteractBlockEvent) event;
Player player = spongeEvent.getCause().first(Player.class).orElse(null);
// Forge doesn't support left-click AIR
if (player == null || (spongeEvent instanceof InteractBlockEvent.Primary && spongeEvent.getTargetBlock() == BlockSnapshot.NONE)) {
return spongeEvent;
}
BlockPos pos = VecHelper.toBlockPos(spongeEvent.getTargetBlock().getPosition());
EnumFacing face = DirectionFacingProvider.getInstance().get(spongeEvent.getTargetSide()).orElse(null);
Vec3d hitVec = null;
final EntityPlayerMP entityPlayerMP = EntityUtil.toNative(player);
if (spongeEvent.getInteractionPoint().isPresent()) {
hitVec = VecHelper.toVec3d(spongeEvent.getInteractionPoint().get());
}
if (spongeEvent instanceof InteractBlockEvent.Primary) {
PlayerInteractEvent.LeftClickBlock forgeEvent = new PlayerInteractEvent.LeftClickBlock(entityPlayerMP, pos, face, hitVec);
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
if (forgeEvent.isCanceled()) {
spongeEvent.setCancelled(true);
}
} else if (face != null && spongeEvent instanceof InteractBlockEvent.Secondary) {
EnumHand hand = spongeEvent instanceof InteractBlockEvent.Secondary.MainHand ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
PlayerInteractEvent.RightClickBlock forgeEvent = new PlayerInteractEvent.RightClickBlock(entityPlayerMP, hand, pos, face, hitVec);
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
if (forgeEvent.isCanceled()) {
spongeEvent.setCancelled(true);
}
// Mods have higher priority
if (forgeEvent.getUseItem() != Result.DEFAULT) {
((InteractBlockEvent.Secondary) spongeEvent).setUseItemResult(getTristateFromResult(forgeEvent.getUseItem()));
}
if (forgeEvent.getUseBlock() != Result.DEFAULT) {
((InteractBlockEvent.Secondary) spongeEvent).setUseBlockResult(getTristateFromResult(forgeEvent.getUseBlock()));
}
}
return spongeEvent;
}
use of org.spongepowered.mod.interfaces.IMixinEventBus in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method callChunkLoadEvent.
private static LoadChunkEvent callChunkLoadEvent(Event event) {
LoadChunkEvent spongeEvent = (LoadChunkEvent) event;
final net.minecraft.world.chunk.Chunk chunk = (net.minecraft.world.chunk.Chunk) spongeEvent.getTargetChunk();
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(new ChunkEvent.Load(chunk), true);
return spongeEvent;
}
use of org.spongepowered.mod.interfaces.IMixinEventBus in project SpongeForge by SpongePowered.
the class SpongeForgeEventFactory method callLivingDeathEvent.
// unused
public static DestructEntityEvent.Death callLivingDeathEvent(Event event) {
DestructEntityEvent.Death spongeEvent = (DestructEntityEvent.Death) event;
if (!spongeEvent.getCause().first(DamageSource.class).isPresent()) {
return spongeEvent;
}
EntityLivingBase entity = (net.minecraft.entity.EntityLivingBase) spongeEvent.getTargetEntity();
net.minecraft.util.DamageSource damageSource = (net.minecraft.util.DamageSource) spongeEvent.getCause().first(DamageSource.class).get();
LivingDeathEvent forgeEvent = new LivingDeathEvent(entity, damageSource);
((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
return spongeEvent;
}
Aggregations