Search in sources :

Example 1 with IBlockProvider

use of mekanism.api.providers.IBlockProvider in project Mekanism by mekanism.

the class BaseBlockLootTables method dropSelfWithContents.

protected void dropSelfWithContents(List<IBlockProvider> blockProviders) {
    // For example, when writing this we added dump mode for chemical tanks to getting transferred to the item
    for (IBlockProvider blockProvider : blockProviders) {
        Block block = blockProvider.getBlock();
        if (skipBlock(block)) {
            continue;
        }
        CopyNbt.Builder nbtBuilder = CopyNbt.copyData(Source.BLOCK_ENTITY);
        boolean hasData = false;
        boolean hasContents = false;
        @Nullable TileEntity tile = null;
        if (block instanceof IHasTileEntity) {
            tile = ((IHasTileEntity<?>) block).getTileType().create();
        }
        if (tile instanceof IFrequencyHandler && ((IFrequencyHandler) tile).getFrequencyComponent().hasCustomFrequencies()) {
            nbtBuilder.copy(NBTConstants.COMPONENT_FREQUENCY, NBTConstants.MEK_DATA + "." + NBTConstants.COMPONENT_FREQUENCY);
            hasData = true;
        }
        if (Attribute.has(block, AttributeSecurity.class)) {
            // TODO: Should we just save the entire security component?
            nbtBuilder.copy(NBTConstants.COMPONENT_SECURITY + "." + NBTConstants.OWNER_UUID, NBTConstants.MEK_DATA + "." + NBTConstants.OWNER_UUID);
            nbtBuilder.copy(NBTConstants.COMPONENT_SECURITY + "." + NBTConstants.SECURITY_MODE, NBTConstants.MEK_DATA + "." + NBTConstants.SECURITY_MODE);
            hasData = true;
        }
        if (Attribute.has(block, AttributeUpgradeSupport.class)) {
            nbtBuilder.copy(NBTConstants.COMPONENT_UPGRADE, NBTConstants.MEK_DATA + "." + NBTConstants.COMPONENT_UPGRADE);
            hasData = true;
        }
        if (tile instanceof ISideConfiguration) {
            nbtBuilder.copy(NBTConstants.COMPONENT_CONFIG, NBTConstants.MEK_DATA + "." + NBTConstants.COMPONENT_CONFIG);
            nbtBuilder.copy(NBTConstants.COMPONENT_EJECTOR, NBTConstants.MEK_DATA + "." + NBTConstants.COMPONENT_EJECTOR);
            hasData = true;
        }
        if (tile instanceof ISustainedData) {
            Set<Entry<String, String>> remapEntries = ((ISustainedData) tile).getTileDataRemap().entrySet();
            for (Entry<String, String> remapEntry : remapEntries) {
                nbtBuilder.copy(remapEntry.getKey(), NBTConstants.MEK_DATA + "." + remapEntry.getValue());
            }
            if (!remapEntries.isEmpty()) {
                hasData = true;
            }
        }
        if (Attribute.has(block, AttributeRedstone.class)) {
            nbtBuilder.copy(NBTConstants.CONTROL_TYPE, NBTConstants.MEK_DATA + "." + NBTConstants.CONTROL_TYPE);
            hasData = true;
        }
        if (tile instanceof TileEntityMekanism) {
            TileEntityMekanism tileEntity = (TileEntityMekanism) tile;
            for (SubstanceType type : EnumUtils.SUBSTANCES) {
                if (tileEntity.handles(type) && !type.getContainers(tileEntity).isEmpty()) {
                    nbtBuilder.copy(type.getContainerTag(), NBTConstants.MEK_DATA + "." + type.getContainerTag());
                    hasData = true;
                    if (type != SubstanceType.ENERGY && type != SubstanceType.HEAT) {
                        hasContents = true;
                    }
                }
            }
        }
        if (Attribute.has(block, AttributeInventory.class)) {
            // then only copy the slots if we actually have any slots because otherwise maybe something just went wrong
            if (!(tile instanceof IItemHandler) || ((IItemHandler) tile).getSlots() > 0) {
                // If we don't actually handle saving an inventory (such as the quantum entangloporter, don't actually add it as something to copy)
                if (!(tile instanceof TileEntityMekanism) || ((TileEntityMekanism) tile).persistInventory()) {
                    nbtBuilder.copy(NBTConstants.ITEMS, NBTConstants.MEK_DATA + "." + NBTConstants.ITEMS);
                    hasData = true;
                    hasContents = true;
                }
            }
        }
        if (block instanceof BlockCardboardBox) {
            // TODO: Do this better so that it doesn't have to be as hard coded to being a cardboard box
            nbtBuilder.copy(NBTConstants.DATA, NBTConstants.MEK_DATA + "." + NBTConstants.DATA);
            hasData = true;
        }
        if (!hasData) {
            // To keep the json as clean as possible don't bother even registering a blank accept function if we have no
            // persistent data that we want to copy. Also log a warning so that we don't have to attempt to check against
            // that block
            dropSelf(block);
        } else {
            add(block, LootTable.lootTable().withPool(applyExplosionCondition(hasContents, LootPool.lootPool().name("main").setRolls(ConstantRange.exactly(1)).add(ItemLootEntry.lootTableItem(block).apply(nbtBuilder)))));
        }
    }
}
Also used : TileEntityMekanism(mekanism.common.tile.base.TileEntityMekanism) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) IItemHandler(net.minecraftforge.items.IItemHandler) CopyNbt(net.minecraft.loot.functions.CopyNbt) IHasTileEntity(mekanism.common.block.interfaces.IHasTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Entry(java.util.Map.Entry) ItemLootEntry(net.minecraft.loot.ItemLootEntry) LootEntry(net.minecraft.loot.LootEntry) SubstanceType(mekanism.common.tile.base.SubstanceType) IBlockProvider(mekanism.api.providers.IBlockProvider) IFrequencyHandler(mekanism.common.lib.frequency.IFrequencyHandler) Block(net.minecraft.block.Block) SlabBlock(net.minecraft.block.SlabBlock) BlockCardboardBox(mekanism.common.block.BlockCardboardBox) ISustainedData(mekanism.common.tile.interfaces.ISustainedData) Nullable(javax.annotation.Nullable) ISideConfiguration(mekanism.common.tile.interfaces.ISideConfiguration)

Example 2 with IBlockProvider

use of mekanism.api.providers.IBlockProvider in project Mekanism by mekanism.

the class BaseTagProvider method addToTags.

protected void addToTags(INamedTag<Item> itemTag, INamedTag<Block> blockTag, IBlockProvider... blockProviders) {
    ForgeRegistryTagBuilder<Item> itemTagBuilder = getItemBuilder(itemTag);
    ForgeRegistryTagBuilder<Block> blockTagBuilder = getBlockBuilder(blockTag);
    for (IBlockProvider blockProvider : blockProviders) {
        itemTagBuilder.add(blockProvider.getItem());
        blockTagBuilder.add(blockProvider.getBlock());
    }
}
Also used : Item(net.minecraft.item.Item) IBlockProvider(mekanism.api.providers.IBlockProvider) Block(net.minecraft.block.Block)

Example 3 with IBlockProvider

use of mekanism.api.providers.IBlockProvider in project Mekanism by mekanism.

the class ClientRegistrationUtil method registerBlockColorHandler.

public static void registerBlockColorHandler(BlockColors blockColors, ItemColors itemColors, IBlockColor blockColor, IItemColor itemColor, IBlockProvider... blocks) {
    for (IBlockProvider blockProvider : blocks) {
        blockColors.register(blockColor, blockProvider.getBlock());
        itemColors.register(itemColor, blockProvider.getItem());
    }
}
Also used : IBlockProvider(mekanism.api.providers.IBlockProvider)

Example 4 with IBlockProvider

use of mekanism.api.providers.IBlockProvider in project Mekanism by mekanism.

the class AdditionsBlockStateProvider method coloredSlabs.

private void coloredSlabs(Map<?, ? extends IBlockProvider> slabs, String existingPrefix, String doubleType) {
    ConfiguredModel bottomModel = new ConfiguredModel(models().getExistingFile(modLoc("block/plastic/" + existingPrefix + "slab")));
    ConfiguredModel topModel = new ConfiguredModel(models().getExistingFile(modLoc("block/plastic/" + existingPrefix + "slab_top")));
    ConfiguredModel doubleModel = new ConfiguredModel(models().getExistingFile(modLoc("block/plastic/" + doubleType)));
    for (IBlockProvider slab : slabs.values()) {
        getVariantBuilder(slab).partialState().with(SlabBlock.TYPE, SlabType.BOTTOM).addModels(bottomModel).partialState().with(SlabBlock.TYPE, SlabType.TOP).addModels(topModel).partialState().with(SlabBlock.TYPE, SlabType.DOUBLE).addModels(doubleModel);
    }
}
Also used : IBlockProvider(mekanism.api.providers.IBlockProvider) ConfiguredModel(net.minecraftforge.client.model.generators.ConfiguredModel)

Example 5 with IBlockProvider

use of mekanism.api.providers.IBlockProvider in project Mekanism by mekanism.

the class AdditionsBlockStateProvider method coloredFences.

private void coloredFences(Map<?, ? extends IBlockProvider> fences, String existingPrefix) {
    ModelFile post = models().getExistingFile(modLoc("block/plastic/" + existingPrefix + "fence_post"));
    ModelFile side = models().getExistingFile(modLoc("block/plastic/" + existingPrefix + "fence_side"));
    for (IBlockProvider fence : fences.values()) {
        fourWayMultipart(getMultipartBuilder(fence.getBlock()).part().modelFile(post).addModel().end(), side);
    }
}
Also used : IBlockProvider(mekanism.api.providers.IBlockProvider) ModelFile(net.minecraftforge.client.model.generators.ModelFile)

Aggregations

IBlockProvider (mekanism.api.providers.IBlockProvider)5 Block (net.minecraft.block.Block)2 Entry (java.util.Map.Entry)1 Nullable (javax.annotation.Nullable)1 BlockCardboardBox (mekanism.common.block.BlockCardboardBox)1 IHasTileEntity (mekanism.common.block.interfaces.IHasTileEntity)1 IFrequencyHandler (mekanism.common.lib.frequency.IFrequencyHandler)1 SubstanceType (mekanism.common.tile.base.SubstanceType)1 TileEntityMekanism (mekanism.common.tile.base.TileEntityMekanism)1 ISideConfiguration (mekanism.common.tile.interfaces.ISideConfiguration)1 ISustainedData (mekanism.common.tile.interfaces.ISustainedData)1 SlabBlock (net.minecraft.block.SlabBlock)1 Item (net.minecraft.item.Item)1 ItemLootEntry (net.minecraft.loot.ItemLootEntry)1 LootEntry (net.minecraft.loot.LootEntry)1 CopyNbt (net.minecraft.loot.functions.CopyNbt)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ConfiguredModel (net.minecraftforge.client.model.generators.ConfiguredModel)1 ModelFile (net.minecraftforge.client.model.generators.ModelFile)1 IItemHandler (net.minecraftforge.items.IItemHandler)1