Search in sources :

Example 1 with IQIODriveItem

use of mekanism.common.content.qio.IQIODriveItem in project Mekanism by mekanism.

the class RecipeUpgradeData method getSupportedTypes.

@Nonnull
static Set<RecipeUpgradeType> getSupportedTypes(ItemStack stack) {
    // TODO: Add more types of data that can be transferred such as side configs, auto sort, bucket mode, dumping mode
    if (stack.isEmpty()) {
        return Collections.emptySet();
    }
    Set<RecipeUpgradeType> supportedTypes = EnumSet.noneOf(RecipeUpgradeType.class);
    Item item = stack.getItem();
    TileEntityMekanism tile = null;
    if (item instanceof BlockItem) {
        Block block = ((BlockItem) item).getBlock();
        if (block instanceof IHasTileEntity) {
            TileEntity tileEntity = ((IHasTileEntity<?>) block).getTileType().create();
            if (tileEntity instanceof TileEntityMekanism) {
                tile = (TileEntityMekanism) tileEntity;
            }
        }
        if (Attribute.has(block, AttributeUpgradeSupport.class)) {
            supportedTypes.add(RecipeUpgradeType.UPGRADE);
        }
    }
    if (stack.getCapability(Capabilities.STRICT_ENERGY_CAPABILITY).isPresent() || tile != null && tile.handles(SubstanceType.ENERGY)) {
        // If we are for a block that handles energy, or we have an energy handler capability
        supportedTypes.add(RecipeUpgradeType.ENERGY);
    }
    if (FluidUtil.getFluidHandler(stack).isPresent() || tile != null && tile.handles(SubstanceType.FLUID)) {
        // If we are for a block that handles fluid, or we have a fluid handler capability
        supportedTypes.add(RecipeUpgradeType.FLUID);
    }
    if (stack.getCapability(Capabilities.GAS_HANDLER_CAPABILITY).isPresent() || tile != null && tile.handles(SubstanceType.GAS)) {
        // If we are for a block that handles gas, or we have a gas handler capability
        supportedTypes.add(RecipeUpgradeType.GAS);
    }
    if (stack.getCapability(Capabilities.INFUSION_HANDLER_CAPABILITY).isPresent() || tile != null && tile.handles(SubstanceType.INFUSION)) {
        // If we are for a block that handles infusion, or we have an infusion handler capability
        supportedTypes.add(RecipeUpgradeType.INFUSION);
    }
    if (stack.getCapability(Capabilities.PIGMENT_HANDLER_CAPABILITY).isPresent() || tile != null && tile.handles(SubstanceType.PIGMENT)) {
        // If we are for a block that handles pigment, or we have a pigment handler capability
        supportedTypes.add(RecipeUpgradeType.PIGMENT);
    }
    if (stack.getCapability(Capabilities.SLURRY_HANDLER_CAPABILITY).isPresent() || tile != null && tile.handles(SubstanceType.SLURRY)) {
        // If we are for a block that handles slurry, or we have a slurry handler capability
        supportedTypes.add(RecipeUpgradeType.SLURRY);
    }
    if (item instanceof ISustainedInventory || tile != null && tile.persistInventory()) {
        supportedTypes.add(RecipeUpgradeType.ITEM);
    }
    if (item instanceof ISecurityItem) {
        supportedTypes.add(RecipeUpgradeType.SECURITY);
    }
    if (item instanceof IQIODriveItem) {
        supportedTypes.add(RecipeUpgradeType.QIO_DRIVE);
    }
    return supportedTypes;
}
Also used : IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IQIODriveItem(mekanism.common.content.qio.IQIODriveItem) Item(net.minecraft.item.Item) ISecurityItem(mekanism.common.lib.security.ISecurityItem) BlockItem(net.minecraft.item.BlockItem) TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) ISustainedInventory(mekanism.common.tile.interfaces.ISustainedInventory) ISecurityItem(mekanism.common.lib.security.ISecurityItem) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) Block(net.minecraft.block.Block) BlockItem(net.minecraft.item.BlockItem) IQIODriveItem(mekanism.common.content.qio.IQIODriveItem) Nonnull(javax.annotation.Nonnull)

Example 2 with IQIODriveItem

use of mekanism.common.content.qio.IQIODriveItem in project Mekanism by mekanism.

the class RecipeUpgradeData method getUpgradeData.

/**
 * Make sure to validate with getSupportedTypes before calling this
 */
