Cleanup ritual events (#1256)

Also actually fire the imperfect one ¬_¬
This commit is contained in:
Nicholas Ignoffo 2018-03-23 16:18:16 -07:00
parent 25f492ef65
commit cdfc77be03
3 changed files with 67 additions and 17 deletions

View file

@ -1,7 +1,9 @@
package WayofTime.bloodmagic.block;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.event.RitualEvent;
import WayofTime.bloodmagic.iface.IBindable;
import WayofTime.bloodmagic.ritual.imperfect.IImperfectRitualStone;
import WayofTime.bloodmagic.ritual.imperfect.ImperfectRitualRegistry;
import WayofTime.bloodmagic.ritual.RitualRegistry;
import WayofTime.bloodmagic.ritual.Ritual;
@ -26,6 +28,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import javax.annotation.Nullable;
@ -66,9 +69,13 @@ public class BlockRitualController extends BlockEnum<EnumRitualController> imple
}
}
} else if (state.getValue(getProperty()) == EnumRitualController.IMPERFECT && tile instanceof TileImperfectRitualStone) {
IBlockState ritualBlock = world.getBlockState(pos.up());
return ((TileImperfectRitualStone) tile).performRitual(world, pos, ImperfectRitualRegistry.getRitualForBlock(ritualBlock), player);
ImperfectRitual ritual = ImperfectRitualRegistry.getRitualForBlock(ritualBlock);
if (ritual == null)
return false;
RitualEvent.ImperfectRitualActivatedEvent event = new RitualEvent.ImperfectRitualActivatedEvent((IImperfectRitualStone) tile, player, ritual);
return !MinecraftForge.EVENT_BUS.post(event) && ((TileImperfectRitualStone) tile).performRitual(world, pos, ritual, player);
}
return false;

View file

@ -13,9 +13,10 @@ import net.minecraftforge.fml.common.eventhandler.Event;
import java.util.UUID;
public class RitualEvent extends Event {
public final IMasterRitualStone mrs;
public final UUID ownerId;
public final Ritual ritual;
private final IMasterRitualStone mrs;
private final UUID ownerId;
private final Ritual ritual;
private RitualEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual) {
this.mrs = mrs;
@ -23,6 +24,18 @@ public class RitualEvent extends Event {
this.ritual = ritual;
}
public IMasterRitualStone getRitualStone() {
return mrs;
}
public UUID getOwnerId() {
return ownerId;
}
public Ritual getRitual() {
return ritual;
}
/**
* This event is called when a ritual is activated. If cancelled, it will
* not activate.
@ -31,9 +44,10 @@ public class RitualEvent extends Event {
*/
@Cancelable
public static class RitualActivatedEvent extends RitualEvent {
public final EntityPlayer player;
public final ItemStack crystalStack;
public int crystalTier;
private final EntityPlayer player;
private final ItemStack crystalStack;
private final int crystalTier;
public RitualActivatedEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual, EntityPlayer player, ItemStack activationCrystal, int crystalTier) {
super(mrs, ownerId, ritual);
@ -42,6 +56,18 @@ public class RitualEvent extends Event {
this.crystalStack = activationCrystal;
this.crystalTier = crystalTier;
}
public EntityPlayer getPlayer() {
return player;
}
public ItemStack getCrystalStack() {
return crystalStack;
}
public int getCrystalTier() {
return crystalTier;
}
}
/**
@ -52,6 +78,7 @@ public class RitualEvent extends Event {
*/
@Cancelable
public static class RitualRunEvent extends RitualEvent {
public RitualRunEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual) {
super(mrs, ownerId, ritual);
}
@ -65,26 +92,42 @@ public class RitualEvent extends Event {
*/
public static class RitualStopEvent extends RitualEvent {
public final Ritual.BreakType method;
private final Ritual.BreakType method;
public RitualStopEvent(IMasterRitualStone mrs, UUID ownerId, Ritual ritual, Ritual.BreakType method) {
super(mrs, ownerId, ritual);
this.method = method;
}
public Ritual.BreakType getMethod() {
return method;
}
}
@Cancelable
public static class ImperfectRitualActivatedEvent extends Event {
public final IImperfectRitualStone ims;
public final UUID ownerId;
public final ImperfectRitual imperfectRitual;
private final IImperfectRitualStone ims;
private final EntityPlayer activator;
private final ImperfectRitual imperfectRitual;
public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, UUID ownerId, ImperfectRitual imperfectRitual) {
public ImperfectRitualActivatedEvent(IImperfectRitualStone ims, EntityPlayer activator, ImperfectRitual imperfectRitual) {
this.ims = ims;
this.ownerId = ownerId;
this.activator = activator;
this.imperfectRitual = imperfectRitual;
}
public IImperfectRitualStone getRitualStone() {
return ims;
}
public EntityPlayer getActivator() {
return activator;
}
public ImperfectRitual getImperfectRitual() {
return imperfectRitual;
}
}
}

View file

@ -140,7 +140,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
RitualEvent.RitualActivatedEvent event = new RitualEvent.RitualActivatedEvent(this, binding.getOwnerId(), ritual, activator, activationCrystal, crystalLevel);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY) {
if (MinecraftForge.EVENT_BUS.post(event)) {
if (activator != null)
activator.sendStatusMessage(new TextComponentTranslation("chat.bloodmagic.ritual.prevent"), true);
return false;
@ -181,7 +181,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
if (RitualHelper.checkValidRitual(getWorld(), getPos(), RitualRegistry.getIdForRitual(currentRitual), getDirection())) {
RitualEvent.RitualRunEvent event = new RitualEvent.RitualRunEvent(this, getOwner(), getCurrentRitual());
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
if (MinecraftForge.EVENT_BUS.post(event))
return;
getCurrentRitual().performRitual(this);
@ -196,7 +196,7 @@ public class TileMasterRitualStone extends TileTicking implements IMasterRitualS
if (!getWorld().isRemote && getCurrentRitual() != null) {
RitualEvent.RitualStopEvent event = new RitualEvent.RitualStopEvent(this, getOwner(), getCurrentRitual(), breakType);
if (MinecraftForge.EVENT_BUS.post(event) || event.getResult() == Event.Result.DENY)
if (MinecraftForge.EVENT_BUS.post(event))
return;
getCurrentRitual().stopRitual(this, breakType);