2012-12-05 22:06:50 +01:00
|
|
|
package ee3.common.network;
|
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
import java.io.DataInputStream;
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2012-12-07 13:11:57 +01:00
|
|
|
import net.minecraft.src.EntityPlayer;
|
2012-12-06 05:15:36 +01:00
|
|
|
import net.minecraft.src.INetworkManager;
|
2012-12-07 13:11:57 +01:00
|
|
|
import net.minecraft.src.World;
|
2012-12-13 04:41:40 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.Event;
|
|
|
|
import net.minecraftforge.event.Event.Result;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
2012-12-06 05:15:36 +01:00
|
|
|
import cpw.mods.fml.common.network.Player;
|
2012-12-13 04:41:40 +01:00
|
|
|
import ee3.common.event.ModActionEvent;
|
|
|
|
import ee3.common.event.WorldTransmutationEvent;
|
|
|
|
import ee3.common.lib.ModAction;
|
|
|
|
import ee3.common.lib.WorldEvents;
|
2012-12-06 05:15:36 +01:00
|
|
|
|
2012-12-06 22:04:20 +01:00
|
|
|
public class PacketWorldEvent extends PacketEE {
|
2012-12-05 22:06:50 +01:00
|
|
|
|
2012-12-06 22:04:20 +01:00
|
|
|
public byte eventType;
|
2012-12-05 22:06:50 +01:00
|
|
|
public int originX, originY, originZ;
|
2012-12-06 22:04:20 +01:00
|
|
|
public byte sideHit;
|
2012-12-06 05:15:36 +01:00
|
|
|
public byte rangeX, rangeY, rangeZ;
|
2012-12-07 03:06:16 +01:00
|
|
|
public String data;
|
2012-12-05 22:06:50 +01:00
|
|
|
|
2012-12-06 22:04:20 +01:00
|
|
|
public PacketWorldEvent() {
|
|
|
|
|
|
|
|
super(PacketTypeHandler.WORLD_EVENT, false);
|
2012-12-06 05:15:36 +01:00
|
|
|
}
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-07 03:06:16 +01:00
|
|
|
public PacketWorldEvent(byte eventType, int originX, int originY, int originZ, byte sideHit, byte rangeX, byte rangeY, byte rangeZ, String data) {
|
2012-12-06 22:04:20 +01:00
|
|
|
|
|
|
|
super(PacketTypeHandler.WORLD_EVENT, false);
|
|
|
|
this.eventType = eventType;
|
|
|
|
this.originX = originX;
|
|
|
|
this.originY = originY;
|
|
|
|
this.originZ = originZ;
|
|
|
|
this.sideHit = sideHit;
|
|
|
|
this.rangeX = rangeX;
|
|
|
|
this.rangeY = rangeY;
|
|
|
|
this.rangeZ = rangeZ;
|
2012-12-07 03:06:16 +01:00
|
|
|
this.data = data;
|
2012-12-06 22:04:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setEventType(byte eventType) {
|
|
|
|
|
|
|
|
this.eventType = eventType;
|
|
|
|
}
|
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
public void setOrigin(int originX, int originY, int originZ) {
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
this.originX = originX;
|
|
|
|
this.originY = originY;
|
|
|
|
this.originZ = originZ;
|
|
|
|
}
|
|
|
|
|
2012-12-06 22:04:20 +01:00
|
|
|
public void setSideHit(byte sideHit) {
|
|
|
|
this.sideHit = sideHit;
|
|
|
|
}
|
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
public void setRange(byte rangeX, byte rangeY, byte rangeZ) {
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
this.rangeX = rangeX;
|
|
|
|
this.rangeY = rangeY;
|
|
|
|
this.rangeZ = rangeZ;
|
|
|
|
}
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-07 03:06:16 +01:00
|
|
|
public void setData(String data) {
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-07 03:06:16 +01:00
|
|
|
this.data = data;
|
2012-12-06 05:15:36 +01:00
|
|
|
}
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
public void writeData(DataOutputStream data) throws IOException {
|
2012-12-06 22:04:20 +01:00
|
|
|
|
|
|
|
data.writeByte(eventType);
|
2012-12-06 05:15:36 +01:00
|
|
|
data.writeInt(originX);
|
|
|
|
data.writeInt(originY);
|
|
|
|
data.writeInt(originZ);
|
2012-12-06 22:04:20 +01:00
|
|
|
data.writeByte(sideHit);
|
2012-12-06 05:15:36 +01:00
|
|
|
data.writeByte(rangeX);
|
|
|
|
data.writeByte(rangeY);
|
|
|
|
data.writeByte(rangeZ);
|
2012-12-07 03:06:16 +01:00
|
|
|
data.writeUTF(this.data);
|
2012-12-06 05:15:36 +01:00
|
|
|
}
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
public void readData(DataInputStream data) throws IOException {
|
2012-12-06 22:04:20 +01:00
|
|
|
|
|
|
|
this.eventType = data.readByte();
|
2012-12-06 05:15:36 +01:00
|
|
|
this.originX = data.readInt();
|
|
|
|
this.originY = data.readInt();
|
|
|
|
this.originZ = data.readInt();
|
2012-12-06 22:04:20 +01:00
|
|
|
this.sideHit = data.readByte();
|
2012-12-06 05:15:36 +01:00
|
|
|
this.rangeX = data.readByte();
|
|
|
|
this.rangeY = data.readByte();
|
|
|
|
this.rangeZ = data.readByte();
|
2012-12-07 03:06:16 +01:00
|
|
|
this.data = data.readUTF();
|
2012-12-06 05:15:36 +01:00
|
|
|
}
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
public void execute(INetworkManager manager, Player player) {
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-07 13:11:57 +01:00
|
|
|
/*
|
|
|
|
* Server knows the world, the player, and all the packet data
|
|
|
|
* Server checks (for each block);
|
|
|
|
* 1) If the action on that block is allowed for the player
|
|
|
|
* 2) If the action is a valid action
|
|
|
|
*
|
|
|
|
* AoE options are; 1x1, 3x3, 5x5, and 7x7
|
|
|
|
* Charge options; 0, 1, 2, 3
|
|
|
|
* so Range would be 1, 2, 4, 6
|
|
|
|
* 1 + 0, 1 + 1, 1 + 3, 1 + 5
|
|
|
|
*/
|
2012-12-13 04:41:40 +01:00
|
|
|
|
|
|
|
EntityPlayer thePlayer = (EntityPlayer) player;
|
|
|
|
ModActionEvent modActionEvent;
|
|
|
|
WorldTransmutationEvent worldTransmutationEvent;
|
|
|
|
|
|
|
|
modActionEvent= new ModActionEvent(thePlayer, ModAction.TRANSMUTATION, originX, originY, originZ, (int) sideHit);
|
|
|
|
MinecraftForge.EVENT_BUS.post(modActionEvent);
|
|
|
|
|
|
|
|
if (modActionEvent.allowEvent != Result.DENY) {
|
|
|
|
worldTransmutationEvent = new WorldTransmutationEvent(thePlayer, thePlayer.worldObj, originX, originY, originZ, sideHit, rangeX, rangeY, rangeZ, data);
|
|
|
|
MinecraftForge.EVENT_BUS.post(worldTransmutationEvent);
|
|
|
|
}
|
|
|
|
|
2012-12-05 22:06:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|