Extend security to generators, gas tanks and energy cubes

This commit is contained in:
aidancbrady 2016-03-21 23:14:38 -04:00
parent b83257d83b
commit 5ed86f3f01
17 changed files with 509 additions and 58 deletions

View file

@ -9,6 +9,7 @@ import mekanism.client.gui.element.GuiEnergyGauge;
import mekanism.client.gui.element.GuiEnergyGauge.IEnergyInfoHandler;
import mekanism.client.gui.element.GuiEnergyInfo;
import mekanism.client.gui.element.GuiRedstoneControl;
import mekanism.client.gui.element.GuiSecurityTab;
import mekanism.client.gui.element.GuiSideConfigurationTab;
import mekanism.client.gui.element.GuiSlot;
import mekanism.client.gui.element.GuiSlot.SlotOverlay;
@ -36,6 +37,7 @@ public class GuiEnergyCube extends GuiMekanism
super(tentity, new ContainerEnergyCube(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiEnergyCube.png")));
guiElements.add(new GuiSecurityTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiEnergyCube.png")));
guiElements.add(new GuiSideConfigurationTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiEnergyCube.png")));
guiElements.add(new GuiTransporterConfigTab(this, 34, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiEnergyCube.png")));
guiElements.add(new GuiEnergyGauge(new IEnergyInfoHandler()

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import mekanism.api.Coord4D;
import mekanism.client.gui.element.GuiRedstoneControl;
import mekanism.client.gui.element.GuiSecurityTab;
import mekanism.client.gui.element.GuiSideConfigurationTab;
import mekanism.client.gui.element.GuiSlot;
import mekanism.client.gui.element.GuiSlot.SlotOverlay;
@ -34,6 +35,7 @@ public class GuiGasTank extends GuiMekanism
super(tentity, new ContainerGasTank(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiGasTank.png")));
guiElements.add(new GuiSecurityTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiGasTank.png")));
guiElements.add(new GuiSideConfigurationTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiGasTank.png")));
guiElements.add(new GuiTransporterConfigTab(this, 34, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiGasTank.png")));
guiElements.add(new GuiSlot(SlotType.OUTPUT, this, MekanismUtils.getResource(ResourceType.GUI, "GuiGasTank.png"), 7, 7).with(SlotOverlay.PLUS));

View file

@ -10,9 +10,13 @@ import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.base.IEnergyCube;
import mekanism.common.base.ISustainedInventory;
import mekanism.common.item.ItemBlockEnergyCube;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.security.ISecurityTile.SecurityMode;
import mekanism.common.tile.TileEntityBasicBlock;
import mekanism.common.tile.TileEntityEnergyCube;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.SecurityUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@ -23,6 +27,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
@ -132,6 +137,19 @@ public class BlockEnergyCube extends BlockContainer
list.add(charged);
}
}
@Override
public float getBlockHardness(World world, int x, int y, int z)
{
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof ISecurityTile)
{
return SecurityUtils.getSecurity((ISecurityTile)tile) == SecurityMode.PUBLIC ? blockHardness : -1;
}
return blockHardness;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float f1, float f2, float f3)
@ -149,21 +167,28 @@ public class BlockEnergyCube extends BlockContainer
if(MekanismUtils.hasUsableWrench(entityplayer, x, y, z))
{
if(entityplayer.isSneaking())
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
dismantleBlock(world, x, y, z, false);
return true;
if(entityplayer.isSneaking())
{
dismantleBlock(world, x, y, z, false);
return true;
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench) tool).wrenchUsed(entityplayer, x, y, z);
}
int change = ForgeDirection.ROTATION_MATRIX[side][tileEntity.facing];
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, this);
}
else {
SecurityUtils.displayNoAccess(entityplayer);
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench) tool).wrenchUsed(entityplayer, x, y, z);
}
int change = ForgeDirection.ROTATION_MATRIX[side][tileEntity.facing];
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, this);
return true;
}
@ -173,7 +198,14 @@ public class BlockEnergyCube extends BlockContainer
{
if(!entityplayer.isSneaking())
{
entityplayer.openGui(Mekanism.instance, 8, world, x, y, z);
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
entityplayer.openGui(Mekanism.instance, 8, world, x, y, z);
}
else {
SecurityUtils.displayNoAccess(entityplayer);
}
return true;
}
}
@ -227,6 +259,22 @@ public class BlockEnergyCube extends BlockContainer
{
TileEntityEnergyCube tileEntity = (TileEntityEnergyCube)world.getTileEntity(x, y, z);
ItemStack itemStack = new ItemStack(MekanismBlocks.EnergyCube);
if(itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
if(tileEntity instanceof ISecurityTile)
{
ISecurityItem securityItem = (ISecurityItem)itemStack.getItem();
if(securityItem.hasSecurity(itemStack))
{
securityItem.setOwner(itemStack, ((ISecurityTile)tileEntity).getSecurity().getOwner());
securityItem.setSecurity(itemStack, ((ISecurityTile)tileEntity).getSecurity().getMode());
}
}
IEnergyCube energyCube = (IEnergyCube)itemStack.getItem();
energyCube.setEnergyCubeTier(itemStack, tileEntity.tier);

View file

@ -7,9 +7,13 @@ import mekanism.common.Mekanism;
import mekanism.common.MekanismBlocks;
import mekanism.common.base.ISustainedInventory;
import mekanism.common.base.ITierItem;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.security.ISecurityTile.SecurityMode;
import mekanism.common.tile.TileEntityBasicBlock;
import mekanism.common.tile.TileEntityGasTank;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.SecurityUtils;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
@ -19,6 +23,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
@ -79,6 +84,19 @@ public class BlockGasTank extends BlockContainer
}
}
}
@Override
public float getBlockHardness(World world, int x, int y, int z)
{
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof ISecurityTile)
{
return SecurityUtils.getSecurity((ISecurityTile)tile) == SecurityMode.PUBLIC ? blockHardness : -1;
}
return blockHardness;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int side, float playerX, float playerY, float playerZ)
@ -96,21 +114,28 @@ public class BlockGasTank extends BlockContainer
if(MekanismUtils.hasUsableWrench(entityplayer, x, y, z))
{
if(entityplayer.isSneaking())
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
dismantleBlock(world, x, y, z, false);
return true;
if(entityplayer.isSneaking())
{
dismantleBlock(world, x, y, z, false);
return true;
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench)tool).wrenchUsed(entityplayer, x, y, z);
}
int change = ForgeDirection.ROTATION_MATRIX[ForgeDirection.UP.ordinal()][tileEntity.facing];
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, this);
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench)tool).wrenchUsed(entityplayer, x, y, z);
else {
SecurityUtils.displayNoAccess(entityplayer);
}
int change = ForgeDirection.ROTATION_MATRIX[ForgeDirection.UP.ordinal()][tileEntity.facing];
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, this);
return true;
}
@ -120,7 +145,14 @@ public class BlockGasTank extends BlockContainer
{
if(!entityplayer.isSneaking())
{
entityplayer.openGui(Mekanism.instance, 10, world, x, y, z);
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
entityplayer.openGui(Mekanism.instance, 10, world, x, y, z);
}
else {
SecurityUtils.displayNoAccess(entityplayer);
}
return true;
}
}
@ -209,6 +241,22 @@ public class BlockGasTank extends BlockContainer
TileEntityGasTank tileEntity = (TileEntityGasTank)world.getTileEntity(x, y, z);
ItemStack itemStack = new ItemStack(MekanismBlocks.GasTank);
if(itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
if(tileEntity instanceof ISecurityTile)
{
ISecurityItem securityItem = (ISecurityItem)itemStack.getItem();
if(securityItem.hasSecurity(itemStack))
{
securityItem.setOwner(itemStack, ((ISecurityTile)tileEntity).getSecurity().getOwner());
securityItem.setSecurity(itemStack, ((ISecurityTile)tileEntity).getSecurity().getMode());
}
}
ITierItem tierItem = (ITierItem)itemStack.getItem();
tierItem.setBaseTier(itemStack, tileEntity.tier.getBaseTier());

View file

@ -960,8 +960,12 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds, IBlo
if(tileEntity instanceof ISecurityTile)
{
ISecurityItem securityItem = (ISecurityItem)itemStack.getItem();
securityItem.setOwner(itemStack, ((ISecurityTile)tileEntity).getSecurity().getOwner());
securityItem.setSecurity(itemStack, ((ISecurityTile)tileEntity).getSecurity().getMode());
if(securityItem.hasSecurity(itemStack))
{
securityItem.setOwner(itemStack, ((ISecurityTile)tileEntity).getSecurity().getOwner());
securityItem.setSecurity(itemStack, ((ISecurityTile)tileEntity).getSecurity().getMode());
}
}
if(tileEntity instanceof IUpgradeTile)

View file

@ -19,9 +19,13 @@ import mekanism.common.base.IEnergyCube;
import mekanism.common.base.ISustainedInventory;
import mekanism.common.integration.IC2ItemManager;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.security.ISecurityTile.SecurityMode;
import mekanism.common.tile.TileEntityEnergyCube;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.SecurityUtils;
import net.minecraft.block.Block;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.entity.player.EntityPlayer;
@ -42,7 +46,7 @@ import cpw.mods.fml.relauncher.SideOnly;
@InterfaceList({
@Interface(iface = "ic2.api.item.ISpecialElectricItem", modid = "IC2")
})
public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IEnergyCube, ISpecialElectricItem, ISustainedInventory, IEnergyContainerItem
public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IEnergyCube, ISpecialElectricItem, ISustainedInventory, IEnergyContainerItem, ISecurityItem
{
public Block metaBlock;
@ -60,12 +64,24 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IE
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag)
{
list.add(EnumColor.BRIGHT_GREEN + LangUtils.localize("tooltip.storedEnergy") + ": " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergy(itemstack)));
if(!MekKeyHandler.getIsKeyPressed(MekanismKeyHandler.sneakKey))
{
list.add(LangUtils.localize("tooltip.hold") + " " + EnumColor.AQUA + GameSettings.getKeyDisplayString(MekanismKeyHandler.sneakKey.getKeyCode()) + EnumColor.GREY + " " + LangUtils.localize("tooltip.forDetails") + ".");
}
else {
list.add(EnumColor.BRIGHT_GREEN + LangUtils.localize("tooltip.storedEnergy") + ": " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergy(itemstack)));
if(hasSecurity(itemstack))
{
list.add(SecurityUtils.getOwnerDisplay(entityplayer.getCommandSenderName(), getOwner(itemstack)));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack));
if(SecurityUtils.isOverridden(itemstack))
{
list.add(EnumColor.RED + "(" + LangUtils.localize("gui.overridden") + ")");
}
}
list.add(EnumColor.AQUA + LangUtils.localize("tooltip.inventory") + ": " + EnumColor.GREY + LangUtils.transYesNo(getInventory(itemstack) != null && getInventory(itemstack).tagCount() != 0));
}
}
@ -95,6 +111,22 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IE
TileEntityEnergyCube tileEntity = (TileEntityEnergyCube)world.getTileEntity(x, y, z);
tileEntity.tier = ((IEnergyCube)stack.getItem()).getEnergyCubeTier(stack);
tileEntity.electricityStored = getEnergy(stack);
if(tileEntity instanceof ISecurityTile)
{
ISecurityTile security = (ISecurityTile)tileEntity;
security.getSecurity().setOwner(getOwner(stack));
if(hasSecurity(stack))
{
security.getSecurity().setMode(getSecurity(stack));
}
if(getOwner(stack) == null)
{
security.getSecurity().setOwner(player.getCommandSenderName());
}
}
((ISustainedInventory)tileEntity).setInventory(getInventory(stack));
@ -330,4 +362,60 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IE
{
return this;
}
@Override
public String getOwner(ItemStack stack)
{
if(stack.stackTagCompound != null && stack.stackTagCompound.hasKey("owner"))
{
return stack.stackTagCompound.getString("owner");
}
return null;
}
@Override
public void setOwner(ItemStack stack, String owner)
{
if(stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());
}
if(owner == null || owner.isEmpty())
{
stack.stackTagCompound.removeTag("owner");
return;
}
stack.stackTagCompound.setString("owner", owner);
}
@Override
public SecurityMode getSecurity(ItemStack stack)
{
if(stack.stackTagCompound == null)
{
return SecurityMode.PUBLIC;
}
return SecurityMode.values()[stack.stackTagCompound.getInteger("security")];
}
@Override
public void setSecurity(ItemStack stack, SecurityMode mode)
{
if(stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());
}
stack.stackTagCompound.setInteger("security", mode.ordinal());
}
@Override
public boolean hasSecurity(ItemStack stack)
{
return true;
}
}

