mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 12:59:41 +00:00
Integrate security into more machines
This commit is contained in:
1 parent
f904c8b80c
commit
a18da2ad27
29 files changed
+385
-61
No files matched your search
@@ -4,9 +4,11 @@ import io.netty.buffer.ByteBuf;
|
||||
import mekanism.api.Coord4D;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.network.PacketSecurityMode.SecurityModeMessage;
|
||||
import mekanism.common.security.ISecurityItem;
|
||||
import mekanism.common.security.ISecurityTile;
|
||||
import mekanism.common.security.ISecurityTile.SecurityMode;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
@@ -18,15 +20,27 @@ public class PacketSecurityMode implements IMessageHandler<SecurityModeMessage,
|
||||
public IMessage onMessage(SecurityModeMessage message, MessageContext context)
|
||||
{
|
||||
EntityPlayer player = PacketHandler.getPlayer(context);
|
||||
TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj);
|
||||
|
||||
if(tileEntity instanceof ISecurityTile)
|
||||
if(message.packetType == SecurityPacketType.BLOCK)
|
||||
{
|
||||
String owner = ((ISecurityTile)tileEntity).getSecurity().getOwner();
|
||||
TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj);
|
||||
|
||||
if(owner != null && player.getCommandSenderName().equals(owner))
|
||||
if(tileEntity instanceof ISecurityTile)
|
||||
{
|
||||
((ISecurityTile)tileEntity).getSecurity().setMode(message.value);
|
||||
String owner = ((ISecurityTile)tileEntity).getSecurity().getOwner();
|
||||
|
||||
if(owner != null && player.getCommandSenderName().equals(owner))
|
||||
{
|
||||
((ISecurityTile)tileEntity).getSecurity().setMode(message.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
ItemStack stack = player.getCurrentEquippedItem();
|
||||
|
||||
if(stack.getItem() instanceof ISecurityItem)
|
||||
{
|
||||
((ISecurityItem)stack.getItem()).setSecurity(stack, message.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +49,7 @@ public class PacketSecurityMode implements IMessageHandler<SecurityModeMessage,
|
||||
|
||||
public static class SecurityModeMessage implements IMessage
|
||||
{
|
||||
public SecurityPacketType packetType;
|
||||
public Coord4D coord4D;
|
||||
public SecurityMode value;
|
||||
|
||||
@@ -42,17 +57,31 @@ public class PacketSecurityMode implements IMessageHandler<SecurityModeMessage,
|
||||
|
||||
public SecurityModeMessage(Coord4D coord, SecurityMode control)
|
||||
{
|
||||
packetType = SecurityPacketType.BLOCK;
|
||||
|
||||
coord4D = coord;
|
||||
value = control;
|
||||
}
|
||||
|
||||
public SecurityModeMessage(SecurityMode control)
|
||||
{
|
||||
packetType = SecurityPacketType.ITEM;
|
||||
|
||||
value = control;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf dataStream)
|
||||
{
|
||||
dataStream.writeInt(coord4D.xCoord);
|
||||
dataStream.writeInt(coord4D.yCoord);
|
||||
dataStream.writeInt(coord4D.zCoord);
|
||||
dataStream.writeInt(coord4D.dimensionId);
|
||||
dataStream.writeInt(packetType.ordinal());
|
||||
|
||||
if(packetType == SecurityPacketType.BLOCK)
|
||||
{
|
||||
dataStream.writeInt(coord4D.xCoord);
|
||||
dataStream.writeInt(coord4D.yCoord);
|
||||
dataStream.writeInt(coord4D.zCoord);
|
||||
dataStream.writeInt(coord4D.dimensionId);
|
||||
}
|
||||
|
||||
dataStream.writeInt(value.ordinal());
|
||||
}
|
||||
@@ -60,8 +89,20 @@ public class PacketSecurityMode implements IMessageHandler<SecurityModeMessage,
|
||||
@Override
|
||||
public void fromBytes(ByteBuf dataStream)
|
||||
{
|
||||
coord4D = Coord4D.read(dataStream);
|
||||
packetType = SecurityPacketType.values()[dataStream.readInt()];
|
||||
|
||||
if(packetType == SecurityPacketType.BLOCK)
|
||||
{
|
||||
coord4D = Coord4D.read(dataStream);
|
||||
}
|
||||
|
||||
value = SecurityMode.values()[dataStream.readInt()];
|
||||
}
|
||||
}
|
||||
|
||||
public static enum SecurityPacketType
|
||||
{
|
||||
BLOCK,
|
||||
ITEM
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user