Generalize more of the events, add the ability to have events fire before/after the action proposed

This commit is contained in:
pahimar 2012-12-18 13:05:04 -05:00
parent d6aca678d5
commit 112b74dd30
5 changed files with 16 additions and 21 deletions

View file

@ -4,20 +4,25 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.event.Event;
public class WorldTransmutationEvent extends Event {
public class ActionEvent extends Event {
public final byte actionType;
public final EntityPlayer player;
public final World world;
public final int x, y, z;
public final boolean hasActionOccured;
public final String data;
public WorldTransmutationEvent(EntityPlayer player, World world, int x, int y, int z, String data) {
public ActionEvent(byte actionType, EntityPlayer player, World world, int x, int y, int z, boolean hasActionOccured, String data) {
this.actionType = actionType;
this.player = player;
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.hasActionOccured = hasActionOccured;
this.data = data;
}
}

View file

@ -4,19 +4,17 @@ import static net.minecraftforge.event.Event.Result.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.Cancelable;
import net.minecraftforge.event.Event;
import net.minecraftforge.event.entity.player.PlayerEvent;
@Cancelable
public class ActionRequestEvent extends PlayerEvent {
public final Event modEvent;
public final ActionEvent modEvent;
public final int x, y, z;
public final int sideHit;
public Result allowEvent;
public ActionRequestEvent(EntityPlayer player, Event modEvent, int x, int y, int z, int sideHit) {
public ActionRequestEvent(EntityPlayer player, ActionEvent modEvent, int x, int y, int z, int sideHit) {
super(player);
this.modEvent = modEvent;

View file

@ -9,7 +9,7 @@ import com.pahimar.ee3.lib.GuiIds;
import com.pahimar.ee3.lib.Reference;
import com.pahimar.ee3.lib.Sounds;
import com.pahimar.ee3.lib.Strings;
import com.pahimar.ee3.lib.RequestEvents;
import com.pahimar.ee3.lib.ActionTypes;
import com.pahimar.ee3.network.PacketTypeHandler;
import com.pahimar.ee3.network.packet.PacketKeyPressed;
import com.pahimar.ee3.network.packet.PacketRequestEvent;
@ -84,7 +84,7 @@ public class ItemPhilosopherStone extends ItemEE
//boolean result = TransmutationHelper.transmuteInWorld(world, entityPlayer, itemStack, x, y, z);
boolean result = true;
if (!world.isRemote) {
EquivalentExchange3.proxy.sendWorldEventPacket(RequestEvents.TRANSMUTATION, x, y, z, (byte)sideHit, (byte)getCharge(itemStack), (byte)getCharge(itemStack), (byte)getCharge(itemStack), "50:0");
EquivalentExchange3.proxy.sendWorldEventPacket(ActionTypes.TRANSMUTATION, x, y, z, (byte)sideHit, (byte)getCharge(itemStack), (byte)getCharge(itemStack), (byte)getCharge(itemStack), "50:0");
}
/*
if (result) {

View file

@ -1,7 +1,7 @@
package com.pahimar.ee3.lib;
public class RequestEvents {
public class ActionTypes {
public static final byte TRANSMUTATION = 0;

View file

@ -4,18 +4,16 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import com.pahimar.ee3.event.ActionEvent;
import com.pahimar.ee3.event.ActionRequestEvent;
import com.pahimar.ee3.event.WorldTransmutationEvent;
import com.pahimar.ee3.lib.RequestEvents;
import com.pahimar.ee3.lib.ActionTypes;
import com.pahimar.ee3.network.PacketTypeHandler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import cpw.mods.fml.common.network.Player;
public class PacketRequestEvent extends PacketEE {
@ -103,13 +101,7 @@ public class PacketRequestEvent extends PacketEE {
EntityPlayer thePlayer = (EntityPlayer) player;
ActionRequestEvent actionRequestEvent = null;
Event actionEvent = null;;
// TODO Move this logic to a ActionEvent handler to post an appropriate event depending on the request received
if (eventType == RequestEvents.TRANSMUTATION) {
actionEvent = new WorldTransmutationEvent(thePlayer, thePlayer.worldObj, originX, originY, originZ, data);
}
ActionEvent actionEvent = new ActionEvent(ActionTypes.TRANSMUTATION, thePlayer, thePlayer.worldObj, originX, originY, originZ, false, data);
if (actionEvent != null) {
actionRequestEvent = new ActionRequestEvent(thePlayer, actionEvent, originX, originY, originZ, (int) sideHit);