diff --git a/src/main/java/mekanism/client/gui/GuiFormulaicAssemblicator.java b/src/main/java/mekanism/client/gui/GuiFormulaicAssemblicator.java index c6ffa935f..6d06c1fe5 100644 --- a/src/main/java/mekanism/client/gui/GuiFormulaicAssemblicator.java +++ b/src/main/java/mekanism/client/gui/GuiFormulaicAssemblicator.java @@ -199,6 +199,7 @@ public class GuiFormulaicAssemblicator extends GuiMekanism GL11.glPushMatrix(); GL11.glEnable(GL11.GL_LIGHTING); MekanismRenderer.blendOn(); + GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.4F); itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.getTextureManager(), stack, guiWidth + slot.xDisplayPosition, guiHeight + slot.yDisplayPosition); MekanismRenderer.blendOff(); GL11.glDisable(GL11.GL_LIGHTING); diff --git a/src/main/java/mekanism/client/gui/element/GuiRedstoneControl.java b/src/main/java/mekanism/client/gui/element/GuiRedstoneControl.java index 8f1018b11..02ae61822 100644 --- a/src/main/java/mekanism/client/gui/element/GuiRedstoneControl.java +++ b/src/main/java/mekanism/client/gui/element/GuiRedstoneControl.java @@ -12,7 +12,10 @@ import mekanism.common.util.MekanismUtils.ResourceType; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ResourceLocation; import codechicken.lib.vec.Rectangle4i; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +@SideOnly(Side.CLIENT) public class GuiRedstoneControl extends GuiElement { TileEntity tileEntity; diff --git a/src/main/java/mekanism/client/gui/element/GuiSecurityTab.java b/src/main/java/mekanism/client/gui/element/GuiSecurityTab.java new file mode 100644 index 000000000..bb7893610 --- /dev/null +++ b/src/main/java/mekanism/client/gui/element/GuiSecurityTab.java @@ -0,0 +1,107 @@ +package mekanism.client.gui.element; + +import mekanism.api.Coord4D; +import mekanism.api.EnumColor; +import mekanism.api.util.ListUtils; +import mekanism.client.gui.IGuiWrapper; +import mekanism.client.sound.SoundHandler; +import mekanism.common.Mekanism; +import mekanism.common.network.PacketSecurityMode.SecurityModeMessage; +import mekanism.common.security.ISecurity; +import mekanism.common.security.ISecurity.SecurityMode; +import mekanism.common.util.LangUtils; +import mekanism.common.util.MekanismUtils; +import mekanism.common.util.MekanismUtils.ResourceType; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ResourceLocation; +import codechicken.lib.vec.Rectangle4i; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class GuiSecurityTab extends GuiElement +{ + TileEntity tileEntity; + + public GuiSecurityTab(IGuiWrapper gui, TileEntity tile, ResourceLocation def) + { + super(MekanismUtils.getResource(ResourceType.GUI_ELEMENT, "GuiSecurityTab.png"), gui, def); + + tileEntity = tile; + } + + @Override + public Rectangle4i getBounds(int guiWidth, int guiHeight) + { + return new Rectangle4i(guiWidth + 176, guiHeight + 32, 26, 26); + } + + @Override + public void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight) + { + mc.renderEngine.bindTexture(RESOURCE); + + guiObj.drawTexturedRect(guiWidth + 176, guiHeight + 32, 0, 0, 26, 26); + + ISecurity tile = (ISecurity)tileEntity; + int renderX = 26 + (18*tile.getSecurity().getMode().ordinal()); + + if(tile.getSecurity().getOwner() != null && tile.getSecurity().getOwner().equals(mc.thePlayer.getCommandSenderName())) + { + if(xAxis >= 179 && xAxis <= 197 && yAxis >= 36 && yAxis <= 54) + { + guiObj.drawTexturedRect(guiWidth + 179, guiHeight + 36, renderX, 0, 18, 18); + } + else { + guiObj.drawTexturedRect(guiWidth + 179, guiHeight + 36, renderX, 18, 18, 18); + } + } + else { + guiObj.drawTexturedRect(guiWidth + 179, guiHeight + 36, renderX, 36, 18, 18); + } + + mc.renderEngine.bindTexture(defaultLocation); + } + + @Override + public void renderForeground(int xAxis, int yAxis) + { + mc.renderEngine.bindTexture(RESOURCE); + + ISecurity control = (ISecurity)tileEntity; + + if(xAxis >= 179 && xAxis <= 197 && yAxis >= 36 && yAxis <= 54) + { + String securityText = EnumColor.GREY + LangUtils.localize("gui.security") + ": " + control.getSecurity().getMode().getDisplay(); + String ownerText = ISecurity.getOwnerDisplay(mc.thePlayer.getCommandSenderName(), control.getSecurity().getOwner()); + + displayTooltips(ListUtils.asList(securityText, ownerText), xAxis, yAxis); + } + + mc.renderEngine.bindTexture(defaultLocation); + } + + @Override + public void preMouseClicked(int xAxis, int yAxis, int button) {} + + @Override + public void mouseClicked(int xAxis, int yAxis, int button) + { + ISecurity control = (ISecurity)tileEntity; + + if(button == 0) + { + if(control.getSecurity().getOwner() != null && mc.thePlayer.getCommandSenderName().equals(control.getSecurity().getOwner())) + { + if(xAxis >= 179 && xAxis <= 197 && yAxis >= 36 && yAxis <= 54) + { + SecurityMode current = control.getSecurity().getMode(); + int ordinalToSet = current.ordinal() < (SecurityMode.values().length-1) ? current.ordinal()+1 : 0; + + SoundHandler.playSound("gui.button.press"); + Mekanism.packetHandler.sendToServer(new SecurityModeMessage(Coord4D.get(tileEntity), SecurityMode.values()[ordinalToSet])); + } + } + } + } +} diff --git a/src/main/java/mekanism/common/HashList.java b/src/main/java/mekanism/common/HashList.java index 2d932f4ce..5d1ed660b 100644 --- a/src/main/java/mekanism/common/HashList.java +++ b/src/main/java/mekanism/common/HashList.java @@ -91,17 +91,17 @@ public class HashList implements Iterable return list.size(); } - public void swap( int source, int target ) + public void swap(int source, int target) { - // Make sure both source and target ar legal values - if( source == target ) return; - if( source < 0 || target < 0 ) return; - if( source >= list.size() || target >= list.size() ) return; + // Make sure both source and target are legal values + if(source == target) return; + if(source < 0 || target < 0) return; + if(source >= list.size() || target >= list.size()) return; // Perform swap - T temp = list.get( source ); - list.set( source, list.get( target ) ); - list.set( target, temp ); + T temp = list.get(source); + list.set(source, list.get( target)); + list.set(target, temp); } @Override diff --git a/src/main/java/mekanism/common/Mekanism.java b/src/main/java/mekanism/common/Mekanism.java index da863a21e..bff0f0c32 100644 --- a/src/main/java/mekanism/common/Mekanism.java +++ b/src/main/java/mekanism/common/Mekanism.java @@ -73,6 +73,7 @@ import mekanism.common.recipe.ShapelessMekanismRecipe; import mekanism.common.recipe.inputs.ItemStackInput; import mekanism.common.recipe.machines.SmeltingRecipe; import mekanism.common.recipe.outputs.ItemStackOutput; +import mekanism.common.security.SecurityFrequency; import mekanism.common.tile.TileEntityAdvancedBoundingBlock; import mekanism.common.tile.TileEntityBoundingBlock; import mekanism.common.tile.TileEntityCardboardBox; @@ -183,6 +184,8 @@ public class Mekanism public static FrequencyManager publicEntangloporters = new FrequencyManager(InventoryFrequency.class, "Entangloporter"); public static Map privateEntangloporters = new HashMap(); + public static FrequencyManager securityFrequencies = new FrequencyManager(SecurityFrequency.class, "Security"); + /** Mekanism creative tab */ public static CreativeTabMekanism tabMekanism = new CreativeTabMekanism(); diff --git a/src/main/java/mekanism/common/PacketHandler.java b/src/main/java/mekanism/common/PacketHandler.java index 03e85ab3b..08c32f438 100644 --- a/src/main/java/mekanism/common/PacketHandler.java +++ b/src/main/java/mekanism/common/PacketHandler.java @@ -55,6 +55,8 @@ import mekanism.common.network.PacketRobit; import mekanism.common.network.PacketRobit.RobitMessage; import mekanism.common.network.PacketScubaTankData; import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage; +import mekanism.common.network.PacketSecurityMode; +import mekanism.common.network.PacketSecurityMode.SecurityModeMessage; import mekanism.common.network.PacketSimpleGui; import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage; import mekanism.common.network.PacketTileEntity; @@ -102,7 +104,7 @@ public class PacketHandler netHandler.registerMessage(PacketDataRequest.class, DataRequestMessage.class, 7, Side.SERVER); netHandler.registerMessage(PacketOredictionificatorGui.class, OredictionificatorGuiMessage.class, 8, Side.CLIENT); netHandler.registerMessage(PacketOredictionificatorGui.class, OredictionificatorGuiMessage.class, 8, Side.SERVER); - //EMPTY SLOT 9 + netHandler.registerMessage(PacketSecurityMode.class, SecurityModeMessage.class, 9, Side.SERVER); netHandler.registerMessage(PacketPortableTeleporter.class, PortableTeleporterMessage.class, 10, Side.CLIENT); netHandler.registerMessage(PacketPortableTeleporter.class, PortableTeleporterMessage.class, 10, Side.SERVER); netHandler.registerMessage(PacketRemoveUpgrade.class, RemoveUpgradeMessage.class, 11, Side.SERVER); diff --git a/src/main/java/mekanism/common/base/ITileComponent.java b/src/main/java/mekanism/common/base/ITileComponent.java index d69119553..d14126ade 100644 --- a/src/main/java/mekanism/common/base/ITileComponent.java +++ b/src/main/java/mekanism/common/base/ITileComponent.java @@ -17,4 +17,6 @@ public interface ITileComponent public void write(NBTTagCompound nbtTags); public void write(ArrayList data); + + public void invalidate(); } diff --git a/src/main/java/mekanism/common/network/PacketSecurityMode.java b/src/main/java/mekanism/common/network/PacketSecurityMode.java new file mode 100644 index 000000000..3cbc4b3da --- /dev/null +++ b/src/main/java/mekanism/common/network/PacketSecurityMode.java @@ -0,0 +1,67 @@ +package mekanism.common.network; + +import io.netty.buffer.ByteBuf; +import mekanism.api.Coord4D; +import mekanism.common.PacketHandler; +import mekanism.common.network.PacketSecurityMode.SecurityModeMessage; +import mekanism.common.security.ISecurity; +import mekanism.common.security.ISecurity.SecurityMode; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; + +public class PacketSecurityMode implements IMessageHandler +{ + @Override + public IMessage onMessage(SecurityModeMessage message, MessageContext context) + { + EntityPlayer player = PacketHandler.getPlayer(context); + TileEntity tileEntity = message.coord4D.getTileEntity(player.worldObj); + + if(tileEntity instanceof ISecurity) + { + String owner = ((ISecurity)tileEntity).getSecurity().getOwner(); + + if(owner != null && player.getCommandSenderName().equals(owner)) + { + ((ISecurity)tileEntity).getSecurity().setMode(message.value); + } + } + + return null; + } + + public static class SecurityModeMessage implements IMessage + { + public Coord4D coord4D; + public SecurityMode value; + + public SecurityModeMessage() {} + + public SecurityModeMessage(Coord4D coord, SecurityMode control) + { + coord4D = coord; + 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(value.ordinal()); + } + + @Override + public void fromBytes(ByteBuf dataStream) + { + coord4D = Coord4D.read(dataStream); + value = SecurityMode.values()[dataStream.readInt()]; + } + } +} diff --git a/src/main/java/mekanism/common/security/ISecurity.java b/src/main/java/mekanism/common/security/ISecurity.java new file mode 100644 index 000000000..1704a6557 --- /dev/null +++ b/src/main/java/mekanism/common/security/ISecurity.java @@ -0,0 +1,106 @@ +package mekanism.common.security; + +import mekanism.api.EnumColor; +import mekanism.common.Mekanism; +import mekanism.common.frequency.Frequency; +import mekanism.common.tile.component.TileComponentSecurity; +import mekanism.common.util.LangUtils; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; + +public interface ISecurity +{ + public TileComponentSecurity getSecurity(); + + public enum SecurityMode + { + PUBLIC(EnumColor.BRIGHT_GREEN + "security.public"), + PRIVATE(EnumColor.RED + "security.private"), + TRUSTED(EnumColor.ORANGE + "security.trusted"); + + private String display; + private EnumColor color; + + public String getDisplay() + { + return color + LangUtils.localize(display); + } + + private SecurityMode(String s) + { + display = s; + } + } + + public static boolean canAccess(EntityPlayer player, ItemStack stack) + { + if(stack == null || !(stack.getItem() instanceof ISecurityItem)) + { + return true; + } + + ISecurityItem security = (ISecurityItem)stack.getItem(); + + return canAccess(security.getSecurity(stack), player.getCommandSenderName(), security.getOwner(stack)); + } + + public static boolean canAccess(EntityPlayer player, TileEntity tile) + { + if(tile == null || !(tile instanceof ISecurity)) + { + return true; + } + + ISecurity security = (ISecurity)tile; + + return canAccess(security.getSecurity().getMode(), player.getCommandSenderName(), security.getSecurity().getOwner()); + } + + public static boolean canAccess(SecurityMode mode, String username, String owner) + { + if(owner == null || username.equals(owner)) + { + return true; + } + + if(mode == SecurityMode.PUBLIC) + { + return true; + } + else if(mode == SecurityMode.TRUSTED) + { + SecurityFrequency freq = getFrequency(owner); + + if(freq == null || freq.trusted.contains(username)) + { + return true; + } + } + + return false; + } + + public static SecurityFrequency getFrequency(String owner) + { + for(Frequency f : Mekanism.securityFrequencies.getFrequencies()) + { + if(f instanceof SecurityFrequency && f.owner.equals(owner)) + { + return (SecurityFrequency)f; + } + } + + return null; + } + + public static String getOwnerDisplay(String user, String owner) + { + if(owner == null) + { + return EnumColor.RED + LangUtils.localize("gui.noOwner"); + } + + return EnumColor.GREY + LangUtils.localize("gui.owner") + ": " + (user.equals(owner) ? EnumColor.BRIGHT_GREEN : EnumColor.RED) + owner; + } +} diff --git a/src/main/java/mekanism/common/security/ISecurityItem.java b/src/main/java/mekanism/common/security/ISecurityItem.java new file mode 100644 index 000000000..413cf2e6a --- /dev/null +++ b/src/main/java/mekanism/common/security/ISecurityItem.java @@ -0,0 +1,15 @@ +package mekanism.common.security; + +import mekanism.common.security.ISecurity.SecurityMode; +import net.minecraft.item.ItemStack; + +public interface ISecurityItem +{ + public String getOwner(ItemStack stack); + + public void setOwner(ItemStack stack, String owner); + + public SecurityMode getSecurity(ItemStack stack); + + public void setSecurity(ItemStack stack, SecurityMode mode); +} diff --git a/src/main/java/mekanism/common/security/SecurityFrequency.java b/src/main/java/mekanism/common/security/SecurityFrequency.java new file mode 100644 index 000000000..d028ade24 --- /dev/null +++ b/src/main/java/mekanism/common/security/SecurityFrequency.java @@ -0,0 +1,111 @@ +package mekanism.common.security; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; + +import mekanism.common.HashList; +import mekanism.common.PacketHandler; +import mekanism.common.frequency.Frequency; +import mekanism.common.security.ISecurity.SecurityMode; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraftforge.common.util.Constants.NBT; + +public class SecurityFrequency extends Frequency +{ + public boolean override; + + public HashList trusted = new HashList(); + + public SecurityMode securityMode = SecurityMode.PUBLIC; + + public SecurityFrequency(String o) + { + super("Security", o); + } + + public SecurityFrequency(NBTTagCompound nbtTags) + { + super(nbtTags); + } + + public SecurityFrequency(ByteBuf dataStream) + { + super(dataStream); + } + + @Override + public void write(NBTTagCompound nbtTags) + { + super.write(nbtTags); + + nbtTags.setBoolean("override", override); + nbtTags.setInteger("securityMode", securityMode.ordinal()); + + if(!trusted.isEmpty()) + { + NBTTagList trustedList = new NBTTagList(); + + for(String s : trusted) + { + trustedList.appendTag(new NBTTagString(s)); + } + + nbtTags.setTag("trusted", trustedList); + } + } + + @Override + protected void read(NBTTagCompound nbtTags) + { + super.read(nbtTags); + + override = nbtTags.getBoolean("override"); + securityMode = SecurityMode.values()[nbtTags.getInteger("securityMode")]; + + if(nbtTags.hasKey("trusted")) + { + NBTTagList trustedList = nbtTags.getTagList("trusted", NBT.TAG_STRING); + + for(int i = 0; i < trustedList.tagCount(); i++) + { + trusted.add(trustedList.getStringTagAt(i)); + } + } + } + + @Override + public void write(ArrayList data) + { + super.write(data); + + data.add(override); + data.add(securityMode.ordinal()); + + data.add(trusted.size()); + + for(String s : trusted) + { + data.add(trusted); + } + } + + @Override + protected void read(ByteBuf dataStream) + { + super.read(dataStream); + + override = dataStream.readBoolean(); + securityMode = SecurityMode.values()[dataStream.readInt()]; + + trusted.clear(); + int size = dataStream.readInt(); + + for(int i = 0; i < size; i++) + { + trusted.add(PacketHandler.readString(dataStream)); + } + } +} diff --git a/src/main/java/mekanism/common/tile/TileEntityBasicBlock.java b/src/main/java/mekanism/common/tile/TileEntityBasicBlock.java index 454d23d24..19d45b1f0 100644 --- a/src/main/java/mekanism/common/tile/TileEntityBasicBlock.java +++ b/src/main/java/mekanism/common/tile/TileEntityBasicBlock.java @@ -137,6 +137,17 @@ public abstract class TileEntityBasicBlock extends TileEntity implements IWrench return data; } + + @Override + public void invalidate() + { + super.invalidate(); + + for(ITileComponent component : components) + { + component.invalidate(); + } + } @Override public void validate() diff --git a/src/main/java/mekanism/common/tile/TileEntityQuantumEntangloporter.java b/src/main/java/mekanism/common/tile/TileEntityQuantumEntangloporter.java index 8cec6ce40..07e6ce3ac 100644 --- a/src/main/java/mekanism/common/tile/TileEntityQuantumEntangloporter.java +++ b/src/main/java/mekanism/common/tile/TileEntityQuantumEntangloporter.java @@ -192,11 +192,6 @@ public class TileEntityQuantumEntangloporter extends TileEntityElectricBlock imp public void setFrequency(String name, boolean publicFreq) { - if(name.equals(frequency)) - { - return; - } - FrequencyManager manager = getManager(new InventoryFrequency(name, null).setPublic(publicFreq)); manager.deactivate(Coord4D.get(this)); diff --git a/src/main/java/mekanism/common/tile/TileEntityTeleporter.java b/src/main/java/mekanism/common/tile/TileEntityTeleporter.java index 9460e8ca2..25117e502 100644 --- a/src/main/java/mekanism/common/tile/TileEntityTeleporter.java +++ b/src/main/java/mekanism/common/tile/TileEntityTeleporter.java @@ -165,11 +165,6 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements ICo public void setFrequency(String name, boolean publicFreq) { - if(name.equals(frequency)) - { - return; - } - FrequencyManager manager = getManager(new Frequency(name, null).setPublic(publicFreq)); manager.deactivate(Coord4D.get(this)); diff --git a/src/main/java/mekanism/common/tile/component/TileComponentConfig.java b/src/main/java/mekanism/common/tile/component/TileComponentConfig.java index 9a359b920..b074c2675 100644 --- a/src/main/java/mekanism/common/tile/component/TileComponentConfig.java +++ b/src/main/java/mekanism/common/tile/component/TileComponentConfig.java @@ -216,6 +216,9 @@ public class TileComponentConfig implements ITileComponent } } + @Override + public void invalidate() {} + public boolean isEjecting(TransmissionType type) { return ejecting.get(type.ordinal()); diff --git a/src/main/java/mekanism/common/tile/component/TileComponentEjector.java b/src/main/java/mekanism/common/tile/component/TileComponentEjector.java index c239d29f0..305534e6f 100644 --- a/src/main/java/mekanism/common/tile/component/TileComponentEjector.java +++ b/src/main/java/mekanism/common/tile/component/TileComponentEjector.java @@ -374,6 +374,9 @@ public class TileComponentEjector implements ITileComponent } } + @Override + public void invalidate() {} + private boolean getEjecting(TransmissionType type) { return ((ISideConfiguration)tileEntity).getConfig().isEjecting(type); diff --git a/src/main/java/mekanism/common/tile/component/TileComponentSecurity.java b/src/main/java/mekanism/common/tile/component/TileComponentSecurity.java new file mode 100644 index 000000000..c7a39147f --- /dev/null +++ b/src/main/java/mekanism/common/tile/component/TileComponentSecurity.java @@ -0,0 +1,220 @@ +package mekanism.common.tile.component; + +import io.netty.buffer.ByteBuf; + +import java.util.ArrayList; + +import mekanism.api.Coord4D; +import mekanism.common.Mekanism; +import mekanism.common.PacketHandler; +import mekanism.common.base.ITileComponent; +import mekanism.common.frequency.Frequency; +import mekanism.common.frequency.FrequencyManager; +import mekanism.common.security.ISecurity.SecurityMode; +import mekanism.common.security.SecurityFrequency; +import mekanism.common.tile.TileEntityContainerBlock; +import mekanism.common.util.MekanismUtils; +import net.minecraft.nbt.NBTTagCompound; + +public class TileComponentSecurity implements ITileComponent +{ + /** TileEntity implementing this component. */ + public TileEntityContainerBlock tileEntity; + + private String owner; + + private SecurityMode securityMode = SecurityMode.PUBLIC; + + private SecurityFrequency frequency; + + public TileComponentSecurity(TileEntityContainerBlock tile) + { + tileEntity = tile; + + tile.components.add(this); + } + + public String getOwner() + { + return owner; + } + + public void setOwner(String o) + { + frequency = null; + owner = o; + } + + public SecurityMode getMode() + { + return securityMode; + } + + public void setMode(SecurityMode mode) + { + securityMode = mode; + } + + public FrequencyManager getManager(Frequency freq) + { + if(owner == null || freq == null) + { + return null; + } + + return Mekanism.securityFrequencies; + } + + public void setFrequency(String owner) + { + FrequencyManager manager = Mekanism.securityFrequencies; + manager.deactivate(Coord4D.get(tileEntity)); + + for(Frequency freq : manager.getFrequencies()) + { + if(freq.owner.equals(owner)) + { + frequency = (SecurityFrequency)freq; + frequency.activeCoords.add(Coord4D.get(tileEntity)); + + return; + } + } + + Frequency freq = new SecurityFrequency(owner).setPublic(true); + freq.activeCoords.add(Coord4D.get(tileEntity)); + manager.addFrequency(freq); + frequency = (SecurityFrequency)freq; + + MekanismUtils.saveChunk(tileEntity); + tileEntity.markDirty(); + } + + @Override + public void tick() + { + if(!tileEntity.getWorldObj().isRemote) + { + if(frequency == null && owner != null) + { + setFrequency(owner); + } + + FrequencyManager manager = getManager(frequency); + + if(manager != null) + { + if(frequency != null && !frequency.valid) + { + frequency = (SecurityFrequency)manager.validateFrequency(owner, Coord4D.get(tileEntity), frequency); + } + + if(frequency != null) + { + frequency = (SecurityFrequency)manager.update(owner, Coord4D.get(tileEntity), frequency); + } + } + else { + frequency = null; + } + } + } + + @Override + public void read(NBTTagCompound nbtTags) + { + securityMode = SecurityMode.values()[nbtTags.getInteger("securityMode")]; + + if(nbtTags.hasKey("owner")) + { + owner = nbtTags.getString("owner"); + } + + if(nbtTags.hasKey("frequency")) + { + frequency = new SecurityFrequency(nbtTags.getCompoundTag("frequency")); + frequency.valid = false; + } + } + + @Override + public void read(ByteBuf dataStream) + { + securityMode = SecurityMode.values()[dataStream.readInt()]; + + if(dataStream.readBoolean()) + { + owner = PacketHandler.readString(dataStream); + } + else { + owner = null; + } + + if(dataStream.readBoolean()) + { + frequency = new SecurityFrequency(dataStream); + } + else { + frequency = null; + } + } + + @Override + public void write(NBTTagCompound nbtTags) + { + nbtTags.setInteger("securityMode", securityMode.ordinal()); + + if(owner != null) + { + nbtTags.setString("owner", owner); + } + + if(frequency != null) + { + NBTTagCompound frequencyTag = new NBTTagCompound(); + frequency.write(frequencyTag); + nbtTags.setTag("frequency", frequencyTag); + } + } + + @Override + public void write(ArrayList data) + { + data.add(securityMode.ordinal()); + + if(owner != null) + { + data.add(true); + data.add(owner); + } + else { + data.add(false); + } + + if(frequency != null) + { + data.add(true); + frequency.write(data); + } + else { + data.add(false); + } + } + + @Override + public void invalidate() + { + if(!tileEntity.getWorldObj().isRemote) + { + if(frequency != null) + { + FrequencyManager manager = getManager(frequency); + + if(manager != null) + { + manager.deactivate(Coord4D.get(tileEntity)); + } + } + } + } +} diff --git a/src/main/java/mekanism/common/tile/component/TileComponentUpgrade.java b/src/main/java/mekanism/common/tile/component/TileComponentUpgrade.java index 94f1662de..71f10d3fb 100644 --- a/src/main/java/mekanism/common/tile/component/TileComponentUpgrade.java +++ b/src/main/java/mekanism/common/tile/component/TileComponentUpgrade.java @@ -226,4 +226,7 @@ public class TileComponentUpgrade implements ITileComponent { Upgrade.saveMap(upgrades, nbtTags); } + + @Override + public void invalidate() {} } diff --git a/src/main/resources/assets/mekanism/gui/GuiSecurityDesk.png b/src/main/resources/assets/mekanism/gui/GuiSecurityDesk.png new file mode 100644 index 000000000..72dd35c61 Binary files /dev/null and b/src/main/resources/assets/mekanism/gui/GuiSecurityDesk.png differ diff --git a/src/main/resources/assets/mekanism/gui/elements/GuiSecurityTab.png b/src/main/resources/assets/mekanism/gui/elements/GuiSecurityTab.png new file mode 100644 index 000000000..79ee90ed6 Binary files /dev/null and b/src/main/resources/assets/mekanism/gui/elements/GuiSecurityTab.png differ diff --git a/src/main/resources/assets/mekanism/lang/en_US.lang b/src/main/resources/assets/mekanism/lang/en_US.lang index f9066ecfb..d0c50a4bf 100644 --- a/src/main/resources/assets/mekanism/lang/en_US.lang +++ b/src/main/resources/assets/mekanism/lang/en_US.lang @@ -540,6 +540,7 @@ gui.autoModeToggle=Turn Auto-Mode gui.craftSingle=Craft Single Item gui.craftAvailable=Craft Available Items gui.fillEmpty=Fill/Empty Grid +gui.noOwner=No Owner gui.reactor.injectionRate=Injection Rate