Search in sources :

Example 6 with IExplosive

use of icbm.classic.api.caps.IExplosive in project ICBM-Classic by BuiltBrokenModding.

the class ExplosiveInit method enderMissileCoordSet.

private static boolean enderMissileCoordSet(Entity entity, EntityPlayer player, EnumHand hand) {
    if (entity.hasCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null)) {
        final IExplosive provider = entity.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null);
        final NBTTagCompound tag = provider.getCustomBlastData();
        if (tag != null) {
            final ItemStack heldItem = player.getHeldItem(hand);
            if (heldItem.getItem() instanceof IWorldPosItem) {
                final IWorldPosItem posItem = ((IWorldPosItem) heldItem.getItem());
                final IWorldPosition link = posItem.getLocation(heldItem);
                if (link instanceof Location) {
                    ((Location) link).writeIntNBT(tag);
                    if (!entity.world.isRemote) {
                        // TODO translate
                        player.sendMessage(new TextComponentString("Coordinates encoded into entity"));
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(icbm.classic.api.data.IWorldPosition) IExplosive(icbm.classic.api.caps.IExplosive) ItemStack(net.minecraft.item.ItemStack) IWorldPosItem(icbm.classic.api.items.IWorldPosItem) Location(icbm.classic.lib.transform.vector.Location) ResourceLocation(net.minecraft.util.ResourceLocation) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 7 with IExplosive

use of icbm.classic.api.caps.IExplosive 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)

Aggregations

IExplosive (icbm.classic.api.caps.IExplosive)7 ItemStack (net.minecraft.item.ItemStack)4 TextComponentString (net.minecraft.util.text.TextComponentString)3 IWorldPosition (icbm.classic.api.data.IWorldPosition)2 IWorldPosItem (icbm.classic.api.items.IWorldPosItem)2 Location (icbm.classic.lib.transform.vector.Location)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ExplosiveDefuseEvent (icbm.classic.api.events.ExplosiveDefuseEvent)1 EntityBombCart (icbm.classic.content.entity.EntityBombCart)1 CapabilityExplosiveEntity (icbm.classic.lib.capability.ex.CapabilityExplosiveEntity)1 CapabilityExplosiveStack (icbm.classic.lib.capability.ex.CapabilityExplosiveStack)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityTNTPrimed (net.minecraft.entity.item.EntityTNTPrimed)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Test (org.junit.jupiter.api.Test)1