@Nullable
static RecipeUpgradeData<?> getUpgradeData(@Nonnull RecipeUpgradeType type, @Nonnull ItemStack stack) {
    Item item = stack.getItem();
    switch(type) {
        case ENERGY:
            return new EnergyRecipeData(ItemDataUtils.getList(stack, NBTConstants.ENERGY_CONTAINERS));
        case FLUID:
            return new FluidRecipeData(ItemDataUtils.getList(stack, NBTConstants.FLUID_TANKS));
        case GAS:
            return new GasRecipeData(ItemDataUtils.getList(stack, NBTConstants.GAS_TANKS));
        case INFUSION:
            return new InfusionRecipeData(ItemDataUtils.getList(stack, NBTConstants.INFUSION_TANKS));
        case PIGMENT:
            return new PigmentRecipeData(ItemDataUtils.getList(stack, NBTConstants.PIGMENT_TANKS));
        case SLURRY:
            return new SlurryRecipeData(ItemDataUtils.getList(stack, NBTConstants.SLURRY_TANKS));
        case ITEM:
            return new ItemRecipeData(((ISustainedInventory) item).getInventory(stack));
        case SECURITY:
            ISecurityItem securityItem = (ISecurityItem) item;
            UUID ownerUUID = securityItem.getOwnerUUID(stack);
            return ownerUUID == null ? null : new SecurityRecipeData(ownerUUID, securityItem.getSecurity(stack));
        case UPGRADE:
            CompoundNBT componentUpgrade = ItemDataUtils.getCompound(stack, NBTConstants.COMPONENT_UPGRADE);
            return componentUpgrade.isEmpty() ? null : new UpgradesRecipeData(Upgrade.buildMap(componentUpgrade));
        case QIO_DRIVE:
            DriveMetadata data = DriveMetadata.load(stack);
            if (data.getCount() > 0 && ((IQIODriveItem) item).hasStoredItemMap(stack)) {
                // If we don't have any stored items don't actually grab any recipe data
                return new QIORecipeData(data, ItemDataUtils.getList(stack, NBTConstants.QIO_ITEM_MAP));
            }
            break;
    }
    return null;
}
Also used : DriveMetadata(mekanism.common.content.qio.IQIODriveItem.DriveMetadata) CompoundNBT(net.minecraft.nbt.CompoundNBT) GasRecipeData(mekanism.common.recipe.upgrade.chemical.GasRecipeData) SlurryRecipeData(mekanism.common.recipe.upgrade.chemical.SlurryRecipeData) IQIODriveItem(mekanism.common.content.qio.IQIODriveItem) Item(net.minecraft.item.Item) ISecurityItem(mekanism.common.lib.security.ISecurityItem) BlockItem(net.minecraft.item.BlockItem) ISecurityItem(mekanism.common.lib.security.ISecurityItem) PigmentRecipeData(mekanism.common.recipe.upgrade.chemical.PigmentRecipeData) UUID(java.util.UUID) InfusionRecipeData(mekanism.common.recipe.upgrade.chemical.InfusionRecipeData) Nullable(javax.annotation.Nullable)

Example 3 with IQIODriveItem

use of mekanism.common.content.qio.IQIODriveItem in project Mekanism by mekanism.

the class QIORecipeData method applyToStack.

@Override
public boolean applyToStack(ItemStack stack) {
    IQIODriveItem driveItem = (IQIODriveItem) stack.getItem();
    if (itemCount > driveItem.getCountCapacity(stack) || itemMap.size() > driveItem.getTypeCapacity(stack)) {
        // then return that we are not able to actually apply them to the stack
        return false;
    }
    ListNBT list = new ListNBT();
    for (Entry<HashedItem> entry : itemMap.object2LongEntrySet()) {
        CompoundNBT tag = new CompoundNBT();
        tag.put(NBTConstants.ITEM, entry.getKey().getStack().save(new CompoundNBT()));
        tag.putLong(NBTConstants.AMOUNT, entry.getLongValue());
        list.add(tag);
    }
    ItemDataUtils.setList(stack, NBTConstants.QIO_ITEM_MAP, list);
    DriveMetadata meta = new DriveMetadata(itemCount, itemMap.size());
    meta.write(stack);
    return true;
}
Also used : DriveMetadata(mekanism.common.content.qio.IQIODriveItem.DriveMetadata) ListNBT(net.minecraft.nbt.ListNBT) HashedItem(mekanism.common.lib.inventory.HashedItem) CompoundNBT(net.minecraft.nbt.CompoundNBT) IQIODriveItem(mekanism.common.content.qio.IQIODriveItem)

Aggregations

IQIODriveItem (mekanism.common.content.qio.IQIODriveItem)3 DriveMetadata (mekanism.common.content.qio.IQIODriveItem.DriveMetadata)2 ISecurityItem (mekanism.common.lib.security.ISecurityItem)2 BlockItem (net.minecraft.item.BlockItem)2 Item (net.minecraft.item.Item)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 UUID (java.util.UUID)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 IHasTileEntity (mekanism.common.block.interfaces.IHasTileEntity)1 HashedItem (mekanism.common.lib.inventory.HashedItem)1 GasRecipeData (mekanism.common.recipe.upgrade.chemical.GasRecipeData)1 InfusionRecipeData (mekanism.common.recipe.upgrade.chemical.InfusionRecipeData)1 PigmentRecipeData (mekanism.common.recipe.upgrade.chemical.PigmentRecipeData)1 SlurryRecipeData (mekanism.common.recipe.upgrade.chemical.SlurryRecipeData)1 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)1 ISustainedInventory (mekanism.common.tile.interfaces.ISustainedInventory)1 Block (net.minecraft.block.Block)1 ListNBT (net.minecraft.nbt.ListNBT)1 TileEntity (net.minecraft.tileentity.TileEntity)1