mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 23:03:01 +00:00
Extend security to generators, gas tanks and energy cubes
This commit is contained in:
1 parent
b83257d83b
commit
5ed86f3f01
17 files changed
+509
-58
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user