View file

@ -18,8 +18,12 @@ import mekanism.common.Tier.GasTankTier;
import mekanism.common.base.ISustainedInventory;
import mekanism.common.base.ITierItem;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.security.ISecurityTile.SecurityMode;
import mekanism.common.tile.TileEntityGasTank;
import mekanism.common.util.LangUtils;
import mekanism.common.util.SecurityUtils;
import net.minecraft.block.Block;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.creativetab.CreativeTabs;
@ -33,7 +37,7 @@ import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants.NBT;
public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedInventory, ITierItem
public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedInventory, ITierItem, ISecurityItem
{
public Block metaBlock;
@ -81,6 +85,22 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
tileEntity.tier = GasTankTier.values()[getBaseTier(stack).ordinal()];
tileEntity.gasTank.setMaxGas(tileEntity.tier.storage);
tileEntity.gasTank.setGas(getGas(stack));
if(tileEntity instanceof ISecurityTile)
{
ISecurityTile security = (ISecurityTile)tileEntity;
security.getSecurity().setOwner(getOwner(stack));
if(hasSecurity(stack))
{
security.getSecurity().setMode(getSecurity(stack));
}
if(getOwner(stack) == null)
{
security.getSecurity().setOwner(player.getCommandSenderName());
}
}
((ISustainedInventory)tileEntity).setInventory(getInventory(stack));
@ -111,6 +131,17 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
list.add(LangUtils.localize("tooltip.hold") + " " + EnumColor.AQUA + GameSettings.getKeyDisplayString(MekanismKeyHandler.sneakKey.getKeyCode()) + EnumColor.GREY + " " + LangUtils.localize("tooltip.forDetails") + ".");
}
else {
if(hasSecurity(itemstack))
{
list.add(SecurityUtils.getOwnerDisplay(entityplayer.getCommandSenderName(), getOwner(itemstack)));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack));
if(SecurityUtils.isOverridden(itemstack))
{
list.add(EnumColor.RED + "(" + LangUtils.localize("gui.overridden") + ")");
}
}
list.add(EnumColor.AQUA + LangUtils.localize("tooltip.inventory") + ": " + EnumColor.GREY + LangUtils.transYesNo(getInventory(itemstack) != null && getInventory(itemstack).tagCount() != 0));
}
}
@ -304,4 +335,60 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
{
return 1D-((getGas(stack) != null ? (double)getGas(stack).amount : 0D)/(double)getMaxGas(stack));
}
@Override
public String getOwner(ItemStack stack)
{
if(stack.stackTagCompound != null && stack.stackTagCompound.hasKey("owner"))
{
return stack.stackTagCompound.getString("owner");
}
return null;
}
@Override
public void setOwner(ItemStack stack, String owner)
{
if(stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());
}
if(owner == null || owner.isEmpty())
{
stack.stackTagCompound.removeTag("owner");
return;
}
stack.stackTagCompound.setString("owner", owner);
}
@Override
public SecurityMode getSecurity(ItemStack stack)
{
if(stack.stackTagCompound == null)
{
return SecurityMode.PUBLIC;
}
return SecurityMode.values()[stack.stackTagCompound.getInteger("security")];
}
@Override
public void setSecurity(ItemStack stack, SecurityMode mode)
{
if(stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());
}
stack.stackTagCompound.setInteger("security", mode.ordinal());
}
@Override
public boolean hasSecurity(ItemStack stack)
{
return true;
}
}

