Search in sources :

Example 1 with CapabilityExplosiveStack

use of icbm.classic.lib.capability.ex.CapabilityExplosiveStack in project ICBM-Classic by BuiltBrokenModding.

the class ItemMissile method initCapabilities.

@Override
@Nullable
public net.minecraftforge.common.capabilities.ICapabilityProvider initCapabilities(ItemStack stack, @Nullable NBTTagCompound nbt) {
    ItemStackCapProvider provider = new ItemStackCapProvider(stack);
    // provider.add("missile", ICBMClassicAPI.MISSILE_CAPABILITY, new CapabilityMissile()); //TODO create an itemstack version
    provider.add(NBTConstants.EXPLOSIVE, ICBMClassicAPI.EXPLOSIVE_CAPABILITY, new CapabilityExplosiveStack(stack));
    return provider;
}
Also used : CapabilityExplosiveStack(icbm.classic.lib.capability.ex.CapabilityExplosiveStack) ItemStackCapProvider(icbm.classic.prefab.item.ItemStackCapProvider) Nullable(javax.annotation.Nullable)

Example 2 with CapabilityExplosiveStack

use of icbm.classic.lib.capability.ex.CapabilityExplosiveStack in project ICBM-Classic by BuiltBrokenModding.

the class EntityExplosiveDataFixer method fixTagCompound.

@Override
public NBTTagCompound fixTagCompound(NBTTagCompound compound) {
    // Match to entity, we get all entity tags as input
    if (compound.hasKey(NBTConstants.ID) && compound.getString(NBTConstants.ID).equalsIgnoreCase(ICBMEntities.BLOCK_EXPLOSIVE.toString())) {
        // Fix explosive ID save
        if (compound.hasKey(NBTConstants.EXPLOSIVE_ID)) {
            int id = compound.getInteger(NBTConstants.EXPLOSIVE_ID);
            // Generate stack so we can serialize off it
            final ItemStack stack = new ItemStack(BlockReg.blockExplosive, 1, id);
            // Handle custom explosive data
            final IExplosive ex = stack.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null);
            if (ex instanceof CapabilityExplosiveStack) {
                if (compound.hasKey(NBTConstants.DATA)) {
                    ((CapabilityExplosiveStack) ex).setCustomData(compound.getCompoundTag(NBTConstants.DATA));
                }
            }
            // Remove old tags
            compound.removeTag(NBTConstants.EXPLOSIVE_ID);
            compound.removeTag(NBTConstants.DATA);
            // Save stack
            compound.setTag(NBTConstants.EXPLOSIVE_STACK, stack.serializeNBT());
        }
    }
    return compound;
}
Also used : CapabilityExplosiveStack(icbm.classic.lib.capability.ex.CapabilityExplosiveStack) IExplosive(icbm.classic.api.caps.IExplosive) ItemStack(net.minecraft.item.ItemStack)

Example 3 with CapabilityExplosiveStack

use of icbm.classic.lib.capability.ex.CapabilityExplosiveStack in project ICBM-Classic by BuiltBrokenModding.

the class TileEntityExplosive method readFromNBT.

/**
 * Reads a tile entity from NBT.
 */
@Override
public void readFromNBT(NBTTagCompound nbt) {
    super.readFromNBT(nbt);
    capabilityExplosive = new CapabilityExplosiveStack(new ItemStack((NBTTagCompound) nbt.getTag(NBTConstants.EXPLOSIVE_STACK)));
}
Also used : CapabilityExplosiveStack(icbm.classic.lib.capability.ex.CapabilityExplosiveStack) ItemStack(net.minecraft.item.ItemStack)

Example 4 with CapabilityExplosiveStack

use of icbm.classic.lib.capability.ex.CapabilityExplosiveStack in project ICBM-Classic by BuiltBrokenModding.

the class BlockExplosive method onBlockPlacedBy.

/**
 * Called when the block is placed in the world.
 */
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entityLiving, ItemStack itemStack) {
    final TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof TileEntityExplosive) {
        TileEntityExplosive explosive = (TileEntityExplosive) tile;
        explosive.capabilityExplosive = new CapabilityExplosiveStack(itemStack.copy());
        if (world.getRedstonePowerFromNeighbors(pos) > 0) {
            BlockExplosive.triggerExplosive(world, pos, false);
        }
        // If so, then detonate.
        for (EnumFacing rotation : EnumFacing.HORIZONTALS) {
            Pos position = new Pos(pos).add(rotation);
            Block blockId = position.getBlock(world);
            if (blockId == Blocks.FIRE || blockId == Blocks.FLOWING_LAVA || blockId == Blocks.LAVA) {
                BlockExplosive.triggerExplosive(world, pos, true);
                break;
            }
        }
        if (entityLiving != null) {
            // TODO turn into event and logger
            ICBMClassic.logger().info("ICBMClassic>>BlockExplosive#onBlockPlacedBy: " + entityLiving.getName() + " placed " + explosive.capabilityExplosive.getExplosiveData().getRegistryName() + " in: " + pos);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pos(icbm.classic.lib.transform.vector.Pos) BlockPos(net.minecraft.util.math.BlockPos) CapabilityExplosiveStack(icbm.classic.lib.capability.ex.CapabilityExplosiveStack) EnumFacing(net.minecraft.util.EnumFacing) Block(net.minecraft.block.Block)

Aggregations

CapabilityExplosiveStack (icbm.classic.lib.capability.ex.CapabilityExplosiveStack)4 ItemStack (net.minecraft.item.ItemStack)2 IExplosive (icbm.classic.api.caps.IExplosive)1 Pos (icbm.classic.lib.transform.vector.Pos)1 ItemStackCapProvider (icbm.classic.prefab.item.ItemStackCapProvider)1 Nullable (javax.annotation.Nullable)1 Block (net.minecraft.block.Block)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1