Search in sources :

Example 6 with ISecurityItem

use of mekanism.common.lib.security.ISecurityItem in project Mekanism by mekanism.

the class BlockMekanism method setPlacedBy.

@Override
public void setPlacedBy(@Nonnull World world, @Nonnull BlockPos pos, @Nonnull BlockState state, @Nullable LivingEntity placer, @Nonnull ItemStack stack) {
    super.setPlacedBy(world, pos, state, placer, stack);
    TileEntityMekanism tile = WorldUtils.getTileEntity(TileEntityMekanism.class, world, pos);
    if (tile == null) {
        return;
    }
    if (tile.supportsRedstone()) {
        tile.redstone = world.hasNeighborSignal(pos);
    }
    tile.onPlace();
    // Handle item
    Item item = stack.getItem();
    setTileData(world, pos, state, placer, stack, tile);
    // but there is a good chance a lot of this stuff has no real reason to need to be set on the client side at all
    if (!world.isClientSide && tile.getFrequencyComponent().hasCustomFrequencies()) {
        tile.getFrequencyComponent().read(ItemDataUtils.getDataMap(stack));
    }
    if (tile instanceof TileEntitySecurityDesk && placer != null) {
        tile.getSecurity().setOwnerUUID(placer.getUUID());
    }
    if (item instanceof ISecurityItem && tile.hasSecurity()) {
        ISecurityItem securityItem = (ISecurityItem) item;
        tile.setSecurityMode(securityItem.getSecurity(stack));
        UUID ownerUUID = securityItem.getOwnerUUID(stack);
        if (ownerUUID != null) {
            tile.getSecurity().setOwnerUUID(ownerUUID);
        } else if (placer != null) {
            tile.getSecurity().setOwnerUUID(placer.getUUID());
            if (!world.isClientSide) {
                // If the machine doesn't already have an owner, make sure we portray this
                Mekanism.packetHandler.sendToAll(new PacketSecurityUpdate(placer.getUUID(), null));
            }
        }
    }
    if (tile.supportsUpgrades()) {
        // The read method validates that data is stored
        tile.getComponent().read(ItemDataUtils.getDataMap(stack));
    }
    if (tile instanceof ISideConfiguration) {
        ISideConfiguration config = (ISideConfiguration) tile;
        // The read methods validate that data is stored
        config.getConfig().read(ItemDataUtils.getDataMap(stack));
        config.getEjector().read(ItemDataUtils.getDataMap(stack));
    }
    for (SubstanceType type : EnumUtils.SUBSTANCES) {
        if (type.canHandle(tile)) {
            DataHandlerUtils.readContainers(type.getContainers(tile), ItemDataUtils.getList(stack, type.getContainerTag()));
        }
    }
    if (tile instanceof ISustainedData && stack.hasTag()) {
        ((ISustainedData) tile).readSustainedData(stack);
    }
    if (tile.supportsRedstone() && ItemDataUtils.hasData(stack, NBTConstants.CONTROL_TYPE, NBT.TAG_INT)) {
        tile.setControlType(RedstoneControl.byIndexStatic(ItemDataUtils.getInt(stack, NBTConstants.CONTROL_TYPE)));
    }
    if (item instanceof ISustainedInventory && tile.persistInventory()) {
        tile.setInventory(((ISustainedInventory) item).getInventory(stack));
    }
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) Item(net.minecraft.item.Item) ISecurityItem(mekanism.common.lib.security.ISecurityItem) ISecurityItem(mekanism.common.lib.security.ISecurityItem) ISustainedInventory(mekanism.common.tile.interfaces.ISustainedInventory) SubstanceType(mekanism.common.tile.base.SubstanceType) TileEntitySecurityDesk(mekanism.common.tile.TileEntitySecurityDesk) UUID(java.util.UUID) ISustainedData(mekanism.common.tile.interfaces.ISustainedData) PacketSecurityUpdate(mekanism.common.network.to_client.PacketSecurityUpdate) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Example 7 with ISecurityItem

use of mekanism.common.lib.security.ISecurityItem in project Mekanism by mekanism.

the class SecurityInventorySlot method unlock.

public void unlock(UUID ownerUUID) {
    if (!isEmpty() && current.getItem() instanceof IOwnerItem) {
        IOwnerItem item = (IOwnerItem) current.getItem();
        UUID stackOwner = item.getOwnerUUID(current);
        if (stackOwner != null && stackOwner.equals(ownerUUID)) {
            item.setOwnerUUID(current, null);
            if (item instanceof ISecurityItem) {
                ((ISecurityItem) item).setSecurity(current, SecurityMode.PUBLIC);
            }
        }
    }
}
Also used : ISecurityItem(mekanism.common.lib.security.ISecurityItem) IOwnerItem(mekanism.common.lib.security.IOwnerItem) UUID(java.util.UUID)

Example 8 with ISecurityItem

use of mekanism.common.lib.security.ISecurityItem in project Mekanism by mekanism.

the class SecurityInventorySlot method lock.

public void lock(UUID ownerUUID, SecurityFrequency frequency) {
    if (!isEmpty() && current.getItem() instanceof IOwnerItem) {
        IOwnerItem item = (IOwnerItem) current.getItem();
        UUID stackOwner = item.getOwnerUUID(current);
        if (stackOwner == null) {
            item.setOwnerUUID(current, stackOwner = ownerUUID);
        }
        if (stackOwner.equals(ownerUUID)) {
            if (item instanceof ISecurityItem) {
                ((ISecurityItem) item).setSecurity(current, frequency.getSecurityMode());
            }
        }
    }
}
Also used : ISecurityItem(mekanism.common.lib.security.ISecurityItem) IOwnerItem(mekanism.common.lib.security.IOwnerItem) UUID(java.util.UUID)

Aggregations

ISecurityItem (mekanism.common.lib.security.ISecurityItem)8 UUID (java.util.UUID)5 Item (net.minecraft.item.Item)4 IOwnerItem (mekanism.common.lib.security.IOwnerItem)3 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)3 ISustainedInventory (mekanism.common.tile.interfaces.ISustainedInventory)3 Nonnull (javax.annotation.Nonnull)2 IQIODriveItem (mekanism.common.content.qio.IQIODriveItem)2 SubstanceType (mekanism.common.tile.base.SubstanceType)2 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)2 ISustainedData (mekanism.common.tile.interfaces.ISustainedData)2 BlockItem (net.minecraft.item.BlockItem)2 ItemStack (net.minecraft.item.ItemStack)2 Nullable (javax.annotation.Nullable)1 IHasTileEntity (mekanism.common.block.interfaces.IHasTileEntity)1 DriveMetadata (mekanism.common.content.qio.IQIODriveItem.DriveMetadata)1 ISecurityObject (mekanism.common.lib.security.ISecurityObject)1 PacketSecurityUpdate (mekanism.common.network.to_client.PacketSecurityUpdate)1 GasRecipeData (mekanism.common.recipe.upgrade.chemical.GasRecipeData)1 InfusionRecipeData (mekanism.common.recipe.upgrade.chemical.InfusionRecipeData)1