View file

@ -16,8 +16,10 @@ import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.ISideConfiguration;
import mekanism.common.integration.IComputerIntegration;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.security.ISecurityTile;
import mekanism.common.tile.component.TileComponentConfig;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentSecurity;
import mekanism.common.util.CableUtils;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.InventoryUtils;
@ -28,7 +30,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityEnergyCube extends TileEntityElectricBlock implements IComputerIntegration, IRedstoneControl, ISideConfiguration
public class TileEntityEnergyCube extends TileEntityElectricBlock implements IComputerIntegration, IRedstoneControl, ISideConfiguration, ISecurityTile
{
/** This Energy Cube's tier. */
public EnergyCubeTier tier = EnergyCubeTier.BASIC;
@ -43,6 +45,7 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo
public TileComponentEjector ejectorComponent;
public TileComponentConfig configComponent;
public TileComponentSecurity securityComponent;
/**
* A block used to store and transfer electricity.
@ -66,6 +69,8 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo
controlType = RedstoneControl.DISABLED;
ejectorComponent = new TileComponentEjector(this);
securityComponent = new TileComponentSecurity(this);
}
@Override
@ -294,4 +299,10 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements ICo
{
return facing;
}
@Override
public TileComponentSecurity getSecurity()
{
return securityComponent;
}
}

View file

@ -21,8 +21,10 @@ import mekanism.common.Tier.GasTankTier;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.base.ISideConfiguration;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.security.ISecurityTile;
import mekanism.common.tile.component.TileComponentConfig;
import mekanism.common.tile.component.TileComponentEjector;
import mekanism.common.tile.component.TileComponentSecurity;
import mekanism.common.util.InventoryUtils;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
@ -33,7 +35,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MathHelper;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityGasTank extends TileEntityContainerBlock implements IGasHandler, ITubeConnection, IRedstoneControl, ISideConfiguration
public class TileEntityGasTank extends TileEntityContainerBlock implements IGasHandler, ITubeConnection, IRedstoneControl, ISideConfiguration, ISecurityTile
{
public enum GasMode
{
@ -56,6 +58,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
public TileComponentEjector ejectorComponent;
public TileComponentConfig configComponent;
public TileComponentSecurity securityComponent;
public TileEntityGasTank()
{
@ -78,6 +81,8 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
controlType = RedstoneControl.DISABLED;
ejectorComponent = new TileComponentEjector(this);
securityComponent = new TileComponentSecurity(this);
}
@Override
@ -348,4 +353,10 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasH
{
return facing;
}
@Override
public TileComponentSecurity getSecurity()
{
return securityComponent;
}
}

View file

@ -9,6 +9,7 @@ import mekanism.client.gui.element.GuiElement.IInfoHandler;
import mekanism.client.gui.element.GuiEnergyInfo;
import mekanism.client.gui.element.GuiPowerBar;
import mekanism.client.gui.element.GuiRedstoneControl;
import mekanism.client.gui.element.GuiSecurityTab;
import mekanism.client.gui.element.GuiSlot;
import mekanism.client.gui.element.GuiSlot.SlotOverlay;
import mekanism.client.gui.element.GuiSlot.SlotType;
@ -34,6 +35,7 @@ public class GuiBioGenerator extends GuiMekanism
super(new ContainerBioGenerator(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiBioGenerator.png")));
guiElements.add(new GuiSecurityTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiBioGenerator.png")));
guiElements.add(new GuiEnergyInfo(new IInfoHandler()
{
@Override

View file

@ -12,6 +12,7 @@ import mekanism.client.gui.element.GuiGasGauge.IGasInfoHandler;
import mekanism.client.gui.element.GuiGauge.Type;
import mekanism.client.gui.element.GuiPowerBar;
import mekanism.client.gui.element.GuiRedstoneControl;
import mekanism.client.gui.element.GuiSecurityTab;
import mekanism.client.gui.element.GuiSlot;
import mekanism.client.gui.element.GuiSlot.SlotOverlay;
import mekanism.client.gui.element.GuiSlot.SlotType;
@ -37,6 +38,7 @@ public class GuiGasGenerator extends GuiMekanism
super(new ContainerGasGenerator(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiGasGenerator.png")));
guiElements.add(new GuiSecurityTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiGasGenerator.png")));
guiElements.add(new GuiEnergyInfo(new IInfoHandler() {
@Override
public List<String> getInfo()

View file

@ -14,6 +14,7 @@ import mekanism.client.gui.element.GuiGauge.Type;
import mekanism.client.gui.element.GuiHeatInfo;
import mekanism.client.gui.element.GuiPowerBar;
import mekanism.client.gui.element.GuiRedstoneControl;
import mekanism.client.gui.element.GuiSecurityTab;
import mekanism.client.gui.element.GuiSlot;
import mekanism.client.gui.element.GuiSlot.SlotOverlay;
import mekanism.client.gui.element.GuiSlot.SlotType;
@ -40,6 +41,7 @@ public class GuiHeatGenerator extends GuiMekanism
super(new ContainerHeatGenerator(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiHeatGenerator.png")));
guiElements.add(new GuiSecurityTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiHeatGenerator.png")));
guiElements.add(new GuiEnergyInfo(new IInfoHandler()
{
@Override

View file

@ -8,6 +8,7 @@ import mekanism.client.gui.element.GuiElement.IInfoHandler;
import mekanism.client.gui.element.GuiEnergyInfo;
import mekanism.client.gui.element.GuiPowerBar;
import mekanism.client.gui.element.GuiRedstoneControl;
import mekanism.client.gui.element.GuiSecurityTab;
import mekanism.client.gui.element.GuiSlot;
import mekanism.client.gui.element.GuiSlot.SlotOverlay;
import mekanism.client.gui.element.GuiSlot.SlotType;
@ -33,6 +34,7 @@ public class GuiSolarGenerator extends GuiMekanism
super(new ContainerSolarGenerator(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiSolarGenerator.png")));
guiElements.add(new GuiSecurityTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiSolarGenerator.png")));
guiElements.add(new GuiEnergyInfo(new IInfoHandler()
{
@Override

View file

@ -11,6 +11,7 @@ import mekanism.client.gui.element.GuiElement.IInfoHandler;
import mekanism.client.gui.element.GuiEnergyInfo;
import mekanism.client.gui.element.GuiPowerBar;
import mekanism.client.gui.element.GuiRedstoneControl;
import mekanism.client.gui.element.GuiSecurityTab;
import mekanism.client.gui.element.GuiSlot;
import mekanism.client.gui.element.GuiSlot.SlotOverlay;
import mekanism.client.gui.element.GuiSlot.SlotType;
@ -38,6 +39,7 @@ public class GuiWindGenerator extends GuiMekanism
super(new ContainerWindGenerator(inventory, tentity));
tileEntity = tentity;
guiElements.add(new GuiRedstoneControl(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiWindTurbine.png")));
guiElements.add(new GuiSecurityTab(this, tileEntity, MekanismUtils.getResource(ResourceType.GUI, "GuiWindTurbine.png")));
guiElements.add(new GuiEnergyInfo(new IInfoHandler()
{
@Override

View file

@ -17,11 +17,15 @@ import mekanism.common.base.ISustainedData;
import mekanism.common.base.ISustainedInventory;
import mekanism.common.base.ISustainedTank;
import mekanism.common.multiblock.IMultiblock;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.security.ISecurityTile.SecurityMode;
import mekanism.common.tile.TileEntityBasicBlock;
import mekanism.common.tile.TileEntityContainerBlock;
import mekanism.common.tile.TileEntityElectricBlock;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.SecurityUtils;
import mekanism.generators.common.GeneratorsBlocks;
import mekanism.generators.common.GeneratorsItems;
import mekanism.generators.common.MekanismGenerators;
@ -47,6 +51,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
@ -250,6 +255,19 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds, IB
{
return i;
}
@Override
public float getBlockHardness(World world, int x, int y, int z)
{
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof ISecurityTile)
{
return SecurityUtils.getSecurity((ISecurityTile)tile) == SecurityMode.PUBLIC ? blockHardness : -1;
}
return blockHardness;
}
@Override
@SideOnly(Side.CLIENT)
@ -425,32 +443,32 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds, IB
if(MekanismUtils.hasUsableWrench(entityplayer, x, y, z))
{
if(entityplayer.isSneaking())
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
dismantleBlock(world, x, y, z, false);
return true;
if(entityplayer.isSneaking())
{
dismantleBlock(world, x, y, z, false);
return true;
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench)tool).wrenchUsed(entityplayer, x, y, z);
}
int change = ForgeDirection.ROTATION_MATRIX[ForgeDirection.UP.ordinal()][tileEntity.facing];
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, this);
}
if(MekanismUtils.isBCWrench(tool))
{
((IToolWrench)tool).wrenchUsed(entityplayer, x, y, z);
else {
SecurityUtils.displayNoAccess(entityplayer);
}
int change = ForgeDirection.ROTATION_MATRIX[ForgeDirection.UP.ordinal()][tileEntity.facing];
tileEntity.setFacing((short)change);
world.notifyBlocksOfNeighborChange(x, y, z, this);
return true;
}
}
if(metadata == 3 && entityplayer.getCurrentEquippedItem() != null && entityplayer.getCurrentEquippedItem().isItemEqual(new ItemStack(GeneratorsBlocks.Generator, 1, 2)))
{
if(((TileEntityBasicBlock)world.getTileEntity(x, y, z)).facing != side)
{
return false;
}
}
if(metadata == GeneratorType.TURBINE_CASING.meta || metadata == GeneratorType.TURBINE_VALVE.meta || metadata == GeneratorType.TURBINE_VENT.meta)
{
@ -523,7 +541,14 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds, IB
{
if(!entityplayer.isSneaking())
{
entityplayer.openGui(MekanismGenerators.instance, guiId, world, x, y, z);
if(SecurityUtils.canAccess(entityplayer, tileEntity))
{
entityplayer.openGui(MekanismGenerators.instance, guiId, world, x, y, z);
}
else {
SecurityUtils.displayNoAccess(entityplayer);
}
return true;
}
}
@ -637,10 +662,26 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds, IB
TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getTileEntity(x, y, z);
ItemStack itemStack = new ItemStack(GeneratorsBlocks.Generator, 1, world.getBlockMetadata(x, y, z));
if(itemStack.stackTagCompound == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
if(tileEntity == null)
{
return null;
}
if(tileEntity instanceof ISecurityTile)
{
ISecurityItem securityItem = (ISecurityItem)itemStack.getItem();
if(securityItem.hasSecurity(itemStack))
{
securityItem.setOwner(itemStack, ((ISecurityTile)tileEntity).getSecurity().getOwner());
securityItem.setSecurity(itemStack, ((ISecurityTile)tileEntity).getSecurity().getMode());
}
}
if(tileEntity instanceof TileEntityElectricBlock)
{

View file

@ -14,10 +14,14 @@ import mekanism.common.base.ISustainedData;
import mekanism.common.base.ISustainedInventory;
import mekanism.common.base.ISustainedTank;
import mekanism.common.integration.IC2ItemManager;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.security.ISecurityTile.SecurityMode;
import mekanism.common.tile.TileEntityBasicBlock;
import mekanism.common.tile.TileEntityElectricBlock;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.SecurityUtils;
import mekanism.generators.common.block.BlockGenerator.GeneratorType;
import net.minecraft.block.Block;
import net.minecraft.client.settings.GameSettings;
@ -59,7 +63,7 @@ import cpw.mods.fml.relauncher.SideOnly;
@InterfaceList({
@Interface(iface = "ic2.api.item.ISpecialElectricItem", modid = "IC2")
})
public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISpecialElectricItem, ISustainedInventory, ISustainedTank, IEnergyContainerItem
public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISpecialElectricItem, ISustainedInventory, ISustainedTank, IEnergyContainerItem, ISecurityItem
{
public Block metaBlock;
@ -122,8 +126,19 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp
}
else if(!MekKeyHandler.getIsKeyPressed(MekanismKeyHandler.modeSwitchKey))
{
if(hasSecurity(itemstack))
{
list.add(SecurityUtils.getOwnerDisplay(entityplayer.getCommandSenderName(), getOwner(itemstack)));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack));
if(SecurityUtils.isOverridden(itemstack))
{
list.add(EnumColor.RED + "(" + LangUtils.localize("gui.overridden") + ")");
}
}
list.add(EnumColor.BRIGHT_GREEN + LangUtils.localize("tooltip.storedEnergy") + ": " + EnumColor.GREY + MekanismUtils.getEnergyDisplay(getEnergy(itemstack)));
if(hasTank(itemstack))
{
if(getFluidStack(itemstack) != null)
@ -197,6 +212,22 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp
{
TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getTileEntity(x, y, z);
if(tileEntity instanceof ISecurityTile)
{
ISecurityTile security = (ISecurityTile)tileEntity;
security.getSecurity().setOwner(getOwner(stack));
if(hasSecurity(stack))
{
security.getSecurity().setMode(getSecurity(stack));
}
if(getOwner(stack) == null)
{
security.getSecurity().setOwner(player.getCommandSenderName());
}
}
if(tileEntity instanceof TileEntityElectricBlock)
{
((TileEntityElectricBlock)tileEntity).electricityStored = getEnergy(stack);
@ -456,4 +487,62 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp
{
return IC2ItemManager.getManager(this);
}
@Override
public String getOwner(ItemStack stack)
{
if(stack.stackTagCompound != null && stack.stackTagCompound.hasKey("owner"))
{
return stack.stackTagCompound.getString("owner");
}
return null;
}
@Override
public void setOwner(ItemStack stack, String owner)
{
if(stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());
}
if(owner == null || owner.isEmpty())
{
stack.stackTagCompound.removeTag("owner");
return;
}
stack.stackTagCompound.setString("owner", owner);
}
@Override
public SecurityMode getSecurity(ItemStack stack)
{
if(stack.stackTagCompound == null)
{
return SecurityMode.PUBLIC;
}
return SecurityMode.values()[stack.stackTagCompound.getInteger("security")];
}
@Override
public void setSecurity(ItemStack stack, SecurityMode mode)
{
if(stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());
}
stack.stackTagCompound.setInteger("security", mode.ordinal());
}
@Override
public boolean hasSecurity(ItemStack stack)
{
GeneratorType type = GeneratorType.getFromMetadata(stack.getItemDamage());
return type.hasModel;
}
}

View file

@ -15,7 +15,9 @@ import mekanism.common.base.IHasSound;
import mekanism.common.base.IRedstoneControl;
import mekanism.common.integration.IComputerIntegration;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.security.ISecurityTile;
import mekanism.common.tile.TileEntityNoisyElectricBlock;
import mekanism.common.tile.component.TileComponentSecurity;
import mekanism.common.util.CableUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.nbt.NBTTagCompound;
@ -24,7 +26,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class TileEntityGenerator extends TileEntityNoisyElectricBlock implements IComputerIntegration, IActiveState, IHasSound, ISoundSource, IRedstoneControl
public abstract class TileEntityGenerator extends TileEntityNoisyElectricBlock implements IComputerIntegration, IActiveState, IHasSound, ISoundSource, IRedstoneControl, ISecurityTile
{
/** Output per tick this generator can transfer. */
public double output;
@ -40,6 +42,8 @@ public abstract class TileEntityGenerator extends TileEntityNoisyElectricBlock i
/** This machine's current RedstoneControl type. */
public RedstoneControl controlType;
public TileComponentSecurity securityComponent = new TileComponentSecurity(this);
/**
* Generator -- a block that produces energy. It has a certain amount of fuel it can store as well as an output rate.
@ -223,4 +227,10 @@ public abstract class TileEntityGenerator extends TileEntityNoisyElectricBlock i
{
return false;
}
@Override
public TileComponentSecurity getSecurity()
{
return securityComponent;
}
}