2012-12-17 21:21:53 +01:00
|
|
|
package com.pahimar.ee3.network.packet;
|
2012-12-05 22:06:50 +01:00
|
|
|
|
2012-12-06 05:15:36 +01:00
|
|
|
import java.io.DataInputStream;
|
|
|
|
import java.io.DataOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2012-12-18 19:05:04 +01:00
|
|
|
import com.pahimar.ee3.event.ActionEvent;
|
2012-12-17 22:38:56 +01:00
|
|
|
import com.pahimar.ee3.event.ActionRequestEvent;
|
2012-12-19 03:57:38 +01:00
|
|
|
import com.pahimar.ee3.event.WorldTransmutationEvent;
|
2012-12-18 19:05:04 +01:00
|
|
|
import com.pahimar.ee3.lib.ActionTypes;
|
2012-12-17 21:21:53 +01:00
|
|
|
import com.pahimar.ee3.network.PacketTypeHandler;
|
|
|
|
|
2012-12-13 16:01:41 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.network.INetworkManager;
|
|
|
|
import net.minecraft.world.World;
|
2012-12-13 04:41:40 +01:00
|
|
|
import net.minecraftforge.common.MinecraftForge;
|
|
|
|
import net.minecraftforge.event.Event.Result;
|
2012-12-06 05:15:36 +01:00
|
|
|
import cpw.mods.fml.common.network.Player;
|
|
|
|
|
2012-12-17 22:38:56 +01:00
|
|
|
public class PacketRequestEvent 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-17 22:38:56 +01:00
|
|
|
public PacketRequestEvent() {
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-17 22:38:56 +01:00
|
|
|
super(PacketTypeHandler.REQUEST_EVENT, false);
|
2012-12-06 05:15:36 +01:00
|
|
|
}
|
2012-12-06 22:04:20 +01:00
|
|
|
|
2012-12-17 22:38:56 +01:00
|
|
|
public PacketRequestEvent(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
|
|
|
|
2012-12-17 22:38:56 +01:00
|
|
|
super(PacketTypeHandler.REQUEST_EVENT, false);
|
2012-12-06 22:04:20 +01:00
|
|
|
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-19 03:57:38 +01:00
|
|
|
|
2012-12-06 22:04:20 +01:00
|
|
|
public void setSideHit(byte sideHit) {
|
2012-12-19 03:57:38 +01:00
|
|
|
|
2012-12-06 22:04:20 +01:00
|
|
|
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-13 04:41:40 +01:00
|
|
|
EntityPlayer thePlayer = (EntityPlayer) player;
|
2012-12-17 22:38:56 +01:00
|
|
|
ActionRequestEvent actionRequestEvent = null;
|
2012-12-19 03:57:38 +01:00
|
|
|
ActionEvent actionEvent = null;
|
|
|
|
|
|
|
|
int lowerBoundX = -1 * rangeX / 2;
|
|
|
|
int upperBoundX = -1 * lowerBoundX;
|
|
|
|
int lowerBoundY = -1 * rangeY / 2;
|
|
|
|
int upperBoundY = -1 * lowerBoundY;
|
|
|
|
int lowerBoundZ = -1 * rangeZ / 2;
|
|
|
|
int upperBoundZ = -1 * lowerBoundZ;
|
|
|
|
|
|
|
|
for (int x = lowerBoundX; x <= upperBoundX; x++) {
|
|
|
|
for (int y = lowerBoundY; y <= upperBoundY; y++) {
|
|
|
|
for (int z = lowerBoundZ; z <= upperBoundZ; z++) {
|
|
|
|
|
|
|
|
actionEvent = new WorldTransmutationEvent(ActionTypes.TRANSMUTATION, thePlayer, thePlayer.worldObj, originX + x, originY + y, originZ + z, false, data);
|
|
|
|
|
|
|
|
if (actionEvent != null) {
|
|
|
|
actionRequestEvent = new ActionRequestEvent(thePlayer, actionEvent, originX + x, originY + y, originZ + z, (int) sideHit);
|
|
|
|
MinecraftForge.EVENT_BUS.post(actionRequestEvent);
|
|
|
|
|
|
|
|
if (actionRequestEvent.allowEvent != Result.DENY) {
|
|
|
|
MinecraftForge.EVENT_BUS.post(actionEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-12-17 22:38:56 +01:00
|
|
|
}
|
2012-12-13 04:41:40 +01:00
|
|
|
}
|
2012-12-05 22:06:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|