Added security card

This commit is contained in:
Raoul Van den Berge
2016-12-16 21:44:16 +01:00
parent e22a4d0629
commit 4cdb8ba72b
5 changed files with 95 additions and 6 deletions

View File

@@ -19,4 +19,5 @@ public final class RSItems {
public static final ItemFluidStoragePart FLUID_STORAGE_PART = new ItemFluidStoragePart();
public static final ItemWrench WRENCH = new ItemWrench();
public static final ItemWirelessCraftingMonitor WIRELESS_CRAFTING_MONITOR = new ItemWirelessCraftingMonitor();
public static final ItemSecurityCard SECURITY_CARD = new ItemSecurityCard();
}

View File

@@ -7,21 +7,31 @@ public enum Permission {
/**
* Whether the player can insert items in a network.
*/
INSERT,
INSERT(0),
/**
* Whether the player can extract items from a network.
*/
EXTRACT,
EXTRACT(1),
/**
* Whether the player can start, cancel or view an autocrafting task.
*/
AUTOCRAFT,
AUTOCRAFT(2),
/**
* Whether the player can open network GUIs and can place or break network blocks.
*/
MODIFY,
MODIFY(3),
/**
* Whether the player can manage the security options for a network.
*/
SECURITY
SECURITY(4);
private final int id;
Permission(int id) {
this.id = id;
}
public int getId() {
return id;
}
}

View File

@@ -0,0 +1,75 @@
package com.raoulvdberge.refinedstorage.item;
import com.raoulvdberge.refinedstorage.api.network.Permission;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import javax.annotation.Nullable;
import java.util.List;
import java.util.UUID;
public class ItemSecurityCard extends ItemBase {
private static final String NBT_BOUND = "Bound";
private static final String NBT_BOUND_NAME = "BoundName";
private static final String NBT_PERMISSION = "Permission_%d";
public ItemSecurityCard() {
super("security_card");
}
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
stack.setTagCompound(new NBTTagCompound());
stack.getTagCompound().setString(NBT_BOUND, player.getGameProfile().getId().toString());
stack.getTagCompound().setString(NBT_BOUND_NAME, player.getGameProfile().getName());
}
return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}
@Nullable
public static UUID getBound(ItemStack stack) {
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_BOUND)) {
return UUID.fromString(stack.getTagCompound().getString(NBT_BOUND));
}
return null;
}
public static boolean hasPermission(ItemStack stack, Permission permission) {
String id = String.format(NBT_PERMISSION, permission.getId());
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(id)) {
return stack.getTagCompound().getBoolean(id);
}
return true;
}
public static void setPermission(ItemStack stack, Permission permission, boolean state) {
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
}
stack.getTagCompound().setBoolean(String.format(NBT_PERMISSION, permission.getId()), state);
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(NBT_BOUND_NAME)) {
tooltip.add(I18n.format("item.refinedstorage:security_card.bound", stack.getTagCompound().getString(NBT_BOUND_NAME)));
}
}
}

View File

@@ -202,6 +202,7 @@ public class ProxyCommon {
registerItem(RSItems.NETWORK_CARD);
registerItem(RSItems.WRENCH);
registerItem(RSItems.WIRELESS_CRAFTING_MONITOR);
registerItem(RSItems.SECURITY_CARD);
OreDictionary.registerOre("itemSilicon", RSItems.SILICON);

View File

@@ -244,4 +244,6 @@ item.refinedstorage:wrench.saved=Configuration written.
item.refinedstorage:wrench.read=Configuration read.
item.refinedstorage:wrench.mode=Mode: %s
item.refinedstorage:wrench.mode.0=Rotation
item.refinedstorage:wrench.mode.1=Configuration
item.refinedstorage:wrench.mode.1=Configuration
item.refinedstorage:security_card.name=Security Card
item.refinedstorage:security_card.bound=Bound to: %s